Sub topic 11
How the SBOM scanner works and what it misses
This chapter assumes you can already generate and inspect an SBOM attestation with docker buildx build --sbom=true. It covers how the scanner behind that flag produces its package list. It also covers which kinds of software end up missing from that list, because you can't treat an SBOM as complete without knowing this.
Where the scanner runs
BuildKit does not analyze your image itself. It delegates to a scanner, which is a container image. The default is docker/buildkit-syft-scanner, a thin wrapper around the open source tool Syft.
The sequence is:
- BuildKit builds the image as usual.
- For each platform, it starts the scanner image as an extra build step.
- It mounts the finished root filesystem of that platform into the scanner.
- The scanner reads the filesystem and writes an SBOM document to an output directory.
- BuildKit wraps the document in an in-toto statement and stores it as an attestation next to the image.
The scanner and BuildKit communicate through environment variables and directories:
| Variable | Meaning |
|---|---|
| `BUILDKIT_SCAN_SOURCE` | Directory containing the filesystem to scan |
| `BUILDKIT_SCAN_DESTINATION` | Directory where the scanner writes its output files |
The scanner writes a file such as sbom.spdx.json into the destination directory. BuildKit picks up the result. The default output format is SPDX JSON.
Because the scanner is an ordinary container image, you can replace it. Any image that follows the same contract can act as a generator:
docker buildx build \
--attest type=sbom,generator=registry.example.com/tools/my-scanner:1.0 \
--tag registry.example.com/demo/app:1.0 \
--push .Replacing the generator is how you get a different format such as CycloneDX, or a scanner with a different set of detectors. The rest of this chapter describes the default Syft-based scanner.
What the scanner detects
Syft works through catalogers. Each cataloger looks for one kind of package metadata in the filesystem. A package appears in the SBOM only if some cataloger recognizes evidence of it.
| Source of evidence | Examples of what is found |
|---|---|
| OS package databases | `/lib/apk/db/installed`, `/var/lib/dpkg/status`, the RPM database |
| Language manifests and lock files | `package-lock.json`, `requirements.txt`, `Gemfile.lock`, `pom.xml` |
| Installed language package metadata | Python `*.dist-info`, Node `node_modules/*/package.json`, Java archives |
| Embedded build information in binaries | Go build info (module list), Rust audit data when present |
Each entry in the SBOM carries a name, a version, and usually a package URL (purl) such as pkg:apk/alpine/[email protected]. It also records where in the filesystem the evidence was found. This is the main strength of the approach. The scanner reads the final image, so everything inherited from the base image is included. You don't have to list base image packages yourself.
A concrete example
The following Dockerfile installs one package through the package manager and adds one tool by hand.
FROM alpine:3.20
RUN apk add --no-cache curl
RUN printf '#!/bin/sh\necho hello\n' > /usr/local/bin/mytool \
&& chmod +x /usr/local/bin/mytool
CMD ["curl", "--version"]Build it with an SBOM and list the package names. The jq filter walks the whole document, so it works whether the output is nested under a platform key or not:
docker buildx build \
--sbom=true \
--tag registry.example.com/demo/app:1.0 \
--push .
docker buildx imagetools inspect registry.example.com/demo/app:1.0 \
--format '{{ json .SBOM }}' \
| jq -r '.. | .packages? | select(. != null) | .[].name' \
| sort -uThe list contains curl, libcurl, musl, busybox, and the other Alpine packages. It does not contain mytool. No package database or manifest mentions it, so no cataloger has a reason to report it. The file is in the image, but the SBOM is silent about it.
What the scanner misses
The scanner can only report what leaves evidence. These are the common gaps.
- Software installed outside a package manager. Files fetched with
curlorwget, tarballs unpacked into/optor/usr/local, and binaries compiled from source usually leave no metadata. Themytoolexample above is the simplest case. - Stripped or deleted metadata. A Dockerfile that removes
/var/lib/dpkgor/lib/apk/dbto save space also removes the evidence. Distroless-style images keep small per-package status files for this reason. - Statically linked or vendored code. A C binary with a statically linked library carries no record of that library. Go binaries are an exception when build info is included. Binaries built with
-trimpathstill keep module data, but binaries stripped of build info lose it. - Build-time dependencies. The default scan covers the final image only. Compilers, test frameworks, and packages in earlier stages of a multi-stage build never appear, even though they influenced the output. You can opt in to scanning other stages through build arguments, which a later chapter covers.
- Data and configuration. Model weights, fonts, and static assets are files, not packages. They are not listed.
- Unknown or renamed packages. Version strings may be wrong or missing when an application bundles a library under another name, such as a shaded Java jar.
The scanner can also over-report. It may list a development manifest that was copied into the image but isn't used at runtime, and the SBOM will list its packages as if they were installed.
Platforms and scope
The scan is per platform. A multi-platform build produces one SBOM attestation for each platform manifest. linux/arm64 can legitimately list different packages than linux/amd64, because package names, versions, and native binaries differ.
Scanning also adds build time, and it grows with the size of the filesystem. The scanner image must be pulled the first time. In an air-gapped environment, mirror it to your own registry and point generator= at the mirror.
The SBOM does not contain vulnerability information. It is an inventory. A vulnerability scanner reads the inventory and matches it against advisory databases. Because a package missing from the SBOM is also invisible to that matching step, SBOM gaps become blind spots in vulnerability reports.
Reducing the gaps
You cannot make the scanner see everything, but you can leave better evidence.
- Prefer package managers and lock files over ad hoc downloads.
- Pin versions and install from registries that produce metadata, such as
npm ciwith a lock file. - Do not delete package databases in final images.
- For tools installed by hand, record them separately, for example in labels or a checked-in manifest, or use a custom generator that knows about them.
- Keep the scanner current. Newer Syft releases add catalogers and fix version parsing, so a pinned old scanner image will miss packages a newer one finds.
You can check the effect directly. Compare the package list before and after a change, and confirm that the packages you expect are present:
docker buildx imagetools inspect registry.example.com/demo/app:1.0 \
--format '{{ json .SBOM }}' \
| jq -r '.. | .packages? | select(. != null) | .[] | "\(.name) \(.versionInfo)"' \
| grep -E '^(curl|mytool) 'Only the curl line appears. A check like this, run in CI against packages you know must be present, turns a silent gap into a failing build.
Exercise
A Dockerfile downloads a statically linked binary with wget into /usr/local/bin and then builds the final image. You build with --sbom=true. Will the binary appear in the SBOM, and why or why not?
Show answer
Most likely not. The scanner reports packages only when a cataloger finds evidence such as a package database entry, a manifest, or embedded build info. A downloaded binary leaves none of these, so it is in the image but absent from the SBOM. Embedded build info (for example in a Go binary) is the main exception.
Exercise
Your multi-stage build compiles the application in a stage that installs many development packages, and the final stage copies only the binary. Which of those development packages does the default SBOM list, and what can you do if you need them recorded?
Show answer
None of them. The default scan covers only the final image filesystem, so packages installed in earlier stages are not listed. To record them, opt in to scanning those stages with the BuildKit SBOM build arguments, or use a custom generator.