Sub topic 11
How the SBOM scanner works and what it misses
This chapter assumes you can already build an image with --sbom=true and read JSON with jq. It covers what the scanner looks at, how to swap it out, and where its results are incomplete.
How the scanner runs
BuildKit does not build the SBOM from your Dockerfile instructions. After the build, it starts a separate scanner image against the resulting filesystem. The default scanner is docker/buildkit-syft-scanner, which wraps the open-source Syft tool. For each platform in the build, it:
- Mounts the final image filesystem.
- Runs Syft's catalogers over it. Each cataloger looks for one kind of package metadata.
- Writes an SPDX JSON document as an in-toto predicate.
What it detects
Catalogers read package manager databases and language manifests that exist in the image. These include apk, dpkg, and rpm databases. They also include language metadata such as package-lock.json, Python dist-info directories, Java archives, and Go build information embedded in binaries.
Build this image and list its packages:
FROM alpine:3.20
RUN apk add --no-cache curl
CMD ["curl", "--version"]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.SPDX }}' | jq -r '.packages[].name'The output lists curl, libcurl, musl, and the other packages apk installed. The .SBOM.SPDX path works for a single-platform image. For a multi-platform image, inspect .SBOM and pick a platform entry.
What it misses
The scanner only reports what it can identify from metadata or known file layouts. Common gaps:
| Case | Why it is missed |
|---|---|
| A binary fetched with `curl` or `wget` and copied into place | No package database entry or manifest |
| Statically linked C libraries | The library is inside the binary and leaves no metadata |
| Vendored source copied into the image | Looks like ordinary files |
| Stripped Go or Rust binaries | Build information was removed |
| Packages from an earlier build stage | Only the final stage is scanned by default |
| Files hidden by the `FROM scratch` pattern with no metadata | Nothing for a cataloger to read |
Detected versions can also be wrong. If someone edits files by hand or removes the package database, the SBOM reflects the leftover metadata and not the real contents.
Using a different scanner
You can replace the default with any image that follows the BuildKit scanner protocol:
docker buildx build \
--attest type=sbom,generator=docker/buildkit-syft-scanner:stable-1 \
--tag registry.example.com/demo/app:1.0 \
--push .A custom generator lets you pin the scanner version, so results stay stable across builds. It can also add cataloging for ecosystems the default misses. The scanner image must read the filesystem BuildKit gives it and write its output to the location BuildKit expects.
Scope beyond the final stage
By default only the final stage is scanned. Build arguments widen the scope to intermediate stages and to the build context. The next chapter covers those arguments. For now, remember that packages used only in a builder stage, such as compilers, do not appear in the default SBOM. That is usually what you want for the shipped image. It is a gap if you need a record of the build toolchain.
Exercise
You build a Go service image with FROM golang as a builder stage and FROM scratch as the final stage, using --sbom=true. The SBOM does not list the Go compiler, and it lists no OS packages. Explain both observations.
Show answer
The scanner reads only the final stage by default, so the compiler in the builder stage is not listed. The scratch stage has no package database, so there are no OS packages to find. The scanner can still list Go modules if the binary keeps its embedded build information.