Sub topic 2
What an SBOM is and what it lists
This chapter assumes you can write a Dockerfile and push an image to a registry. It also assumes you can read JSON with jq. The earlier chapter covered why supply chain metadata matters. This one covers the SBOM itself: what the document is, what it contains, and how to read it.
What an SBOM is
A Software Bill of Materials (SBOM) is a machine-readable inventory of the components inside a piece of software. It works like an ingredients list on food packaging. It tells you what is in the artifact. It does not tell you whether those ingredients are safe.
For a container image, the components are mostly:
- Operating system packages, such as
apk,dpkg, orrpmpackages. - Language packages, such as Python wheels, npm modules, Go modules, Java JARs, or Rust crates.
- Binaries and libraries that a scanner can identify.
An SBOM answers questions such as these:
- Which version of OpenSSL is in this image?
- Is a newly announced vulnerable library present in any image we shipped?
- Which licenses apply to what we distribute?
Because the inventory is structured data, tools can answer these questions automatically across thousands of images.
SBOM formats
Two formats dominate:
| Format | Maintained by | Typical focus |
|---|---|---|
| SPDX | Linux Foundation | Licensing and compliance, general inventory |
| CycloneDX | OWASP | Security and vulnerability management |
BuildKit's default SBOM scanner produces SPDX, serialized as JSON. When BuildKit wraps the SBOM as an attestation, the in-toto predicate type is https://spdx.dev/Document. The next chapter covers the in-toto wrapper. This chapter looks only at the SPDX document inside it.
How a build produces one
The default scanner runs as a BuildKit step after your image is assembled. It is distributed as the image docker/buildkit-syft-scanner, and it uses the Syft cataloging library. It reads the final filesystem, recognizes package databases and language manifests, and writes an SPDX document.
Here is a small Dockerfile. It installs one extra package, curl, so you can find that package in the SBOM later.
FROM alpine:3.20
RUN apk add --no-cache curl
CMD ["curl", "--version"]Build it and push it with SBOM generation turned on:
docker buildx build \
--sbom=true \
--provenance=mode=max \
--tag registry.example.com/demo/app:1.0 \
--push .Chapter 6 covers the build flags in detail. For now, --sbom=true is the part that matters.
The structure of an SPDX document
Print the SBOM of the pushed image:
docker buildx imagetools inspect registry.example.com/demo/app:1.0 \
--format '{{ json .SBOM }}' | jq .The output has an SPDX object. If the image is multi-platform, the output is keyed by platform first, for example linux/amd64, and each platform has its own SPDX object. If you are unsure of the shape, run the same command with | jq 'keys' first.
The examples below assume a single-platform image. For a multi-platform image, add the platform key before .SPDX.
An SPDX document has these main sections.
Document metadata
The top-level fields describe the document itself:
spdxVersion: the SPDX specification version, for exampleSPDX-2.3.SPDXID: the identifier of the document, alwaysSPDXRef-DOCUMENT.name: a label for what was scanned.documentNamespace: a unique URI for this document.creationInfo: when the document was created and which tool created it (creators).
Print just these fields:
docker buildx imagetools inspect registry.example.com/demo/app:1.0 \
--format '{{ json .SBOM }}' \
| jq '.SPDX | {spdxVersion, name, documentNamespace, creationInfo}'The creators list in creationInfo names the scanner and its version. This tells you which tool's detection rules produced the inventory. Two different scanner versions can give different results for the same image.
Packages
The packages array is the core of the SBOM. Each entry describes one component. Common fields:
| Field | Meaning |
|---|---|
| `name` | Package name, such as `curl` |
| `versionInfo` | Package version |
| `SPDXID` | Identifier used by other parts of the document to refer to this package |
| `downloadLocation` | Where the package came from, or `NOASSERTION` if unknown |
| `licenseConcluded` / `licenseDeclared` | License information, often `NOASSERTION` |
| `externalRefs` | Extra identifiers such as a package URL (purl) or a CPE |
List every package with its version:
docker buildx imagetools inspect registry.example.com/demo/app:1.0 \
--format '{{ json .SBOM }}' \
| jq '.SPDX.packages | map({name, versionInfo})'For the example image you should see curl, its library dependencies such as libcurl, and base system packages from Alpine, including musl and busybox. The exact list depends on the Alpine release that the 3.20 tag resolves to when you build.
Count the packages:
docker buildx imagetools inspect registry.example.com/demo/app:1.0 \
--format '{{ json .SBOM }}' \
| jq '.SPDX.packages | length'The count includes more than your installed packages. Syft may add an entry that represents the image or filesystem itself, so the count can be one or two higher than the number of installed packages.
Identifiers: purl and CPE
A package name alone is ambiguous. Two ecosystems can both have a package named requests. For this reason, entries carry externalRefs. The two types you will see most are:
- purl (package URL): a standard way to write a package identity, such as
pkg:apk/alpine/curl@<version>?arch=<arch>. It includes the ecosystem, so it is unambiguous. - CPE (Common Platform Enumeration): an identifier that vulnerability databases such as the NVD use.
Vulnerability scanners match on these identifiers. If an identifier is wrong or missing, a vulnerability may be missed or a false match may appear. Extract all purls:
docker buildx imagetools inspect registry.example.com/demo/app:1.0 \
--format '{{ json .SBOM }}' \
| jq -r '.SPDX.packages[].externalRefs[]? | select(.referenceType=="purl") | .referenceLocator'The ? after externalRefs[] stops jq from failing on packages that have no references.
Files and relationships
The relationships array connects elements by SPDXID. Examples:
SPDXRef-DOCUMENT DESCRIBES <image or filesystem>marks what the document is about.<package> CONTAINS <file>links a package to files that belong to it.<package> DEPENDS_ON <package>records a dependency, when the scanner can determine it.
Some scans also include a files array that lists individual files with checksums. How much file-level detail you get depends on the scanner and its configuration.
Count the relationship types to see what the document describes:
docker buildx imagetools inspect registry.example.com/demo/app:1.0 \
--format '{{ json .SBOM }}' \
| jq '.SPDX.relationships | group_by(.relationshipType) | map({type: .[0].relationshipType, count: length})'What the SBOM does and does not tell you
Keep these limits in mind when you read an SBOM:
- Completeness depends on detection. The scanner recognizes known package databases and manifests. Software copied in as a plain binary, compiled statically, or vendored without a manifest may not appear. Chapter 11 returns to this.
NOASSERTIONmeans unknown. It does not mean "no license" or "no source". Do not treat it as a negative finding.- An SBOM is a snapshot. A package list that was accurate at build time says nothing about vulnerabilities disclosed later. Re-run vulnerability matching against stored SBOMs when new advisories appear.
- An unsigned SBOM can be replaced. Anyone who can write to the registry could attach a different one. Chapters 13 and 14 cover signing and the trust model.
Reading an SBOM in practice
A useful routine when you first look at an SBOM:
- Check
creationInfoto see which scanner and version made it. - Count the packages and compare the number to what you expect from the Dockerfile.
- Search for a package you know you installed, such as
curl, and confirm its version. - Check that entries have purls. If many do not, vulnerability matching will be weak.
- Look at
relationshipsto see whether dependencies were recorded.
Step 3 can be done with one filter:
docker buildx imagetools inspect registry.example.com/demo/app:1.0 \
--format '{{ json .SBOM }}' \
| jq '.SPDX.packages[] | select(.name=="curl") | {name, versionInfo, externalRefs}'Exercise
You inspect the SBOM of an image built from FROM scratch that contains one statically linked Go binary. The package list has almost no entries. Is the image free of third-party code? What should you check?
Show answer
No. The scanner reads package databases and manifests, and a scratch image has none. A static Go binary can still contain many third-party modules. Syft can sometimes read Go module information embedded in the binary, so check whether the SBOM lists Go module packages with purls such as pkg:golang/.... If it does not, the SBOM is incomplete and you need another source, such as the project's go.mod or a scan of the build context.
Exercise
Write a jq filter that prints only the name and version of packages whose purl starts with pkg:apk/. Assume a single-platform image.
Show answer
jq '.SPDX.packages[] | select(any(.externalRefs[]?; .referenceType=="purl" and (.referenceLocator | startswith("pkg:apk/")))) | {name, versionInfo}', applied to the output of docker buildx imagetools inspect <ref> --format '{{ json .SBOM }}'.