Sub topic 13
From attestations to verified trust: signing and policy checks
This chapter assumes you can build and push an image with docker buildx build, that you know how attestations sit in an image index, and that you can read JSON with jq. It also assumes you have cosign installed and a CI system that can issue identity tokens.
Why unsigned attestations are only claims
An SBOM or provenance attestation made by BuildKit is a statement about how an image was built. Anyone who can push to the registry can push a different image with a different statement. A consumer who reads the attestation learns what the publisher says, not what is true.
To turn the claim into trust, you need two things:
- A signature that ties the image, and the attestations in its index, to a known identity.
- A policy check that compares the attestation contents with rules you set.
Sign the digest of the index
BuildKit stores the SBOM and provenance as manifests inside the image index. The index lists each of them by digest. If you sign the index digest, the signature therefore covers every manifest the index references, attestations included. Always sign a digest, never a tag, because a tag can be moved.
DIGEST=$(docker buildx imagetools inspect registry.example.com/demo/app:1.0 \
--format '{{ json .Manifest }}' | jq -r .digest)
cosign sign "registry.example.com/demo/app@${DIGEST}"In CI, cosign sign can use keyless signing. The CI job's identity token is exchanged for a short-lived certificate, so you do not manage a long-lived private key.
Verify the signature
A verifier must state which identity it expects. Verifying only that "some signature exists" proves nothing.
cosign verify \
--certificate-identity "https://github.com/example/demo/.github/workflows/build.yml@refs/heads/main" \
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
"registry.example.com/demo/app@${DIGEST}"The command fails if the signature is missing, if it was made by a different identity, or if the digest does not match.
Check attestation contents against a policy
A valid signature says who published the index. A policy check says whether the build meets your rules. For example, you can require that provenance exists before you accept the image.
docker buildx imagetools inspect \
"registry.example.com/demo/app@${DIGEST}" \
--format '{{ json .Provenance }}' \
| jq -e 'any(..; type == "object" and has("buildType"))' > /dev/null \
&& echo "provenance present" \
|| { echo "provenance missing"; exit 1; }The -e flag makes jq exit with a non-zero status when the test is false, so the script can gate a pipeline. Real policies go further. They can check that the source repository is the expected one, that the build ran on your CI, or that the SBOM lists no banned package. Policy engines such as Docker Scout policies, OPA, or Kyverno can run these checks for you. In every case, run the check on the digest you verified, not on a tag you resolve later.
Common errors
| Mistake | Effect |
|---|---|
| Signing a tag instead of a digest | The tag can later point to different content that the signature does not cover. |
| Verifying without an expected identity | Any signer passes, including an attacker. |
| Checking attestations of one tag and deploying another | The checked content and the deployed content can differ. |
| Treating a missing attestation as a pass | Policies must fail closed. |
Exercise
Why does signing the image index digest also protect the SBOM and provenance attached by BuildKit, and why must you pass an expected identity to cosign verify?
Show answer
The index lists the image manifests and the attestation manifests by digest, so the index digest changes if any of them change. A signature on that digest therefore covers all of them. The expected identity is needed because a signature only proves that some signer signed the digest. Without a required identity and issuer, a signature from an attacker would also pass.