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

Use of go.mod fails with golang 1.13+ unless run as root #49

Closed
electrofelix opened this issue Sep 21, 2020 · 2 comments · Fixed by #50
Closed

Use of go.mod fails with golang 1.13+ unless run as root #49

electrofelix opened this issue Sep 21, 2020 · 2 comments · Fixed by #50
Labels

Comments

@electrofelix
Copy link
Contributor

It appears newer versions of golang (not entirely sure when this was introduced) remove write permissions for the cache populated, which because it is under a temp directory context will trigger an error on attempt to remove.

$ CGO_CFLAGS='-I<project_dir>/.tox/py37/include -I<homedir>/.pyenv/versions/3.7.7/include/python3.7m' CGO_LDFLAGS=-Wl,--unresolved-symbols=ignore-all GOPATH=<usertmpbasedir>/tmpqb7gjsft go build -buildmode=c-shared -o <project_dir>/build/lib.linux-x86_64-3.7/<my-library>.cpython-37m-x86_64-linux-gnu.so
error: [Errno 13] Permission denied: '<usertmpbasedir>/tmpqb7gjsft/pkg/mod/google.golang.org/[email protected]/compiler/protogen/protogen_test.go'

Sanitizing the output because the project is an internal work based one

ls -la <usertmpbasedir>/tmpqb7gjsft/pkg/mod/google.golang.org/[email protected]/compiler/protogen/
total 68
dr-xr-xr-x 2 electrofelix users  4096 Sep 21 14:49 .
dr-xr-xr-x 3 electrofelix users  4096 Sep 21 14:49 ..
-r--r--r-- 1 electrofelix users 45926 Sep 21 14:49 protogen.go
--w------- 1 electrofelix users 10685 Sep 21 14:49 protogen_test.go

Notice no write access on the directory, even run manually:

rm -f <usertmpbasedir>/tmpqb7gjsft/pkg/mod/google.golang.org/[email protected]/compiler/protogen/protogen_test.go

gets the same error of Permission denied

Though perhaps given that downloading the go dependencies pristine each time it might be more performant to allow the user to reuse their existing golang cache or even only download to the temp directory those files that are not already available under GOPATH as it can be a list of paths instead of a single path.

@asottile
Copy link
Owner

can probably use the same trick that pre-commit uses if you'd like to send a patch and bump the tested go versions to the latest two (those are all that upstream supports)

@asottile asottile added the bug label Sep 21, 2020
electrofelix added a commit to electrofelix/setuptools-golang that referenced this issue Sep 22, 2020
Projects that use go.mod will result in the build downloading the
modules to an temporary path. Golang introduced read only directories to
protect the generated module cache from accidental writes, resulting in
failures to build when exiting the temporary directory context.

Adapt the solution from pre-commit to make the directory and file
writable on removal and include a rudimentary test that exercises
download via a simple example module hosted by the golang org in github.

Fixes asottile#49
@electrofelix electrofelix changed the title Fails with golang 1.14 unless run as root Use of go.mod fails with golang 1.11+ unless run as root Sep 22, 2020
@electrofelix
Copy link
Contributor Author

I've updated the title, it appears to be an issue where use of go.mod or a module cache is involved where the directories were made not writable at least as far back as Aug 2018 golang/go#27161 (comment). It appears to be only use of go.mod that triggers this behaviour for this module, possibly because that is the only one that results in a module cache being populated under a temporary directory. This should mean that the current versions of go being tested are just fine, so I added a test that triggered the issue locally for me, and I believe should trigger it (if you remove the fix) on go from 1.11+

@electrofelix electrofelix changed the title Use of go.mod fails with golang 1.11+ unless run as root Use of go.mod fails with golang 1.13+ unless run as root Sep 22, 2020
electrofelix added a commit to electrofelix/setuptools-golang that referenced this issue Sep 23, 2020
Projects that use go.mod will result in the build downloading the
modules to an temporary path. Golang introduced read only directories to
protect the generated module cache from accidental writes, resulting in
failures to build when exiting the temporary directory context.

Adapt the solution from pre-commit to make the directory and file
writable on removal and include a rudimentary test that exercises
download via a simple example module hosted by the golang org in github.

Fixes asottile#49
electrofelix added a commit to electrofelix/setuptools-golang that referenced this issue Sep 23, 2020
Projects that use go.mod will result in the build downloading the
modules to an temporary path. Golang introduced read only directories to
protect the generated module cache from accidental writes, resulting in
failures to build when exiting the temporary directory context.

Adapt the solution from pre-commit to make the directory and file
writable on removal and include a rudimentary test that exercises
download via a simple example module hosted by the golang org in github.

Fixes asottile#49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants