Skip to content

build: make the main module version readable by image scanners - #4486

Draft
stevenvegt wants to merge 1 commit into
masterfrom
ci/scanner-main-module-version
Draft

build: make the main module version readable by image scanners#4486
stevenvegt wants to merge 1 commit into
masterfrom
ci/scanner-main-module-version

Conversation

@stevenvegt

@stevenvegt stevenvegt commented Sep 9, 2026

Copy link
Copy Markdown
Member

Docker image scanners could not read the version of the nuts-node main module from the image. Trivy showed no version at all, because it only reads -X ldflag keys ending in .version and ours was core.GitVersion. The GitHub release binaries carry v0.0.0-<time>-<rev>, stamped by Go's VCS support, because the module path without /v6 makes the v6.x tags invalid module versions.

Changes:

  • Rename core.GitVersion to core.Version, so the ldflag key ends in .version. That name was taken by the function core.Version(), and a Go package cannot have a variable and a function with the same name, so the function is renamed to core.VersionOrBranch(). Its behaviour is unchanged: it returns the tagged version if set, otherwise the branch. Tests updated.
  • Build with -buildvcs=false in the Dockerfile, makefile and binaries workflow, so no pseudo-version can be stamped. The ldflag is the intended source of the version.
  • Derive the version in the images workflow from GITHUB_REF_TYPE and GITHUB_REF_NAME instead of git name-rev, so tag builds get a clean vX.Y.Z and everything else gets undefined.

Verified on a binary built with the new flags: Trivy and Syft both report pkg:golang/github.com/nuts-foundation/nuts-node@v6.2.10. Before the change Trivy reported no version for the published 6.2.10 image.

This does not make advisories match yet. Both GitHub and the Go vulnerability database store our advisory ranges as "up to 1.1.0" or "all versions", because the module path has no major version suffix. See #4485 for that.

Related: #4451 attaches the SBOM to the image; this PR fixes what that SBOM says about the nuts-node module. The two are independent and touch neighbouring lines of build-images.yaml, so whichever merges second needs a trivial rebase.

Trivy only reads a version from -ldflags when the -X key ends in
".version", so core.GitVersion was ignored and the nuts-node module
showed up without a version in Trivy scans of the image. Rename the
variable to core.Version (and the Version() func to VersionOrBranch())
so both Trivy and Syft pick it up.

Build with -buildvcs=false: the module path has no /v6 suffix, so Go
cannot derive the version from the v6.x tags and stamps a pseudo-version
(v0.0.0-<time>-<rev> on the release binaries) that scanners rank against
old advisories. The ldflag is the intended source of the version.

Derive the version in the image workflow from the tag ref instead of
git name-rev, so it is always a clean vX.Y.Z on tag builds and
"undefined" otherwise.

Refs #4485

Assisted-by: AI
@qltysh

qltysh Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

0 new issues

Tool Category Rule Count

@qltysh

qltysh Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Qlty


Coverage Impact

This PR will not change total coverage.

Modified Files with Diff Coverage (3)

RatingFile% DiffUncovered Line #s
Coverage rating: B Coverage rating: B
tracing/engine.go100.0%
Coverage rating: A Coverage rating: A
core/status/engine.go100.0%
Coverage rating: A Coverage rating: A
core/build_vars.go80.0%40
Total85.7%
🤖 Increase coverage with AI coding...
In the `ci/scanner-main-module-version` branch, add test coverage for this new code:

- `core/build_vars.go` -- Line 40

🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

@stevenvegt

Copy link
Copy Markdown
Member Author

Converted to draft. #4487 (module path rename on V6.2) supersedes this PR: once the module path carries the /v6 suffix, go build stamps the version from the tag itself and scanners read it from the build info, so the ldflags key and -buildvcs=false here are no longer needed. The -buildvcs=false flag would even block that stamping. If #4487 is approved and ported to master, close this PR. If #4487 is rejected, this PR is the fallback and can be marked ready again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant