Sub topic 3
SBOMs: the inventory scanners work from
A Software Bill of Materials (SBOM) is the list of components inside an image. Scanners do not look for vulnerabilities directly. They build or read an inventory, then match each entry against advisory data. This chapter covers what an SBOM contains, where the inventory comes from, which formats you will meet, and where it can be wrong.
This chapter assumes you know how an image is built from layers and what a CVE identifier is. It also assumes you can read a short JSON file and run a Python script.
Inventory first, matching second
Every scan has two stages. The first stage answers "what is in this image?". The second answers "which of those things have known vulnerabilities?". The SBOM is the output of stage one and the input to stage two.
This split has three practical consequences:
- A component missing from the inventory can never produce a finding. A clean report only means "nothing known in what was found".
- The inventory can be stored. You can match the same SBOM against a newer advisory database next week without pulling the image again.
- The matching step can change while the inventory stays fixed. When two tools disagree, compare their inventories before you compare their findings.
What an SBOM entry contains
Each entry describes one component. The fields that matter for scanning are:
- Name and version. The matcher compares these against affected version ranges.
- Type. An operating system package, a language library, or an application.
- Package URL (purl). A standard identifier that encodes the ecosystem, namespace, name, and version in one string.
- Licenses and hashes. These are not used for vulnerability matching, but they make the SBOM useful for compliance and integrity checks.
A purl looks like this:
pkg:deb/debian/[email protected]~deb12u2?arch=amd64&distro=debian-12The prefix pkg:deb says the package came from the Debian packaging system. The distro qualifier matters because the same upstream library has different patched versions in different distribution releases. A matcher that ignores the distribution reports false positives or misses fixes.
Where the inventory comes from
A scanner reads files from the image filesystem. It does not run anything inside the container. Each kind of component has a known location.
| Source | What the scanner reads |
|---|---|
| Debian and Ubuntu packages | `/var/lib/dpkg/status` (and `/var/lib/dpkg/status.d/` in distroless images) |
| Alpine packages | `/lib/apk/db/installed` |
| Red Hat family packages | The RPM database under `/var/lib/rpm` |
| Python | Installed package metadata such as `*.dist-info` directories |
| Node.js | `package-lock.json`, `yarn.lock`, or installed `package.json` files |
| Go | Module information embedded in compiled binaries |
| Java | JAR and WAR files, including their bundled `pom.properties` |
The scanners process the layers in order and combine them into the final filesystem, so a file deleted in a later layer does not appear in the inventory. A file that is only hidden by a later layer still occupies space in the image, but the combined view is what a running container sees.
What the inventory misses
Package metadata is the reliable source. Anything that leaves no metadata is invisible:
- A binary downloaded with
curland copied into/usr/local/bin. - A library compiled from source with
make install. - Dependencies vendored into a source tree with no manifest.
- A stripped binary built without embedded module information.
These gaps are the most common reason a scanner reports nothing for software you know is old. They are also a reason to prefer package managers over manual installs.
Multi-stage builds add a related point. The SBOM describes only the final image. Compilers and libraries from earlier stages do not appear, because they are not in the shipped filesystem.
Two SBOM formats
Two formats dominate. Both are machine-readable, and most tools can read or write both.
| Property | SPDX | CycloneDX |
|---|---|---|
| Origin | Linux Foundation, originally for license compliance | OWASP, originally for security use |
| Typical file | JSON or tag-value text | JSON or XML |
| Strengths | License detail, broad compliance tooling | Vulnerability and dependency-graph focus |
| Used in this tutorial | Docker Scout can emit it | Trivy can emit it |
Pick the format that your consuming tool expects. If you have no constraint, choose the one your scanner writes natively, because conversions can drop fields.
Generating an SBOM
Trivy writes a CycloneDX SBOM from an image with a single command:
trivy image --format cyclonedx --output sbom.cdx.json python:3.12-slimDocker Scout can print the inventory it builds for an image. The default output is a readable list, and you can ask for a machine-readable format instead:
docker scout sbom python:3.12-slim
docker scout sbom --format spdx python:3.12-slimThe later chapter on Trivy reports covers output options in more detail. Here the point is that the inventory is a file you can keep.
Reading the file
A CycloneDX document has a top-level components array. This short script counts components by package ecosystem, using the purl prefix:
import json
import sys
from collections import Counter
def main(path):
with open(path, encoding="utf-8") as handle:
bom = json.load(handle)
components = bom.get("components", [])
counts = Counter()
for component in components:
purl = component.get("purl", "")
# "pkg:deb/debian/[email protected]" -> "deb"
ecosystem = purl.split("/", 1)[0].removeprefix("pkg:") if purl else "no-purl"
counts[ecosystem] += 1
print(f"format: {bom.get('bomFormat')} {bom.get('specVersion')}")
print(f"total components: {len(components)}")
for ecosystem, count in counts.most_common():
print(f" {ecosystem}: {count}")
if __name__ == "__main__":
if len(sys.argv) != 2:
sys.exit("usage: python summarize_bom.py sbom.cdx.json")
main(sys.argv[1])Run it with python summarize_bom.py sbom.cdx.json. For a Debian-based Python image you should see mostly deb entries for system packages, plus pypi entries for the installed Python packages. A count of zero pypi entries in an image you know ships Python dependencies is a sign that the scanner did not find their metadata.
Build-time SBOMs
You can also have the build produce an SBOM and attach it to the image as an attestation, which is a signed or structured statement stored alongside the image in the registry:
docker buildx build --sbom=true --push -t registry.example.com/myapp:2.0 .A build-time SBOM sees the build context, so it can record details a later filesystem scan cannot. The cost is that it reflects the moment of the build. An image that stays in a registry for months keeps the same SBOM while the advisory data keeps changing. Re-run the matching step regularly against the stored inventory, or rescan the image.
Common errors
- Comparing findings without comparing inventories. Two tools can list different versions for the same package, or one can list a package the other skipped. The finding counts will differ even if both matchers are correct.
- Treating an old SBOM as current. The inventory does not change, but the advisory data does. A stored SBOM from last quarter says nothing about CVEs published since.
- Scanning the wrong artifact. Scanning a tag instead of a digest can give different results from one day to the next if the tag moves. Record the digest next to the SBOM.
- Assuming the SBOM includes the base image's history. It describes the final filesystem only.
Exercise
You scan an image that runs a Go service. The scanner reports no Go library findings, but the image's Dockerfile copies a Go binary built in an earlier stage with go build -ldflags="-s -w". Give one likely reason the inventory has no Go entries, and one way to check it.
Show answer
The inventory for Go comes from module information embedded in the binary. If the build stripped or omitted that information (or the binary was built outside a module), the scanner has nothing to read. To check, generate the SBOM and count the Go entries (purls starting with pkg:golang) with the script above. You can also run go version -m /app on the binary outside the container to see whether module data is present. Rebuilding without stripping the module data, or supplying a build-time SBOM, restores the entries.
Exercise
A teammate says: "Our SBOM was generated at build time six months ago and shows no vulnerabilities, so the image is fine." What is wrong with this claim, and what would you do?
Show answer
The SBOM is only an inventory. Findings depend on the advisory database at match time, which has changed in six months. Re-run the matching step against the stored SBOM, or rescan the image, with a current database. Also confirm that the SBOM still corresponds to the deployed image by comparing the image digest.