Build the SBOM from
go.mod: since Go 1.17 it lists every module needed to build your packages, indirect ones included. Record the Go version too, because the standard library is compiled into your binary and has its own vulnerabilities. To check what a shipped binary contains, rungo version -mon it; to triage vulnerabilities, usegovulncheck, which reports only the ones your code can reach.
Which file the SBOM comes from
| Package manager | File | Full dependency tree? | Dev dependencies left out? |
|---|---|---|---|
| Go modules | go.mod (require, including // indirect) | Yes, since Go 1.17 | No: modules used only by tests aren't marked |
How to generate it
With the CRA Starter Kit tool
normavio_sbom.py reads the require lines of go.mod, skips vendor, and writes a readable report for the technical file next to the SBOM. It doesn't read go.sum, which also lists versions you don't build with.
python3 normavio_sbom.py ./gateway \
--name "Nimbus Gateway" --version 2.0.0 \
--osv --out ./technical-file/sbom/2.0.0
# -> sbom.cdx.json and sbom-report.md With the official CycloneDX tool
cyclonedx-gomod has a mod mode for the module and an app mode that keeps only the modules compiled into one main package, which is closer to what you ship.
go install github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@latest
cyclonedx-gomod mod -json -output sbom.cdx.json Check a shipped binary
Every Go binary carries its module list and the Go version it was built with. Use it to confirm that the SBOM in the technical file matches the release.
go version -m ./bin/gateway Triage with govulncheck
govulncheck, from the Go team, reports vulnerabilities in your modules and in the standard library, and tells you whether your code calls the affected function. That is exactly the evidence you need to decide whether a vulnerability affects your product.
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./... What catches teams out
- The standard library. It isn't a module in
go.mod, but it is in your binary. Note the Go toolchain version in the SBOM or the report, and rebuild when a Go security release fixes something you use. replacedirectives. Ifgo.modreplaces a module with a fork or a local path, the shipped code isn't the original one. The kit's tool readsrequirelines only, so check replaced modules in the report by hand.- Test-only modules.
go.moddoesn't tell them apart.cyclonedx-gomod appandgo version -mshow only what is compiled in. - cgo. C libraries linked through cgo aren't Go modules. If you ship them, they belong in the SBOM of the image or firmware.
What the CRA asks of this SBOM
- Identify and document the components, including by drawing up an SBOM in a commonly used, machine-readable format, covering at least the top-level dependencies (Annex I, Part II, point 1).
- Keep it in the technical documentation, one per product version (Annex VII, point 2).
- Use it to find and fix vulnerabilities in those components without delay (Annex I, Part II, point 2).
The SBOM guide covers formats, fields and how to keep it alive.
Frequently asked questions
Is go.sum a better source than go.mod?
No. go.sum holds checksums for every version the module graph mentions, including ones you don't build with. Use go.mod, or the binary itself.
One SBOM per binary or per module?
Per product you place on the market. If a module builds several binaries that are sold separately, generate one per binary (cyclonedx-gomod app).
Does govulncheck replace the SBOM?
No. The SBOM documents components (Annex I, Part II, point 1); govulncheck helps you handle vulnerabilities in them (point 2). You need both.