Skip to content

fix(notices): resolve GOROOT explicitly for go-licenses - #2159

Merged
mchmarny merged 1 commit into
mainfrom
fix/go-licenses-empty-goroot
Aug 11, 2026
Merged

mchmarny merged 1 commit into
mainfrom
fix/go-licenses-empty-goroot

Conversation

@mchmarny

@mchmarny mchmarny commented Aug 11, 2026 •

Copy link
Copy Markdown
Member

Summary

go-licenses silently reports an empty dependency graph when its baked-in GOROOT is missing, which broke make tidy and made make license-check pass while inspecting nothing. Resolve GOROOT explicitly at both call sites and fail closed on an empty collection.

Motivation / Context

go-licenses decides whether a package is standard library by testing its source path against go/build's GOROOT, and a Go binary only carries a baked-in GOROOT when it was linked without -trimpath. With GOFLAGS=-trimpath exported in the environment (a common local default), go install go-licenses produces a binary whose GOROOT is empty. The stdlib prefix then collapses to /, every absolute source path matches, and the tool classifies the entire dependency graph as standard library — writing nothing and exiting 0.

That silence surfaced two ways:

  1. make tidy failed with an error that pointed nowhere near the cause:

    Collecting licenses for linux/amd64...
    cp: /var/folders/.../aicr-notices.fhoCkZ/linux_amd64/.: No such file or directory
    make[1]: *** [notices] Error 1
    

    tools/generate-notices merged a save_path that go-licenses save had never created.

  2. make license-check passed vacuously — a silent false PASS in a supply-chain gate. Reproduced on main: the target exits 0 having inspected zero packages, so a disallowed license would not have been caught.

Confirmed root cause by building the same probe with and without -trimpath:

runtime.GOROOT()="/opt/homebrew/Cellar/go/1.26.5/libexec"   # go build
runtime.GOROOT()=""                                          # go build -trimpath

Fixes: N/A
Related: #2158 — separate root cause (vendor path casing); both surfaced while running make tidy after 13f6057d.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • Build/CI/tooling

Component(s) Affected

  • CLI (cmd/aicr, pkg/cli)
  • API server (cmd/aicrd, pkg/server)
  • Recipe engine / data (pkg/recipe)
  • Bundlers (pkg/bundler, pkg/component/*)
  • Collectors / snapshotter (pkg/collector, pkg/snapshotter)
  • Validator (pkg/validator)
  • Core libraries (pkg/errors, pkg/k8s)
  • Docs/examples (docs/, examples/)
  • Other: third-party notices generator, license-check gate, merge-gate workflow

Implementation Notes

Fixing this at the call sites rather than only at install time is deliberate: it repairs already-installed binaries and any install path we do not control (a hand-run go install, a runner whose environment carries -trimpath). GOROOT is derived from go env GOROOT, so it always matches the toolchain actually in use, including after a GOTOOLCHAIN switch.

  • tools/generate-notices — resolve and export GOROOT (validated non-empty and a real directory) before invoking go-licenses.
  • tools/generate-notices — fail closed when a per-platform save collects nothing, reporting the actual cause instead of a bare ENOENT from the following cp. An empty collection can no longer reach the notices file.
  • Makefile (license-check) — same explicit GOROOT resolution, so the gate cannot pass vacuously.
  • .github/actions/install-go-licenses/ — new composite action that installs the pinned version with GOFLAGS cleared, matching tools/setup-tools and the convention already asserted by tools/setup-tools_test.sh. Both merge-gate jobs now call it instead of installing inline.

CI installs go-licenses through a new install-go-licenses composite action instead of repeating the install inline in both merge-gate jobs, so the GOFLAGS contract lives in one place. It is a dedicated primitive rather than an addition to setup-build-tools, because that action deliberately installs from binary releases ("go install puts in GOPATH which isn't in PATH") and go-licenses publishes none.

No Go source changed.

Testing

make qualify   # exit 0

Verification performed:

  • Original failure fixed — make tidy now exits 0; make notices writes 204 Go modules + 130 Python packages.
  • Output is correct, not merely non-empty — the regenerated THIRD_PARTY_NOTICES.md is byte-identical to the committed file, and make notices-check passes.
  • False PASS closed — make license-check now genuinely walks the dependency graph (emits per-package warnings for non-Go sources) and still passes.
  • New regression test tools/generate-notices_test.sh, wired into make test-shell → make test:
    • Behavioral: with a stub go-licenses that exits 0 and writes nothing (exactly the observed failure mode), the generator must exit non-zero, name the cause, and write no notices file.
    • Confirmed the test fails against the pre-fix script and passes after; the stub reproduces the original cp: ... No such file or directory on the old code.
    • Both call sites are verified by execution, not by grepping the source: each runs with GOROOT unset against a stub that records the GOROOT it actually received, so a bare assignment that is never exported fails the test. Verified by deleting export GOROOT from the Makefile and from tools/generate-notices in turn — each deletion fails the suite (exit 1).
    • Asserts the composite action clears GOFLAGS, and that no workflow installs go-licenses inline without it. Both guards verified to fail against the pre-fix workflow.
    • Skips locally when mikefarah/yq is absent, fails in CI — matching tools/api-diff_test.sh.
  • make qualify details: coverage 82.9% (threshold 80%), golangci-lint 0 issues, e2e chainsaw 24/24 passed, scan + api-diff clean.

One unrelated flake was seen on the first qualify run: tests/releasepolicy/TestReleaseResolverBehavior/Docker_manifest_list. It passes standalone on both this branch and pristine main, and passed on re-run under the full suite — pre-existing timing sensitivity in a package this PR does not touch (parallelized recently in 9198f361), not a regression from this change.

Risk Assessment

  • Low — Isolated change, well-tested, easy to revert
  • Medium — Touches multiple components or has broader impact
  • High — Breaking change, affects critical paths, or complex rollout

Rollout notes: N/A — build tooling only, no runtime or released-artifact behavior change. Worth noting for reviewers: license-check now actually enforces the allowed-license policy, so it can legitimately start failing on a dependency that was previously waved through unexamined. It passes on main today.

Checklist

  • Tests pass locally (make test with -race)
  • Linter passes (make lint)
  • I did not skip/disable tests to make CI green
  • I added/updated tests for new functionality
  • I updated docs if user-facing behavior changed — N/A, no user-facing behavior change
  • Changes follow existing patterns in the codebase
  • Commits are cryptographically signed (git commit -S) — GPG signing info

@mchmarny
mchmarny requested review from a team as code owners August 11, 2026 16:14
@mchmarny mchmarny added the theme/ci-dx CI pipelines, developer experience, and build tooling label Aug 11, 2026
@mchmarny mchmarny self-assigned this Aug 11, 2026
@coderabbitai

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

@github-actions

github-actions Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Report ✅

Metric Value
Coverage 82.9%
Threshold 80%
Status Pass
Coverage Badge
![Coverage](https://img.shields.io/badge/coverage-82.9%25-brightgreen)

No Go source files changed in this PR.

@mchmarny
mchmarny force-pushed the fix/go-licenses-empty-goroot branch from 6c7fd4d to bc58c58 Compare August 11, 2026 16:26
@github-actions github-actions Bot added size/L and removed size/M labels Aug 11, 2026
coderabbitai[bot]

This comment was marked as resolved.

@mchmarny
mchmarny force-pushed the fix/go-licenses-empty-goroot branch from bc58c58 to 858e665 Compare August 11, 2026 16:39
coderabbitai[bot]

This comment was marked as resolved.

go-licenses classifies a package as standard library by matching its
source path against go/build's GOROOT, which a Go binary only carries
when it was linked WITHOUT -trimpath. With GOFLAGS=-trimpath exported in
the environment, `go install go-licenses` yields a binary whose GOROOT is
empty: the stdlib prefix collapses to "/", every absolute source path
matches, and the tool reports the entire dependency graph as standard
library - writing nothing and exiting 0.

That silence surfaced two ways:

  * `make tidy` died on an unrelated "cp: .../linux_amd64/.: No such file
    or directory" when the notices generator merged a save_path that
    go-licenses had never created.
  * `make license-check` passed while inspecting zero packages - a silent
    false PASS in a supply-chain gate.

Resolve GOROOT explicitly at both call sites so the outcome no longer
depends on how the binary happened to be built, and fail closed when a
per-platform save collects nothing.

CI installs go-licenses through a new install-go-licenses composite
action rather than duplicating the install inline in both merge-gate
jobs, keeping the GOFLAGS contract in one place.

Signed-off-by: Mark Chmarny <[email protected]>
@mchmarny
mchmarny force-pushed the fix/go-licenses-empty-goroot branch from 858e665 to 936d0b0 Compare August 11, 2026 16:49
@mchmarny
mchmarny enabled auto-merge (squash) August 11, 2026 16:52
coderabbitai[bot]

This comment was marked as resolved.

@mchmarny
mchmarny merged commit b2e5908 into main Aug 11, 2026
40 checks passed
@mchmarny
mchmarny deleted the fix/go-licenses-empty-goroot branch August 11, 2026 17:00
yuanchen8911 added a commit to yuanchen8911/aicr that referenced this pull request Aug 11, 2026
…d path

The guards added with the GOROOT fix pass in states they exist to reject.

- The install-action assertion did a whole-file `grep -q 'GOFLAGS= go install'`,
  which the action's own explanatory comment satisfies. Deleting `GOFLAGS=` from
  the real `run:` step left the suite green, so the -trimpath/empty-GOROOT
  regression could return undetected. Anchor the match to the executable line.

- The inline-install scan required whitespace directly before the module path,
  so it matched only an unquoted `go install github.com/...`. Every install site
  in this repo quotes the path, so a quoted inline install in a workflow was not
  detected. Accept either quote form: matching only `"` would still let a
  single-quoted install through. The scan stays scoped to .github/workflows/ on
  purpose - the canonical action is where the real install lives, so widening
  the root would flag it as a violation of itself.

- `make license-check` had no negative case. The stub go-licenses exits 0
  unconditionally, so deleting the recipe's GOROOT validation branch left the
  suite green and only the export half was covered. Add a control that stubs
  `go env GOROOT` to print an unusable path while exiting 0. Exporting
  GOROOT=/nonexistent does not work: the real `go env` rejects it and exits 2,
  aborting the recipe under `set -e` before the branch is reached, which passes
  against a recipe with no validation at all.

- The yq gate exited 0 for the whole file, discarding the license-check cases
  that never invoke the generator and so have no yq dependency. Locally that
  disabled every new assertion. Move the shared fixtures above the gate and run
  the license-check cases first, leaving the gate to guard only the generator.

Follow-up to NVIDIA#2159.

Signed-off-by: Yuan Chen <[email protected]>
yuanchen8911 added a commit to yuanchen8911/aicr that referenced this pull request Aug 11, 2026
verify-licenses runs `make license-check`, gated on the `deps` paths-filter
output. That filter matched go.mod, go.sum, vendor/**, and
'.github/workflows/verify-licenses.yaml' - a file deleted in 3c9f6ec when the
job was folded into merge-gate.yaml. The entry was never updated to follow it,
so nothing in the filter watched any input the job actually consumes.

A PR that changes the license gate therefore merges with the gate skipped. That
happened on NVIDIA#2159, which repaired `make license-check` after finding it passed
while inspecting zero packages: it rewrote the Makefile recipe and added the
install-go-licenses action, and verify-licenses was skipped on it, so the
repaired gate was never run against the real dependency graph before merging.

Replace the dead entry and add every input that defines the check, mirroring the
reasoning the sibling notices filter already documents ("a change to them must
not be able to skip its own gate"):

- Makefile - the license-check recipe is the gate's contract.
- .github/actions/install-go-licenses/** - supplies the binary the check runs;
  that action clears GOFLAGS, without which -trimpath strips GOROOT and the
  check passes vacuously.
- .github/workflows/merge-gate.yaml - now defines the job, and makes a change
  to the filter trigger the gate it controls.
- .go-version, .settings.yaml, .github/actions/load-versions/** - the toolchain
  pins and the action that resolves them. The job reads both through
  load-versions before running the check, so a version bump would otherwise
  skip the gate it changes: NVIDIA#814 bumped go-licenses touching only
  .settings.yaml, and NVIDIA#1204 bumped Go touching only .go-version. Both would
  have run the license gate against a tool version it never validated.

Fixes NVIDIA#2164.

Signed-off-by: Yuan Chen <[email protected]>
yuanchen8911 added a commit to yuanchen8911/aicr that referenced this pull request Aug 11, 2026
verify-licenses runs `make license-check`, gated on the `deps` paths-filter
output. That filter matched go.mod, go.sum, vendor/**, and
'.github/workflows/verify-licenses.yaml' - a file deleted in 3c9f6ec when the
job was folded into merge-gate.yaml. The entry was never updated to follow it,
so nothing in the filter watched any input the job actually consumes.

A PR that changes the license gate therefore merges with the gate skipped. That
happened on NVIDIA#2159, which repaired `make license-check` after finding it passed
while inspecting zero packages: it rewrote the Makefile recipe and added the
install-go-licenses action, and verify-licenses was skipped on it, so the
repaired gate was never run against the real dependency graph before merging.

Replace the dead entry and add every input that defines the check, mirroring the
reasoning the sibling notices filter already documents ("a change to them must
not be able to skip its own gate"):

- Makefile - the license-check recipe is the gate's contract.
- .github/actions/install-go-licenses/** - supplies the binary the check runs;
  that action clears GOFLAGS, without which -trimpath strips GOROOT and the
  check passes vacuously.
- .github/workflows/merge-gate.yaml - now defines the job, and makes a change
  to the filter trigger the gate it controls.
- .go-version, .settings.yaml, .github/actions/load-versions/** - the toolchain
  pins and the action that resolves them. The job reads both through
  load-versions before running the check, so a version bump would otherwise
  skip the gate it changes: NVIDIA#814 bumped go-licenses touching only
  .settings.yaml, and NVIDIA#1204 bumped Go touching only .go-version. Both would
  have run the license gate against a tool version it never validated.

Fixes NVIDIA#2164.

Signed-off-by: Yuan Chen <[email protected]>
yuanchen8911 added a commit to yuanchen8911/aicr that referenced this pull request Aug 11, 2026
…d path

The guards added with the GOROOT fix pass in states they exist to reject.

- The install-action assertion did a whole-file `grep -q 'GOFLAGS= go install'`,
  which the action's own explanatory comment satisfies. Deleting `GOFLAGS=` from
  the real `run:` step left the suite green, so the -trimpath/empty-GOROOT
  regression could return undetected. Anchor the match to the executable line.

- That assertion is a presence check: it proves at least one correct install
  exists, not that every install is. A second install line appended to the same
  action without `GOFLAGS=` would leave it green, and the workflow scan below
  deliberately does not cover .github/actions/, so nothing else would catch it.
  Reject any install line in the action that does not clear GOFLAGS.

- The inline-install scan required whitespace directly before the module path,
  so it matched only an unquoted `go install github.com/...`. Every install site
  in this repo quotes the path, so a quoted inline install in a workflow was not
  detected. Accept either quote form: matching only `"` would still let a
  single-quoted install through. The scan stays scoped to .github/workflows/ on
  purpose - the canonical action is where the real install lives, so widening
  the root would flag it as a violation of itself.

- `make license-check` had no negative case. The stub go-licenses exits 0
  unconditionally, so deleting the recipe's GOROOT validation branch left the
  suite green and only the export half was covered. Add a control that stubs
  `go env GOROOT` to print an unusable path while exiting 0. Exporting
  GOROOT=/nonexistent does not work: the real `go env` rejects it and exits 2,
  aborting the recipe under `set -e` before the branch is reached, which passes
  against a recipe with no validation at all.

- The yq gate exited 0 for the whole file, discarding the license-check cases
  that never invoke the generator and so have no yq dependency. Locally that
  disabled every new assertion. Move the shared fixtures above the gate and run
  the license-check cases first, leaving the gate to guard only the generator.

Follow-up to NVIDIA#2159.

Signed-off-by: Yuan Chen <[email protected]>
yuanchen8911 added a commit to yuanchen8911/aicr that referenced this pull request Aug 11, 2026
…d path

The guards added with the GOROOT fix pass in states they exist to reject.

- The install-action assertion did a whole-file `grep -q 'GOFLAGS= go install'`,
  which the action's own explanatory comment satisfies. Deleting `GOFLAGS=` from
  the real `run:` step left the suite green, so the -trimpath/empty-GOROOT
  regression could return undetected. Anchor the match to the executable line.

- That assertion is a presence check: it proves at least one correct install
  exists, not that every install is. A second install line appended to the same
  action without `GOFLAGS=` would leave it green, and the workflow scan below
  deliberately does not cover .github/actions/, so nothing else would catch it.
  Reject any install line in the action that does not clear GOFLAGS.

- The inline-install scan required whitespace directly before the module path,
  so it matched only an unquoted `go install github.com/...`. Every install site
  in this repo quotes the path, so a quoted inline install in a workflow was not
  detected. Accept either quote form: matching only `"` would still let a
  single-quoted install through. The scan stays scoped to .github/workflows/ on
  purpose - the canonical action is where the real install lives, so widening
  the root would flag it as a violation of itself.

- `make license-check` had no negative case. The stub go-licenses exits 0
  unconditionally, so deleting the recipe's GOROOT validation branch left the
  suite green and only the export half was covered. Add a control that stubs
  `go env GOROOT` to print an unusable path while exiting 0. Exporting
  GOROOT=/nonexistent does not work: the real `go env` rejects it and exits 2,
  aborting the recipe under `set -e` before the branch is reached, which passes
  against a recipe with no validation at all.

- The yq gate exited 0 for the whole file, discarding the license-check cases
  that never invoke the generator and so have no yq dependency. Locally that
  disabled every new assertion. Move the shared fixtures above the gate and run
  the license-check cases first, leaving the gate to guard only the generator.

Follow-up to NVIDIA#2159.

Signed-off-by: Yuan Chen <[email protected]>
yuanchen8911 added a commit to yuanchen8911/aicr that referenced this pull request Aug 11, 2026
…d path

The guards added with the GOROOT fix pass in states they exist to reject.

- The install-action assertion did a whole-file `grep -q 'GOFLAGS= go install'`,
  which the action's own explanatory comment satisfies. Deleting `GOFLAGS=` from
  the real `run:` step left the suite green, so the -trimpath/empty-GOROOT
  regression could return undetected. Anchor the match to the executable line.

- That assertion is a presence check: it proves at least one correct install
  exists, not that every install is. A second install line appended to the same
  action without `GOFLAGS=` would leave it green, and the workflow scan below
  deliberately does not cover .github/actions/, so nothing else would catch it.
  Reject any install line in the action that does not clear GOFLAGS.

- The inline-install scan required whitespace directly before the module path,
  so it matched only an unquoted `go install github.com/...`. Every install site
  in this repo quotes the path, so a quoted inline install in a workflow was not
  detected. Accept either quote form: matching only `"` would still let a
  single-quoted install through. The scan stays scoped to .github/workflows/ on
  purpose - the canonical action is where the real install lives, so widening
  the root would flag it as a violation of itself.

- `make license-check` had no negative case. The stub go-licenses exits 0
  unconditionally, so deleting the recipe's GOROOT validation branch left the
  suite green and only the export half was covered. Add a control that stubs
  `go env GOROOT` to print an unusable path while exiting 0. Exporting
  GOROOT=/nonexistent does not work: the real `go env` rejects it and exits 2,
  aborting the recipe under `set -e` before the branch is reached, which passes
  against a recipe with no validation at all.

- The yq gate exited 0 for the whole file, discarding the license-check cases
  that never invoke the generator and so have no yq dependency. Locally that
  disabled every new assertion. Move the shared fixtures above the gate and run
  the license-check cases first, leaving the gate to guard only the generator.

Follow-up to NVIDIA#2159.

Signed-off-by: Yuan Chen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ci size/L theme/ci-dx CI pipelines, developer experience, and build tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants