SBOMs for Go
Go has no built-in SBOM command. sbombox generate uses cyclonedx-gomod if installed, then cdxgen or syft. For a release, describe the binary you ship: that lists only what was compiled in.
At a glance
| Package manager | Built-in SBOM command | What sbombox generate runs | Lockfile to commit |
|---|---|---|---|
| Go modules | No (go version -m prints build info) | cyclonedx-gomod, then cdxgen or syft | go.sum |
Generate with SBOMBox
curl -fsSL https://sbombox.com/install.sh | sh
sbombox generate -o sbom.json
sbombox score sbom.jsonRun it from the directory that holds go.mod and go.sum. The default installer adds syft. Install cyclonedx-gomod to use the native tool:
go install github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@latestTo pin the choice, set SBOMBOX_GENERATOR to one or more generator names, comma-separated. SBOMBox tries them in that order and skips any that are not installed. An unknown name fails with the list of valid names.
SBOMBOX_GENERATOR=syft sbombox generate -o sbom.jsonValid names for Go: cyclonedx-gomod (alias golang), cdxgen, syft.
Use cyclonedx-gomod or syft
cyclonedx-gomod has three modes: mod describes the whole module, app describes one main package as built, and bin reads a compiled binary. For a release SBOM, use app:
cyclonedx-gomod app -json -licenses -output sbom.json -main cmd/api .To describe the module instead:
cyclonedx-gomod mod -json -licenses -output sbom.json .Go 1.25 and later can print the build information embedded in a binary as JSON. It is not an SBOM, but it shows exactly which modules were linked:
go version -m -json ./bin/apisyft reads the same build information from a compiled binary:
syft ./bin/api -o cyclonedx-json=sbom.json# See what lowers the score
sbombox score sbom.json --format detailed
# Check a ruleset, e.g. EU Cyber Resilience Act readiness
sbombox compliance sbom.json -p cra-readiness
# Upload it to the active project, labelled with the release
sbombox push sbom.json --version v1.4.0Monorepos and workspaces
- A repository with several
go.modfiles has several modules. Runsbombox generate --dir path/to/modulefor each. - For several services in one module, run
cyclonedx-gomod apponce per-mainpackage and upload each to its own project. go.workworkspaces are a development aid. Generate release SBOMs per module or per binary.
Known gaps and how SBOMBox handles them
- Go has no built-in SBOM command. SBOMBox uses cyclonedx-gomod when installed, otherwise a universal tool.
- A module SBOM can list modules that are never compiled into your binary. Use
cyclonedx-gomod appor scan the binary for a release. - Go module metadata has no license field.
-licensesmakes cyclonedx-gomod detect licenses from the module source.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
No lockfile for golang: transitive dependencies may be missing and versions may be guessed. | go.sum not committed | Run go mod tidy, commit go.sum |
| Components with no license | Licenses not detected | Use cyclonedx-gomod with -licenses |
| Test-only modules in the SBOM | Module-level SBOM | Use cyclonedx-gomod app or scan the binary |
go version -m -json fails | Go older than 1.25 | Upgrade Go, or use go version -m without -json |
In CI, run the same commands. See GitHub Actions, GitLab CI, Jenkins, Azure Pipelines, Bitbucket Pipelines or CircleCI, or use the GitHub Action.