athens icon indicating copy to clipboard operation
athens copied to clipboard

Filesystem backend marks files as executables

Open lwithers opened this issue 8 years ago • 7 comments

Describe the bug When using the filesystem storage backend, newly-created files are marked as executable.

Error Message

total 116
-rwxr-xr-x 1 lwithers lwithers     36 Sep 24 16:47 go.mod
-rwxr-xr-x 1 lwithers lwithers 108149 Sep 24 16:47 source.zip
-rwxr-xr-x 1 lwithers lwithers     78 Sep 24 16:47 v0.0.0-20180828140353-eee3db372b31.info

As you can see, each file incorrectly has the execute permission bit x set.

To Reproduce Cause the proxy to download anything new.

Expected behavior Files should not be marked as executable:

total 116
-rw-r--r-- 1 lwithers lwithers     36 Sep 24 16:47 go.mod
-rw-r--r-- 1 lwithers lwithers 108149 Sep 24 16:47 source.zip
-rw-r--r-- 1 lwithers lwithers     78 Sep 24 16:47 v0.0.0-20180828140353-eee3db372b31.info

Environment (please complete the following information):

  • OS: Linux 64bit
  • Go version : 1.11.1
  • Olympus or proxy version : HEAD (13083b9d)

Additional context In pkg/storage/fs/saver.go, there's a comment saying:

// TODO: 777 is not the best filemode, use something better

What I'd suggest is:

  • use 0777 for newly-created directories
  • use 0666 for newly-created files

This allows the administrator to use the normal Unix umask mechanism to control the actual permissions files and directories get created with. This is normal, expected behaviour. Perhaps something like the following patch: fs_saver.patch.txt

lwithers avatar Oct 15 '18 10:10 lwithers

are you interested in fixing this?

michalpristas avatar Oct 15 '18 10:10 michalpristas

Sure, I can open a PR.

lwithers avatar Oct 15 '18 11:10 lwithers

Maybe one suggestion, If you could check that 0600 is sufficient for this file because we probably don't want all users to be able to access those files.

t-tomalak avatar Oct 15 '18 11:10 t-tomalak

Well, 0666 is actually just passed to the OS as the most permissions the file will get. The OS then subtracts the umask, which is why the files currently being created are 0755 and not 0777 (since the default, commonly used umask is 0022).

So by passing 0666 you leave it up to the administrator to maybe allow the files to be group-readable or perhaps even group-writeable, by supplying an appropriate umask when they run athens.

If you pass 0600 you take this ability away, which could potentially be annoying.

lwithers avatar Oct 15 '18 11:10 lwithers

I have a question. I did a go get without the proxy on a MacOs and the permissions assigned to the downloaded modules are 0755. A) Should the code not mimic that behavior? B) Why did the go mod authors chose 0755 as the permissions or it is just a bug in the go get tool.

This is regardless of the report above. Can you help me clarify?

manugupt1 avatar Oct 15 '18 11:10 manugupt1

Under Linux, without the proxy, I get the following:

 $ ls -l ~/go/pkg/mod/cache/download/gopkg.in/yaml.v2/@v/
total 92
-rw-r--r-- 1 lwithers lwithers     7 Sep 30 10:18 list
-rw------- 1 lwithers lwithers    50 Sep 30 10:18 v2.2.1.info
-rw------- 1 lwithers lwithers    95 Sep 30 10:18 v2.2.1.mod
-rw-r--r-- 1 lwithers lwithers 77767 Sep 30 10:18 v2.2.1.zip
-rw-r--r-- 1 lwithers lwithers    47 Sep 30 10:18 v2.2.1.ziphash

(i.e. a mix of 0600 and 0644).

In fact, if you take a look in the Go source at src/cmd/go/internal/modfetch, you'll see multiple invocations of os.MkdirAll used with mode 0777 and multiple ioutil.WriteFile with mode 0666.

lwithers avatar Oct 15 '18 11:10 lwithers

Thanks for a quick fix @lwithers ;-) i checked with https://github.com/golang/go/blob/56dc1795e756767adb373a5bc151c9c820152025/src/cmd/go/internal/modfetch/fetch.go#L152 it is aligned so I guess it answers @manugupt1 's concerns

michalpristas avatar Oct 15 '18 12:10 michalpristas