The go feature doesn't appear to work properly with non-root user, can't run "go install <package>" /go/pkg permission denied
I have installed the go devcontainer feature and the common-utils, when I try to install a package in that environment, I then get:
+ go install github.com/coreos/[email protected]
go: could not create module cache: mkdir /go/pkg: permission denied
also, go mod tidy fails, ...
Looking into the go feature's installation script https://github.com/devcontainers/features/blob/8e8e14f6fbb1f1c30e7794aff293960caba2945a/src/go/install.sh#L338 and then checking in a live container, I notice that while /go/pkg belongs to group golang, it is r-x only, but not rwx. ~~Cleaning up the module and sumdb caches and then setting sudo chmod -R g+w /go/pkg seems to fix things.~~ EDIT: see below comment.
I would suspect that the pkg directory gets only created later due to some other action where the umask is the usual 0755 instead of 0775.
In .devcontainer/devcontainer.json I need to configure:
{
"remoteEnv": {
"GOPATH": "/home/vscode/go",
"PATH": "/home/vscode/go/bin:/go/bin:/usr/local/go/bin:${localEnv:PATH}"
},
}
There might be better ways and I would be grateful for any feedback on this; for the moment, that seems to get me finally up and running correctly in that go mod tidy, go install golang.org/x/vuln/cmd/govulncheck@latest, etc work.