Repository navigation
fix(build): honor PATH set in environment.environment - #2740
theluckystrike wants to merge 5 commits into
Conversation
03ac708 to
00a9237
Compare
|
Rebased onto current main as a single GitHub-signed commit (00a9237) so the commit-signing policy passes. Diff is unchanged: pkg/build/pipeline.go + pkg/build/pipeline_test.go, same tree as before. |
An empty PATH makes the shell look commands up in the current directory, which for a step is the workspace holding the fetched upstream source. Fall back to the default PATH in that case, as the configuration defaults already do for HOME and GOPATH. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Code reviewers1 finding (1 low) · reviewed edd9707
Standards: 1 read, 0 left out
Reviewers are configured in |
There was a problem hiding this comment.
reviewer/melange · Commented
Verdict: comment. 0 Blocking, 1 Questions, 0 Pre-existing. I checked the fix against all three runners: bubblewrap_runner.go:192-197, docker_runner.go:235-240 and qemu_runner.go:224-236 all apply cfg.Environment first and envOverride second, so the root cause is as described. Nothing in config parsing puts PATH into environment.environment (config.go:1891-1897), so builds that never set PATH keep today's PATH. TestRunPipelineHonorsConfiguredPath fails without the change. The open question is which existing packages now get a PATH they never had before.
| // An empty PATH counts as none: a shell reads it as "search the current | ||
| // directory", which is the workspace holding the fetched source. | ||
| // NOTE: This does not currently override PATH in the qemu runner, that's set at openssh build time | ||
| if r.config.Environment["PATH"] == "" { |
There was a problem hiding this comment.
reviewer/melange · low
Question: This changes behaviour for every existing package that sets PATH under environment.environment, test.environment.environment, or a subpackage's test environment. It also reaches PATH values loaded from an --env-file, because those are merged into cfg.Environment.Environment (config.go:1857-1868). Until now that value was silently replaced by the default PATH. From this change on it is used as written. None of the runners expand it: bwrap --setenv, docker exec Env and ssh Setenv all pass the string through unchanged. So a package with PATH: /usr/lib/foo/bin:$PATH would get a literal $PATH entry and lose /usr/bin. That breaks a build that passes today. A build PATH also reaches every test container now, because test.go:498 copies the build's environment.environment into the test config. Did you search wolfi-dev/os (and the enterprise package repos, if you can) for PATH under environment.environment and the test environments? Did any hit rely on $PATH or on directories missing from the test image? If there are hits, list them in the PR body, or fix them before this merges, so the change is announced as AGENTS.md (Compatibility) and .chainguard/review-prompt.md require.
There was a problem hiding this comment.
I measured it against wolfi-dev/os at 129c3a0 (shallow clone, today). I parsed all 3,914 package YAMLs and checked environment.environment, test.environment.environment and every subpackage's test.environment.environment for PATH.
One hit: infinispan-16.3.yaml:170, test environment only:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin (infinispan)
/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin (default, pipeline.go:238)
Same six directories; only /usr/sbin and /usr/bin swap order. So in Wolfi, no package build changes, and one test gets an equivalent PATH.
What I can't measure from here is --env-file usage outside that repo, or enterprise-packages. If you'd rather be careful, I can log a warning when a configured PATH differs from the default, so changes are visible in build logs. Happy to add that.
dustinkirkland
left a comment
There was a problem hiding this comment.
Reviewed at 8bc7ab4 against AGENTS.md (Compatibility, Runners, Go and commits). 0 blocking, 1 suggestion. No design doc found beyond #1956; the change does what the issue asks.
Watch focus items checked:
- Supply chain: the net diff is only
pkg/build/pipeline.goandpkg/build/pipeline_test.go. Both merge commits (ecd67c1, 8bc7ab4) have an empty remerge diff, so they add nothing beyond main. No new deps, no CI or workflow edits. - PATH security: PATH reaches
cfg.Environmentonly from the package'senvironment.environment(and, for tests,test.environment.environment) or the operator's--env-file(config.go:1856-1868). Whoever writes those already controls everyruns:block, so honoring their PATH crosses no new trust boundary. apko's locked image configuration doesn't add a PATH to the struct; it only sets PATH in the OCI config (apko pkg/build/oci/image.go:175), so builds that never set PATH keep the default. An empty PATH falls back to the default (pipeline.go:247). A relative entry, or a leading, trailing or doubled:, is passed through as written. That only puts the workspace on the search path when the package author writes it that way, the same as acdplus./toolinruns:. - Runners: bubblewrap, docker and qemu (
qemu_runner.go:224-236) all applycfg.Environmentfirst andenvOverridesecond. Nothing else inpkg/readsenvOverride["PATH"].
I'm not seconding the open question in T1. The author's wolfi-dev/os scan answers it for Wolfi.
The required e2e tests complete check hasn't reported at this head yet.
autorev-by: dustinkirkland
autorev-by: dustinkirkland
| { | ||
| name: "nothing sets PATH", | ||
| yaml: head + steps, | ||
| want: []string{stdPath, stdPath, "/opt/step/bin"}, | ||
| }, |
There was a problem hiding this comment.
Suggestion (non-blocking). 4a8609f made an empty configured PATH fall back to the default (pipeline.go:247). Its commit message gives a safety reason: an empty PATH makes the shell search the workspace. No test covers that. If someone reverts to the earlier if _, ok := r.config.Environment["PATH"]; !ok form, steps run with PATH="" and every case here still passes. AGENTS.md asks that a fix come with a test that fails without it. Adding one case pins this down:
| { | |
| name: "nothing sets PATH", | |
| yaml: head + steps, | |
| want: []string{stdPath, stdPath, "/opt/step/bin"}, | |
| }, | |
| }, | |
| { | |
| name: "configuration sets an empty PATH", | |
| yaml: head + "environment:\n environment:\n PATH: \"\"\n" + steps, | |
| want: []string{stdPath, stdPath, "/opt/step/bin"}, | |
| }, |
2d2293c to
8bc7ab4
Compare
|
Added the empty PATH case you suggested in edd9707, as a row in TestRunPipelineHonorsConfiguredPath. It covers the fallback from 4a8609f. With that change reverted locally the new row fails, and with it in place all three rows pass: Nothing else in pkg/build changes. The rest of the package fails the same 24 split/manpage subtests on macOS with or without this commit. |
Fixes #1956.
A PATH set under
environment.environmentnever reached the steps.runPipelinestarts every step'senvOverridewith a fixed default PATH, and the runners (bubblewrap, docker, qemu) applycfg.Environmentfirst andenvOverrideafter it. The default PATH therefore replaced the configured one, while other variables such asFOOin the issue came through as expected. A PATH set in a step's ownenvironmentalready worked, because it is copied intoenvOverrideafter the default.With this change
runPipelineonly adds the default PATH when the runner config has no PATH. The default value moves into adefaultPathconstant and is the same string as before. Nested steps inherit from their parent as before, so they see the configured PATH too. Builds that do not set PATH get the same PATH as today.TestRunPipelineHonorsConfiguredPathinpkg/build/pipeline_test.goparses a config, runs its steps through the build and the test pipeline runners with the existing env recording runner, and checks the PATH each step gets. With PATH set to/usr/bininenvironment.environment, the step and its nested step must see/usr/binand a step with its own PATH keeps it. Without any configured PATH those two steps get the default. On main (76b6e95) the first case fails because both steps get the default PATH instead of/usr/bin. With the change both cases pass.I ran
go test -count=1 ./...on main and on this branch with Go 1.27.3 on macOS. Both runs have 19 packages ok and the same 24 failing test lines, all inpkg/build(TestSplitManpagesSucceeds,TestSplitManpagesFailsLoudlyandTestSplitAllDocsMergesRoots). They fail because the split pipeline scripts call GNUrmdiroptions that the BSDrmdiron macOS does not have. This branch has 946 passing test lines against 943 on main, which is the new test and its two cases.go vet ./pkg/build/is clean,go build ./...works and gofmt reports nothing.Functional changes. I did not build Wolfi or any package with a real runner, so I leave the box about building all of Wolfi unchecked. A package only sees a different PATH if it sets PATH in
environment.environment, and right now that setting has no effect. The SCA and linter sections do not apply.Not run. The e2e targets, the integration tag,
-raceand any container or qemu runner. The qemu runner comment still applies, since PATH there comes from the openssh build and this change does not touch it.