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: unhelpful go cache error when running in container as non-root user #26280

Closed
zevdg opened this issue Jul 8, 2018 · 3 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@zevdg
Copy link
Contributor

zevdg commented Jul 8, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.10.3 linux/amd64

Does this issue reproduce with the latest release?

yes

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

GOOS="linux"
GOARCH="amd64"

What did you do?

Build any go program in a docker image as a user that doesn't exist in the image.
Although this sounds weird, it is specifically allowed in the docker run documentation

When passing a numeric ID, the user does not have to exist in the container.

Any CI server following the principle of least privilege would be configured to run their containers in this way.

Assuming docker is installed, the following command will recreate the issue

docker run -u $UID golang /bin/bash -c "cd /go/src/; mkdir hello; cd hello;
echo 'package main
import \"fmt\"
func main() {
    fmt.Println(\"hello world\")
}' > main.go; go run main.go"

More specifically, this is caused when $HOME is set to / which is what docker does in this situation.

What did you expect to see?

hello world

What did you see instead?

go: disabling cache (/.cache/go-build) due to initialization failure: mkdir /.cache: permission denied
hello world

Notes

This is effectively an iteration on #23638. Disabling the cache is probably still the correct thing to do, but in this case, the current error message is unnecessary and more confusing than it is helpful. You can see that confusion in docker-library/golang#225.

As I suggested in my comment on that issue, if go were to silently set GOCHACHE to "off" when $HOME=='/' then this confusion would be avoided. Go already does this when $HOME=='', so I'm just proposing to extend that behavior to one more edge case.

I'm happy to submit a PR that fixes this if you agree with the change.

@ianlancetaylor ianlancetaylor changed the title unhelpful go cache error when running in container as non-root user cmd/go: unhelpful go cache error when running in container as non-root user Jul 8, 2018
@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Jul 8, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Jul 8, 2018
@ianlancetaylor
Copy link
Contributor

I think it would be fine to disable the cache in that case.

@gopherbot
Copy link

Change https://golang.org/cl/122487 mentions this issue: cmd/go/internal/cache: disable cache when $HOME is /

@bcmills
Copy link
Contributor

bcmills commented Dec 7, 2018

Per the Go 1.11 release notes:

Starting in Go 1.12, the build cache will be required

I suspect that means that Docker users will need to set GOCACHE explicitly when running a build as a nonexistent user.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants