Sub topic 6
Generating SBOM and provenance with docker buildx build
This chapter shows how to turn on SBOM and provenance attestations in docker buildx build. It covers the two flag styles, what each option changes, and the settings that make a build fail or silently produce nothing. It assumes you can write a Dockerfile, push to a registry, and read JSON with jq. It also assumes you know that images are identified by tags and digests, and that multi-platform images are published as an index.
What the build produces
Attestations are generated by BuildKit during the build. Buildx only passes your request to the builder. When you ask for an attestation, BuildKit does two things:
- It runs an SBOM scanner (by default the
docker/buildkit-syft-scannerimage) to list the packages in the result. - It records how the build ran, as SLSA provenance.
Each result is wrapped as an in-toto attestation and exported together with the image.
A small example image
Use this Dockerfile. The curl package it installs will appear in the SBOM.
FROM alpine:3.20
RUN apk add --no-cache curl
CMD ["curl", "--version"]Turning attestations on
The shortest form uses the dedicated flags. This command builds the image and pushes it with an SBOM and a max-mode provenance attestation:
docker buildx build \
--sbom=true \
--provenance=mode=max \
--tag registry.example.com/demo/app:1.0 \
--push .The longer --attest form is equivalent and lets you set the attestation type and its options explicitly. This example uses min-mode provenance:
docker buildx build \
--attest type=sbom \
--attest type=provenance,mode=min \
--tag registry.example.com/demo/app:1.0 \
--push .The two spellings map like this:
| Short flag | Long form | Meaning |
|---|---|---|
| `--sbom=true` | `--attest type=sbom` | Generate an SBOM with the default scanner |
| `--provenance=true` | `--attest type=provenance` | Generate provenance in the default mode (`min`) |
| `--provenance=mode=max` | `--attest type=provenance,mode=max` | Generate provenance with the most detail |
| `--provenance=false` | none | Do not generate provenance |
Use the --attest form when you need several options on one attestation, or when you want all attestation settings in one place in a script.
Defaults you might not expect
SBOM generation is off unless you ask for it. Provenance behaves differently. With a builder and image store that support attestations, Buildx adds min mode provenance to a pushed image even if you pass no flag. This surprises people who compare digests between builds or who push to a registry with limited support. To stop the default, either pass --provenance=false or set the environment variable BUILDX_NO_DEFAULT_ATTESTATIONS=1.
This command disables provenance for one build:
docker buildx build \
--provenance=false \
--tag demo/app:no-provenance \
--push .Use it when a consumer or registry cannot handle the extra manifests that attestations add to the index.
Changing the SBOM scanner
The scanner is a container image that BuildKit runs against the build result. You can replace it with the generator option:
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 must follow the BuildKit SBOM scanner protocol. It reads the filesystem to scan and writes an in-toto SPDX or CycloneDX document. Most users keep the default.
Two build arguments change what gets scanned. They are normal --build-arg values, and a later chapter covers them in detail:
BUILDKIT_SBOM_SCAN_CONTEXT=truealso scans the build context.BUILDKIT_SBOM_SCAN_STAGE=truescans an intermediate stage. You declare it as anARGinside that stage.
Builder requirements
Attestations need a builder that can export them. The default docker driver on the classic image store cannot, and Buildx reports an error about the exporter or driver. These are the usual ways to get a working setup:
- Create a builder with the
docker-containerdriver:docker buildx create --use --name attest-builder. - Use Docker Engine with the containerd image store enabled.
- Use a remote or Kubernetes builder.
The destination matters too. Attestations are extra manifests inside an image index, so the exporter must preserve indexes. The --push flag and type=registry do. A plain --load into the classic Docker image store does not, because that store holds single-platform images with no index. Check your builder and exporter first when a build succeeds but you find no attestations.
The local and tar exporters write attestations to disk as JSON files instead of an index. Use --output type=local,dest=./out when you want to inspect the documents without a registry.
Choosing provenance mode at build time
The mode controls how much the provenance records:
minrecords the build source, the builder, and timing and platform details, and leaves out the sensitive parts.maxadds full build arguments, the Dockerfile content, and detailed build steps.
docker buildx build \
--provenance=mode=max \
--build-arg API_ENDPOINT=https://internal.example.com \
--tag registry.example.com/demo/app:1.0 \
--push .In max mode that API_ENDPOINT value is stored in the attestation, and anyone who can pull the image can read it. Treat any value you pass with --build-arg as public if you use max. Secrets mounted with --secret are not recorded, but a secret written into a build argument is. Prefer min for public images and use max only when the audience for the registry is trusted.
You can also add options to the same attestation:
docker buildx build \
--attest type=provenance,mode=max,builder-id=https://ci.example.com/runners/build-7 \
--tag registry.example.com/demo/app:1.0 \
--push .The builder-id option sets a stable identifier for the system that ran the build. Verifiers can then match it against an allowed list.
Multi-platform builds
With several platforms, each platform's image gets its own SBOM and provenance:
docker buildx build \
--platform linux/amd64,linux/arm64 \
--sbom=true \
--provenance=mode=max \
--tag registry.example.com/demo/app:1.0 \
--push .The index then has four manifest entries for the two images and their two attestation sets. Packages can differ across architectures, so do not assume the amd64 SBOM describes the arm64 image.
Checking that it worked
After the push, read the attestations back with imagetools:
docker buildx imagetools inspect registry.example.com/demo/app:1.0 \
--format '{{ json .SBOM }}'
docker buildx imagetools inspect registry.example.com/demo/app:1.0 \
--format '{{ json .Provenance }}'Pipe the output through jq to read it comfortably:
docker buildx imagetools inspect registry.example.com/demo/app:1.0 \
--format '{{ json .SBOM }}' | jq .Empty output or null means the pushed image has no attestation of that type. The next chapters examine the content in detail.
Common errors
- No attestations after a successful build. The build used
--load, thedockerdriver, or an exporter that does not write indexes. Switch to adocker-containerbuilder and--push. - A registry or tool rejects the image. Some older registries and scanners cannot read the attestation manifests with an
unknown/unknownplatform. Retry with--provenance=falseand omit--sbom. - A secret appears in provenance. You passed it as a build argument in
maxmode. Rotate it, rebuild withmin, and move the value to--secret. - Digests change between otherwise identical builds. Provenance contains timing and builder data, so the index digest differs even when layers are the same. Compare image manifest digests, not the index digest.
- SBOM is missing a package. The scanner reads what is in the final filesystem. Software added without a package manager may not be detected.
Exercise
You run docker buildx build --sbom=true --tag demo/app:1.0 --load . on a default setup, and imagetools inspect finds no SBOM. Name two likely causes and the fix.
Show answer
The classic docker driver and image store cannot export attestations, and --load puts a single image into that store with no index to hold them. The fix is to use a docker-container builder (or the containerd image store) and push with --push to a registry that accepts the index, then inspect the pushed tag.
Exercise
A teammate builds with --provenance=mode=max --build-arg DB_PASSWORD=hunter2 and pushes to a shared registry. What is the risk, and what should change?
Show answer
In max mode the build arguments are stored in the provenance attestation, so anyone who can pull the image can read the password. Rotate the password, rebuild with mode=min or without the build argument, and supply the value through --secret so it is not recorded.