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: improve handling of tmpdir being noexec #52941

Open
daenney opened this issue May 17, 2022 · 4 comments · May be fixed by #52959
Open

cmd/go: improve handling of tmpdir being noexec #52941

daenney opened this issue May 17, 2022 · 4 comments · May be fixed by #52959
Labels
GoCommand cmd/go help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@daenney
Copy link

daenney commented May 17, 2022

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

$ go version
go version go1.18.2 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/daenney/.cache/go-build"
GOENV="/home/daenney/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/daenney/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/daenney/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2560607780=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Run go test on a system with /tmp mounted as noexec.

What did you expect to see?

Tests run, or some helpful suggestion on how to fix the problem.

What did you see instead?

fork/exec /tmp/go-build/...: .permission denied

In #8451 the new GOTMPDIR was added, allowing a user to configure their system to fix this situation. Unfortunately the Go command does not provide that context or recommendation to me as a user if it runs into this situation.

On systems using systemd a reasonable choice could be to instead default to XDG_RUNTIME_DIR (with fallbacks to (GO)TMPDIR), which has the added benefit of being tied to the user session (instead of being a system-wide thing) and getting cleaned up somewhat regularly. Checking if that environment variable is defined ought to be enough, as it's set by pam-systemd (or was explicitly set by the user).

Regardless of potential changes to the default behaviour, I think it would be helpful to users if the go command could output the suggestion to configure GOTPMDIR in case it hits the permission denied case when launching the test binary.

@mknyszek
Copy link
Contributor

CC @bcmills maybe? Sounds like at the very least we could improve the output.

@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 17, 2022
@mknyszek mknyszek added this to the Backlog milestone May 17, 2022
@mknyszek mknyszek changed the title cmd/go: Improve handling of tmpdir being noexec cmd/go: improve handling of tmpdir being noexec May 17, 2022
@bcmills bcmills added the GoCommand cmd/go label May 17, 2022
@bcmills
Copy link
Contributor

bcmills commented May 17, 2022

Probably both go test and go run could check for EPERM or similar and give a hint with the error message.

@bcmills bcmills added help wanted NeedsFix The path to resolution is known, but the work has not been done. labels May 17, 2022
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 17, 2022
@ZekeLu ZekeLu linked a pull request May 18, 2022 that will close this issue
@gopherbot
Copy link

Change https://go.dev/cl/406848 mentions this issue: cmd/go: improve handling of tmpdir being noexec

@ZekeLu
Copy link
Contributor

ZekeLu commented May 18, 2022

After CL 406848 is merged, the output will be:

$ gotip run main.go
go: creating work dir: mkdir /tmp/go-build1759159385: permission denied.
	Run 'go env -w GOTMPDIR=...' to specify another temporary directory.
	For more about GOTMPDIR, see 'go help environment'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants