Add SBOM artifact using cyclonedx-gomod - #5220
Conversation
6f154d5 to
118f5bb
Compare
|
Converted to draft, while the scope of sbom is being discussed, and to exclude it from release concerns. The main shortcomings of the current report is that it doesn't include the "supplier" or the "copyright". NTIA (2021)SBOM Quality Score: 8.6/10.0 Grade: B Components: 107 EngineVersion: 8 File: bom.json Summary: NTIA (2025)SBOM Quality Score: 6.9/10.0 Grade: D Components: 107 EngineVersion: 8 File: bom.json Summary: Any value for the supplier is accepted, so it could be "name: Unknown" etc. The licenses needs to be asserted (from "evidence"), and 3 licenses added. The threshold for go-license-detector SPDX is currently hardcoded to 85%. Upgrading to github.com/go-enry/go-license-detector/v4 v4.3.1 will fix: [
{
"project": "vendor/github.com/balajiv113/fd",
"matches": [
{
"license": "MIT",
"confidence": 0.90066224,
"file": "LICENSE.MIT"
}
]
},
{
"project": "vendor/github.com/fatih/color",
"matches": [
{
"license": "MIT",
"confidence": 0.9096774,
"file": "LICENSE.md"
}
]
},
{
"project": "vendor/github.com/jinzhu/copier",
"matches": [
{
"license": "MIT",
"confidence": 0.9096774,
"file": "License"
}
]
}
]The missing hash on the top component (lima), is another such issue: if module.Main {
// We currently don't have an accurate way of hashing the main module, as it may contain
// files that are .gitignore'd and thus not part of the hashes in Go's sumdb.
logger.Debug().Str("module", module.Coordinates()).Msg("not calculating hash for main module")
return nil
}The new fields sbom_author and software_producer should be simple:
|
|
Here's the hack to get a perfect score with #!/usr/bin/env python3
import sys
import json
# organizationalContact
AUTHOR = {"name": "Unknown", "email": "unknown@example.com"}
# organizationalEntity
MANUFACTURER = {"name": "Unknown", "url": ["https://example.com"]}
# organizationalEntity
SUPPLIER = {"name": "Unknown"}
# organizationalEntity
NOASSERTION = {"name": "Unknown"}
def fix(sbom):
metadata = sbom.get("metadata", {})
if metadata.get("authors") is None:
metadata["authors"] = [AUTHOR]
if metadata.get("manufacturer") is None:
metadata["manufacturer"] = MANUFACTURER
if metadata.get("supplier") is None:
metadata["supplier"] = SUPPLIER
component = metadata.get("component", {})
if component.get("supplier") is None:
component["supplier"] = SUPPLIER
for component in sbom.get("components", []):
if component.get("supplier") is None:
component["supplier"] = NOASSERTION
sbom = json.load(sys.stdin)
fix(sbom)
json.dump(sbom, sys.stdout, indent=2)
print(file=sys.stdout)$ make sbom CYCLONEDX_GOMOD=cyclonedx-gomod CYCLONEDX_GOMOD_FLAGS="-licenses -assert-licenses"
$ ./bom-fix.py <bom.json >sbom.json
$ sbomqs score --profile ntia,ntia-2025 --basic sbom.json
10.0 A NTIA Minimum Elements (2021) 1.6 json sbom.json
10.0 A NTIA Minimum Elements (2025) - RFC 1.6 json sbom.jsonBut it is just a hack (even with the proper values), it doesn't add very much? Finding out the actual "supplier" for each go module is a bigger problem... |
AkihiroSuda
left a comment
There was a problem hiding this comment.
Please tidy up the commits
|
We can leave this feature out of 2.3.0 if needed, it can be recreated from the go.mod (and mods) That is, the bom.json does not really include any information that is not in "go.mod" and "vendor". |
This comment was marked as resolved.
This comment was marked as resolved.
|
I am leaving the lima hash as undefined (it does record the tag, but commit is currently broken*) e.g. Should not matter for release versions, where the commit is the tag. And the "hash" is undefined. The current consensus is that the SHA-256 of the Source code .tar.gz should be used, for the root. But currently we are not recording that anywhere, not in the Releases and not in the SHA256SUMS: The 2.1.5 is another bug in the tool, it uses the latest tag - not necessarily the one in the branch Again it should not matter for the release, since the current tag will be the most recent created. |
One for lima as a library, one for each cmd. https://github.com/CycloneDX/cyclonedx-gomod Add cyclonedx-gomod to hack/tools dir Running cyclonedx-gomod vendor fails Mention SBOM in README.md as required Upgrade go-license-detector to v4.3.1 Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
|
I added a separate issue for the missing hash of the top-level component: |
One for lima as a library, one for each cmd.
https://github.com/CycloneDX/cyclonedx-gomod
Closes #5219
Minor license problem with one dependency:
WRN no licenses detected module=github.com/balajiv113/fd@v0.0.0-20230330094840-143eec500f3eDBG detection confidence for license is too low confidence=0.8476821 license=MIT minConfidence=0.85 module=github.com/balajiv113/fd@v0.0.0-20230330094840-143eec500f3ei.e. they forgot to say "MIT License" :-)
https://github.com/balajiv113/fd/blob/master/LICENSE.MIT
https://spdx.org/licenses/MIT.html
TODO:
Use GitHub Actions for installingcyclonedx-gomod, instead ofgo install? cyclonedx-gomod-generate-sbomUsing go hack/tools instead.
Published to GitHub Releases.
The scope of this PR is to declare what software source code that went into the compiled binaries:
It does not do any files (e.g. checksums) or architectures, and does not cover any external drivers.
EDIT: The "app" SBOM actually was per-arch, while the "mod" SBOM is the same for all architectures.
The tool doesn't support cross-compiling, since it needs to be able to run a binary for the OS/ARCH.