Sub topic 3
SBOMs: the inventory scanners work from
This chapter assumes you know how an image is built from layers and what a CVE is. A scanner cannot find vulnerabilities in an image until it knows what the image contains. That list of contents is the Software Bill of Materials (SBOM).
What an SBOM is
An SBOM is a machine-readable inventory of the components in a piece of software. For a container image, each entry usually records:
- The package name and version.
- The package type, such as
deb,apk,pypi, orgolang. - The location in the image where the package was found.
- A package URL (purl), a standard identifier such as
pkg:deb/debian/[email protected]. - Optionally, licenses and file hashes.
Scanners use this inventory to look for matches in vulnerability databases. The scan has two steps: build the inventory, then match it against advisories.
Where the inventory comes from
A cataloger reads the image layers and looks in known places:
- OS package databases, such as
/var/lib/dpkg/statuson Debian and Ubuntu or/lib/apk/db/installedon Alpine. - Language manifests and lockfiles, such as
requirements.txt,package-lock.json, orgo.mod. - Compiled binaries that embed dependency metadata. Go binaries are a common example.
Anything the cataloger cannot see is not in the SBOM, so the scanner cannot report vulnerabilities in it. Examples are a library copied in as a loose file, or a binary downloaded with curl during the build. A clean scan means "no known problems in what was cataloged". It does not mean "nothing is wrong".
Why the SBOM matters
Keeping the inventory separate from the matching has practical benefits:
- Re-matching without re-pulling. Advisory databases change daily. Docker Scout stores the SBOM of an analyzed image and matches it against new advisories as they appear. A new CVE can therefore show up against an image you scanned last week.
- Answering "are we affected?" When a new CVE is announced, you can search stored SBOMs for the package instead of scanning every image again.
- Auditing. Customers and regulators increasingly ask for an SBOM as a deliverable.
SBOM formats
Two formats are widely used.
| Format | Maintained by | Notes |
|---|---|---|
| CycloneDX | OWASP | Designed for security use. Trivy can write it, as you will see later in this tutorial. |
| SPDX | Linux Foundation | Strong on license compliance. Also accepted by many tools. |
Both are JSON or XML documents that list components with their versions and identifiers. The tools in this tutorial can produce or read at least one of them.
Attestations
An SBOM can travel with an image as an attestation, which is signed metadata attached to the image in the registry. Docker Buildx can attach one at build time:
docker buildx build --sbom=true --tag myapp:1.0 .Scanners can then read the SBOM that the build produced and skip re-cataloging the image. The SBOM reflects what the builder knew at build time, so it can still miss files added by unusual means.
Common errors
- Treating the SBOM as a vulnerability list. The SBOM contains no CVEs. Findings come from matching it against advisory data, and the result depends on which databases the tool uses.
- Trusting a stale SBOM. An SBOM generated for one build does not describe a later one. Regenerate it on every build.
- Assuming two tools will list the same packages. Catalogers differ in what they detect. This is one reason Docker Scout and Trivy can disagree, which a later chapter covers.
Exercise
A Dockerfile downloads a library archive with curl, unpacks it into /opt/lib, and never installs it with a package manager. A scanner reports no vulnerabilities for that library. Does this show the library is safe? Explain using the SBOM.
Show answer
No. The cataloger finds packages through package databases, lockfiles, and embedded metadata. A library unpacked into /opt/lib has none of these, so it is probably missing from the SBOM. The scanner cannot match what is not in the inventory, so the empty result says nothing about the library. To cover it, install it through a package manager or declare it in a lockfile.