-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
x/tools: replace use of x/sys/execabs with os/exec #57304
Comments
Also, I guess the error message is technically incorrect if you go edge-case hunting and put |
Also, technically I can work around this by having Bazel run a wrapper around |
Duplicate of #53962 |
Further, the GODEBUG flag was created in the spirit of a temporary migration measure, but there's no reasonable way to work around this problem as a consumer of
The ONLY workaround that I see here is to add a wrapper in Bazel that makes the |
cc @golang/tools-team |
One way to support the Bazel use case is to make the In general I don't think we want x/tools/go/packages to ignore |
If the route forward is to respect the |
Bazel build systems try to keep hermeticity by setting PATH="." - but Go does not like this as it is a security concern; almost all Go tooling relies on golang.org/x/tools/go/packages.Load which behind the scenes must invoke `go` and uses the secure version of x/sys/execabs, but ultimately this means Go tools like autogold cannot be run in Bazel: golang/go#57304 Autogold relies on `packages.Load` in order to determine the Go package name / path when writing out a Go AST representation of the value passed in; but the issue above means autogold cannot be used with Bazel without removing "." from your PATH, which Bazel claims breaks hermeticity (one of the whole reasons people use Bazel.) For Bazel users, we allow them to set ENABLE_BAZEL_HACKS=true which causes autogold to guess/infer package names and paths using stack trace information and import paths. This is not perfect, it doesn't respect packages whose import paths donot match their defined `package foo` statement for example - but it's sufficient to enable autogold to be used in Bazel build environments where the above Go/Bazel bug is found. Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
Bazel build systems try to keep hermeticity by setting PATH="." - but Go does not like this as it is a security concern; almost all Go tooling relies on golang.org/x/tools/go/packages.Load which behind the scenes must invoke `go` and uses the secure version of x/sys/execabs, but ultimately this means Go tools like autogold cannot be run in Bazel: golang/go#57304 Autogold relies on `packages.Load` in order to determine the Go package name / path when writing out a Go AST representation of the value passed in; but the issue above means autogold cannot be used with Bazel without removing "." from your PATH, which Bazel claims breaks hermeticity (one of the whole reasons people use Bazel.) For Bazel users, we allow them to set ENABLE_BAZEL_PACKAGES_LOAD_HACK=true which causes autogold to guess/infer package names and paths using stack trace information and import paths. This is not perfect, it doesn't respect packages whose import paths donot match their defined `package foo` statement for example - but it's sufficient to enable autogold to be used in Bazel build environments where the above Go/Bazel bug is found. Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I'm trying to run gqlgen (https://github.com/99designs/gqlgen) as part of a Bazel build.
What did you expect to see?
There should be some way to make gqlgen run correctly in Bazel
What did you see instead?
gqlgen fails with the error:
go resolves to executable in current directory (.\external\go_sdk\bin\go.exe)
I originally commented on the execabs proposal here: #43724 (comment)
Bazel makes it intentionally difficult to ever get an absolute path in order to make builds more hermetic. To that end, Bazel runs executable files in this arrangement:
This creates a somewhat-unusual situation where the paths to be found by
exec.LookPath
/execabs.LookPath
aren't absolute, but they also aren't files directly in CWD. Since the paths aren't absolute, the current behavior ofexec.LookPath
/execabs.LookPath
is to return an error. However, my understanding is that the LookPath security vulnerability is only relevant if the relative directory is conventionally listed on PATH variables in interactive sessions, but the only such conventionally-used relative path that I'm aware of is.
. If it's true that.
is the only relative path that regularly appears on users' PATH variables, I think it should be safe to update the enforcement check to allow relative paths outside of.
:The text was updated successfully, but these errors were encountered: