Sub topic 13
From attestations to verified trust: signing and policy checks
This chapter assumes you can build and push images with docker buildx build. It also assumes you know that BuildKit stores SBOM and provenance attestations in the image index, and that you can read JSON with jq. The previous chapter covered the limits of unsigned attestations. This one covers the next step: making the metadata something a consumer can trust, and then checking it automatically.
Why unsigned attestations are not proof
An attestation attached by docker buildx build is a JSON document in the registry. Anyone who can push to the repository can push a different index with different attestations. docker buildx imagetools inspect prints what is stored. It does not check who wrote it.
Trust needs two more things:
- Authenticity and integrity. A signature ties a digest to an identity, such as a CI workflow or a key holder. It proves the content has not changed since that identity signed it.
- Policy. A rule that decides whether the signed content is acceptable. Examples: "built from our main branch", "built by our CI", "no package with a known critical vulnerability".
A signature without policy only says someone signed the image. Policy without a signature checks data that may be forged.
What gets signed
BuildKit stores attestations as extra manifests inside the image index. The index lists each attestation manifest by digest. A signature over the index digest therefore covers the image manifests and the attestation manifests, because changing any of them changes the index digest.
Always sign by digest, never by tag. A tag can move after you sign it.
Get the index digest after a push:
docker buildx imagetools inspect registry.example.com/demo/app:1.0 \
--format '{{ json .Manifest.Digest }}'The command prints a quoted sha256: value. Use it to form registry.example.com/demo/app@sha256:<digest>.
Signing with Sigstore cosign
Cosign is a common signing tool from the Sigstore project. In keyless mode it uses a short-lived certificate tied to an OIDC identity. In CI, that identity is the workflow run. There are no long-lived private keys to protect.
Sign the pushed index:
cosign sign --yes \
registry.example.com/demo/app@sha256:<digest>Verify it, naming the identity you expect:
cosign verify \
--certificate-identity "https://github.com/example/app/.github/workflows/release.yml@refs/heads/main" \
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
registry.example.com/demo/app@sha256:<digest>The two --certificate-* flags are the important part. Without them you only learn that someone signed the image. With them you learn that the specific workflow on main signed it.
Two attestation locations
BuildKit attestations live inside the image index. Cosign's own attestations (cosign attest) are separate OCI artifacts attached to the image. The two are not interchangeable, and cosign verify-attestation does not read BuildKit's in-index manifests.
You have two options:
| Approach | How it works | Trade-off |
|---|---|---|
| Sign the index only | `cosign sign` on the index digest. The signature covers the BuildKit attestations indirectly. | Simple. Policy tools must read the in-index attestations themselves. |
| Re-attach as cosign attestations | Extract the predicate and run `cosign attest`. Admission tools can then use `verify-attestation`. | Two copies of the data. You must keep them consistent. |
For the second approach, extract the provenance and attach it:
docker buildx imagetools inspect registry.example.com/demo/app:1.0 \
--format '{{ json .Provenance }}' > provenance.json
cosign attest --yes \
--type slsaprovenance \
--predicate provenance.json \
registry.example.com/demo/app@sha256:<digest>Check the shape of provenance.json before attaching it. For a multi-platform image the output is keyed by platform, and --predicate expects the predicate body itself. You may need jq to pick one platform's entry.
Some platforms combine these steps. GitHub's artifact attestations and Docker Scout read the BuildKit attestations directly, so you may not need to re-attach anything.
Writing a policy check
Policy can be as simple as a script in CI. This one reads provenance JSON from standard input and checks two things: the source repository, and a non-empty builder identity. It finds every predicate in the document, so it works for single-platform and multi-platform output.
import json
import sys
EXPECTED_REPO = "https://github.com/example/app"
def find_predicates(node):
"""Collect every dict that looks like a SLSA v0.2 provenance predicate."""
found = []
if isinstance(node, dict):
if "buildType" in node:
found.append(node)
else:
for value in node.values():
found.extend(find_predicates(value))
elif isinstance(node, list):
for item in node:
found.extend(find_predicates(item))
return found
def check(predicate):
errors = []
config = predicate.get("invocation", {}).get("configSource", {})
uri = config.get("uri", "")
if not uri.startswith(EXPECTED_REPO):
errors.append(f"unexpected source: {uri or 'missing'}")
if not predicate.get("builder", {}).get("id"):
errors.append("builder id is empty")
return errors
def main():
predicates = find_predicates(json.load(sys.stdin))
if not predicates:
sys.exit("no provenance predicate found")
failed = False
for predicate in predicates:
for error in check(predicate):
print("FAIL:", error)
failed = True
if failed:
sys.exit(1)
print("provenance policy passed")
main()Run it against the registry copy:
docker buildx imagetools inspect registry.example.com/demo/app:1.0 \
--format '{{ json .Provenance }}' | python3 check_provenance.pyThe script assumes SLSA v0.2 field names (builder, invocation, buildType). Newer BuildKit versions can emit SLSA v1, which uses different fields such as buildDefinition and runDetails. Check which version your builder produces before relying on field names.
What to check
- Source. The repository URI and the commit digest match what you expect. In
maxmode, BuildKit records the source in more detail. - Builder identity. BuildKit leaves
builder.idempty unless the CI system sets it. GitHub Actions integrations set it to the workflow run. An empty value means the claim names no builder. - Materials. The base image digests should be pinned and on an approved list.
- SBOM content. No package from a deny list, and no missing SBOM where one is required.
The check is only as strong as the signature behind it. A forged attestation that names the right repository passes this script. The policy has to run after signature verification, on content that came from a signed digest.
Enforcing at deploy time
Checking in CI protects the pipeline. Checking at admission protects the cluster, because it blocks images that skipped the pipeline.
Common enforcement points:
- Kubernetes admission controllers such as Kyverno or the Sigstore policy-controller. They verify signatures and attestation predicates before a pod starts.
- Docker Scout policies, which evaluate SBOM and provenance of images in a registry or in CI.
- Registry-side or platform-side gates, such as a promotion step that only copies verified digests into the production repository.
Enforce by digest where you can. A tag-based deployment can pass verification and then pull a different image if the tag moves between check and pull.
Failure modes
| Failure | Effect | Mitigation |
|---|---|---|
| Verifying without identity flags | Any signer passes | Always set expected identity and issuer |
| Signing a tag | Tag can move to unsigned content | Sign and deploy by digest |
| Re-signing in a later step | The signature says "this passed our pipeline", not "this was built by our pipeline" | Sign in the build job itself |
| Provenance from an untrusted build step | The attestation is accurate about a compromised build | Isolate and harden the build environment |
| Copying an image with a tool that drops attestations | Attestations are lost in the target registry | Use tools that copy the whole index, and verify after copying |
Signed provenance proves what the builder claims and who the builder was. It does not prove the build was free of compromise. A malicious build step can produce a truthful attestation about a malicious build. Signing moves the trust to the build platform, so protecting that platform matters as much as the signature.
Exercise
You sign registry.example.com/demo/app:1.0 with cosign sign and later deploy by tag. A teammate pushes a different image to the same tag. Why can the deployment still run unsigned content, and what should change?
Show answer
The signature is attached to the digest that the tag pointed to when you signed. Moving the tag changes which digest the deployment pulls, and that new digest has no signature unless the admission check verifies it. Sign by digest (app@sha256:...), deploy by digest, and have the verifier reject any digest without a valid signature from the expected identity.
Exercise
cosign verify succeeds with no --certificate-identity flag. What have you learned, and what have you not learned?
Show answer
You have learned that the image digest has a valid signature from some identity that Sigstore accepted. You have not learned who signed it. Anyone with an OIDC account can pass this check. Add --certificate-identity and --certificate-oidc-issuer so only the expected workflow passes.
Exercise
The Python policy script prints "provenance policy passed" for an image whose attestation names the right repository. Name one reason that result is still not enough to trust the image.
Show answer
The script does not verify a signature. Anyone who can push to the registry could have written an attestation naming the right repository. Verify the signature on the index digest first, then run the policy on content from that digest.