Sub topic 5
BuildKit and Buildx: where attestations are produced
This chapter assumes you can write a Dockerfile, push an image to a registry, and read JSON with jq. It explains which tool creates SBOM and provenance attestations, so you know where to look when they are missing.
Two tools, two roles
Two components work together when you build an image:
- BuildKit is the build engine. It reads your Dockerfile, builds a graph of build steps, runs them, and produces the image.
- Docker Buildx is a command-line client for BuildKit. It adds the
docker buildxcommands, manages builders, and sends build requests to BuildKit.
BuildKit generates the attestations. Buildx asks for them with flags and decides how the result is exported. The classic docker build command can use BuildKit too, but the attestation flags are documented for docker buildx build, so this tutorial uses that command.
Why BuildKit is the right place
BuildKit sees the whole build. It knows which base image it pulled, which build stages ran, which build arguments were set, and which source files came in. A tool that scans a finished image later can only guess at most of this.
For provenance, BuildKit records the facts about the build itself. For the SBOM, it runs a scanner during the build. You will see how both are configured in later chapters.
Builders and drivers
A builder is a BuildKit instance that Buildx talks to. Each builder uses a driver, which controls how BuildKit runs. Common drivers are docker (the engine built into Docker), docker-container (BuildKit in its own container), kubernetes, and remote.
The driver matters because not every driver supports every feature. The docker-container driver supports attestations. The default docker driver on older setups may not, depending on whether the Docker Engine uses the containerd image store. A later chapter covers driver and registry requirements. For now, list your builders:
docker buildx lsTo create a builder that supports attestations and make it the default, run:
docker buildx create --name attest-builder --driver docker-container --useWhat Buildx adds to the build
When you pass --sbom or --provenance, Buildx turns the flags into attestation settings in the build request. BuildKit then does the work.
| Task | Done by |
|---|---|
| Parse flags such as `--sbom=true` and `--attest` | Buildx |
| Run the build steps | BuildKit |
| Scan for packages and write the SBOM | BuildKit (SBOM scanner) |
| Record build facts as provenance | BuildKit |
| Push the image and attestations | BuildKit exporter, started by Buildx |
Provenance has a default. Recent Buildx versions add min-mode provenance to images you push, even without a flag. SBOMs are not generated unless you ask for them.
Checking which tools you have
Confirm your versions before you debug missing attestations:
docker buildx version
docker buildx inspectThe inspect output shows the builder's driver and the BuildKit version. If the driver does not support attestations, or BuildKit is too old, the build can succeed with no attestations at all. That is a quiet failure, so check it first.
Exercise
Which component generates the SBOM and provenance attestations, and which component only requests them?
Show answer
BuildKit generates them. Docker Buildx only translates your flags, such as --sbom and --provenance, into a build request that asks BuildKit to produce them.
Exercise
A build with --sbom=true succeeds, but the output has no SBOM. Name two things to check.
Show answer
Check the builder's driver and BuildKit version with docker buildx inspect, because the driver may not support attestations. Also check the exporter, because attestations need an output that can hold an image index, such as a registry push.