Sub topic 5
BuildKit and Buildx: where attestations are produced
This chapter assumes you can write a Dockerfile, run docker build, push to a registry, and read JSON with jq. It also assumes you know that an SBOM lists software components and that provenance describes how an artifact was built. Here you learn which component creates those records, which component asks for them, and what that means for your builds.
Two tools, two roles
People often say "Docker builds the image", but two separate programs are involved.
- BuildKit is the build engine. It reads a build definition, runs the steps, caches the results, and exports the output. It runs either inside the Docker daemon or as a standalone daemon called
buildkitd. - Docker Buildx is a command-line client. It is a plugin for the
dockerCLI that talks to BuildKit. It also manages builders, which are named BuildKit instances.
Attestations come from BuildKit. Buildx is how you ask for them. docker buildx build accepts the options --sbom, --provenance and --attest, translates them into build options, and sends them to the builder. BuildKit produces the attestation data, and Buildx or BuildKit pushes the result.
| Component | Role in attestations |
|---|---|
| Buildx | Parses `--sbom`, `--provenance` and `--attest`. Sends them to the builder. Reads attestations back with `imagetools inspect`. |
| BuildKit solver | Knows every step, input and source of the build. Records this as provenance. |
| Frontend (for example the Dockerfile frontend) | Turns the Dockerfile into BuildKit's internal build graph. Adds frontend details such as the Dockerfile source in max mode. |
| SBOM scanner | A container image that BuildKit runs against the finished filesystem to produce the SBOM. |
| Exporter | Writes the image and its attestations to a registry, a local directory or an image store. |
Why BuildKit is the right place
BuildKit sees facts that nobody can reconstruct reliably afterwards:
- Which base images were resolved, including their digests.
- Which build arguments and secrets were used.
- Which files came from the build context and which from other stages.
- Which platform each part of the output was built for.
A tool that scans a finished image has only the final filesystem. BuildKit has the filesystem and the process that created it. That is why provenance can only be made at build time, and why the SBOM scanner is wired into the build instead of running afterwards.
The flow of a build with attestations
Two details matter here:
- The scanner is a separate container image. By default BuildKit uses
docker/buildkit-syft-scanner, which is based on Syft. You can replace it with thegeneratoroption, covered in a later chapter. - BuildKit creates the provenance itself from the solve. You do not install anything for it.
Setting up a builder that can produce attestations
The builder you use decides whether attestations work. A driver is the way a builder runs BuildKit. The classic docker driver, which uses the BuildKit inside the Docker daemon, cannot export attestations unless the daemon uses the containerd image store. The docker-container driver runs BuildKit in its own container and supports attestations in all cases. A later chapter covers drivers and registries in full. For now, create a dedicated builder:
docker buildx create --name attest-builder --driver docker-container --use
docker buildx inspect --bootstrapThe --bootstrap flag starts the builder container and prints its details. Check these fields in the output:
Driver: docker-container- the BuildKit version, which should be recent (provenance and SBOM support arrived in BuildKit 0.11)
- the platforms the builder can build for
List your builders and see which one is active with:
docker buildx lsThe active builder has a * after its name.
Building with attestations
Use this small Dockerfile. The package curl will appear in the SBOM:
FROM alpine:3.20
RUN apk add --no-cache curl
CMD ["curl", "--version"]Build and push with both attestations:
docker buildx build \
--sbom=true \
--provenance=mode=max \
--tag registry.example.com/demo/app:1.0 \
--push .--sbom=true is shorthand for --attest type=sbom. --provenance=mode=max is shorthand for --attest type=provenance,mode=max. The long form is useful when you want to pass more options:
docker buildx build \
--attest type=sbom \
--attest type=provenance,mode=min \
--tag registry.example.com/demo/app:1.0 \
--push .Both forms send the same request. They differ only in how options are written.
What Buildx adds by default
Buildx adds provenance by itself in some cases, so you may have attestations without asking for them. From Buildx 0.10, a build that pushes to a registry gets mode=min provenance unless you disable it. SBOMs are never on by default, because they add scan time and need the scanner image.
This default has side effects. The image you push is no longer a single manifest. It becomes an image index (a manifest list) that contains the image manifest plus extra attestation manifests. Some tools handle this badly:
- Registries or mirrors that reject unknown manifest types.
- Scripts that assume a tag points directly at one image manifest.
- Deployment tools that read the first entry of an index.
If a consumer cannot handle the extra manifests, turn provenance off for that build:
docker buildx build \
--provenance=false \
--tag demo/app:no-provenance \
--push .Checking that the builder produced attestations
After a push, read them back with Buildx. This also confirms the client and the builder agree:
docker buildx imagetools inspect registry.example.com/demo/app:1.0 \
--format '{{ json .SBOM }}' | jq .
docker buildx imagetools inspect registry.example.com/demo/app:1.0 \
--format '{{ json .Provenance }}' | jq .If either command prints null or an empty result, the attestation was not created. The next section lists the usual causes.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Error that attestations are not supported by the current driver | Using the default `docker` driver with the classic image store | Create a `docker-container` builder, or enable the containerd image store |
| `--load` with `--sbom` fails or drops attestations | The classic Docker image store cannot hold an index with attestations | Push with `--push`, or export with `--output type=local` or `type=oci` |
| SBOM is empty or missing | `--sbom` was not set, or the build was cached from an earlier run without it | Add the flag, and check the cache if the result looks stale |
| Registry rejects the push | Registry does not accept attestation manifests | Use a registry that supports OCI image indexes, or disable attestations |
| Provenance present but SBOM missing | Provenance is a default, SBOM is not | Set `--sbom=true` explicitly |
What BuildKit does not do
BuildKit records what happened. It does not check it. The provenance reflects what the solver did, and the SBOM reflects what the scanner found. Neither is signed by default, and neither proves that the builder itself was trustworthy. Later chapters on signing and the trust model return to this limit.
Exercise
A teammate runs docker buildx build --sbom=true --push . on the default builder with the classic image store and gets an error about attestations. Which component produces attestations, which one did the teammate use to request them, and what is the quickest fix?
Show answer
BuildKit produces the attestations (the solver makes provenance, the scanner image makes the SBOM). The teammate used Buildx to request them. The default docker driver cannot export attestations with the classic image store, so the fix is to create and use a docker-container builder with docker buildx create --name attest-builder --driver docker-container --use and run the build again.
Exercise
You build and push an image with only --provenance=false, but the tag still points to an image index instead of a single manifest. What is the likely reason, and how do you get a single manifest?
Show answer
The build also had --sbom=true (or another attestation) enabled, and any attestation forces an image index. Disable the SBOM as well, or set both --sbom=false and --provenance=false, so the exporter writes a plain image manifest.