Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: no respect to group sticky bit #18878

Closed
dieselburner opened this issue Feb 1, 2017 · 5 comments
Closed

cmd/go: no respect to group sticky bit #18878

dieselburner opened this issue Feb 1, 2017 · 5 comments

Comments

@dieselburner
Copy link

What version of Go are you using (go version)?

go version go1.7.4 linux/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/srv/test"
GORACE=""
GOROOT="/home/user/bin/go"
GOTOOLDIR="/home/user/bin/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build374787660=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"

What did you do?

Notice the group sticky bit:

$ ls -la
drwxrwsr-x 7 user www-data 4096 Feb  1 10:33 .
drwxr-xr-x 5 root root     4096 Feb  1 10:55 ..
drwxrwsr-x 2 user www-data 4096 Dec  2 17:02 bin
drwxrwsr-x 8 user www-data 4096 Feb  1 10:31 .git
-rw-rw-r-- 1 user www-data  169 Dec  8 15:25 .gitignore
drwxrwsr-x 3 user www-data 4096 Jan 17 15:03 src

Build:

$ go build pkg_name

What did you expect to see?

Produced binary respects group sticky bit, and correct group is set:

$ ls -la
drwxrwsr-x 7 user www-data     4096 Feb  1 10:33 .
drwxr-xr-x 5 root root         4096 Feb  1 10:55 ..
drwxrwsr-x 2 user www-data     4096 Dec  2 17:02 bin
drwxrwsr-x 8 user www-data     4096 Feb  1 10:31 .git
-rw-rw-r-- 1 user www-data      169 Dec  8 15:25 .gitignore
-rwxrwxr-x 1 user www-data 14693816 Feb  1 10:58 pkg_name
drwxrwsr-x 3 user www-data     4096 Jan 17 15:03 src

What did you see instead?

Group sticky bit is not respected:

$ ls -la
drwxrwsr-x 7 user www-data     4096 Feb  1 10:33 .
drwxr-xr-x 5 root root         4096 Feb  1 10:55 ..
drwxrwsr-x 2 user www-data     4096 Dec  2 17:02 bin
drwxrwsr-x 8 user www-data     4096 Feb  1 10:31 .git
-rw-rw-r-- 1 user www-data      169 Dec  8 15:25 .gitignore
-rwxrwxr-x 1 user user     14693816 Feb  1 10:58 pkg_name
drwxrwsr-x 3 user www-data     4096 Jan 17 15:03 src
@ianlancetaylor ianlancetaylor changed the title go/build: no respect to group sticky bit cmd/go: no respect to group sticky bit Feb 1, 2017
@ianlancetaylor ianlancetaylor added this to the Go1.9 milestone Feb 1, 2017
@ianlancetaylor
Copy link
Contributor

This is happening because the go tool builds the binary elsewhere, in a temporary directory, and then moves it into place.

@dieselburner
Copy link
Author

dieselburner commented Feb 1, 2017

Of course, and I assume it uses /tmp for this purpose. But IMHO implementing this would not be a huge deal - instead of moving the file go build could create the file manually and just copy the content there.

I'm haven't looked into the code, but in bash it is as simple as cat /tmp/binary > binary && rm /tmp/binary instead of mv /tmp/binary ..

@ianlancetaylor
Copy link
Contributor

Yes, the code to change is builder.moveOrCopyFile in cmd/go/build.go. If the destination directory has the ModeSetgid bit set, we should copy rather than move.

@paranoiacblack paranoiacblack self-assigned this Feb 7, 2017
@paranoiacblack paranoiacblack added the GoCommand cmd/go label Feb 7, 2017
@gopherbot
Copy link

CL https://golang.org/cl/36797 mentions this issue.

@gopherbot
Copy link

CL https://golang.org/cl/40912 mentions this issue.

gopherbot pushed a commit that referenced this issue Apr 17, 2017
Use our own tempdir, to avoid having to Init (and somehow teardown)
Builder.  This way we don't leave behind any temp files.

Also, don't create a hardcoded path inside a testcase.

Followup to #18878.
Fixes #19449.

Change-Id: Ieb1ebeab24ae8a74a6fa058d9c23f72b3fc1c444
Reviewed-on: https://go-review.googlesource.com/40912
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@golang golang locked and limited conversation to collaborators Apr 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants