Sub topic 14
Verifying images: signing, SBOMs, and provenance
This chapter assumes you can build and push images, you know what a registry is, and you have read the chapters on image pinning and vulnerability scanning. Pinning and scanning tell you what an image contains. They do not tell you who built it or whether it was changed after the build. Signing, SBOMs, and provenance cover those gaps.
Three questions about an image
- Who published this image? A signature answers this.
- What is inside it? A software bill of materials (SBOM) answers this. An SBOM is a list of the packages and libraries in the image.
- How was it built? Provenance answers this. Provenance is a record of the source repository, the commit, and the build system that produced the image.
An attacker who takes over a registry account or a build step can push a malicious image under a tag you trust. A digest pin stops a tag from being moved. It does not prove the digest came from your team.
Signing with Cosign
Cosign, from the Sigstore project, signs an image digest and stores the signature in the registry next to the image. With keyless signing, Cosign uses a short-lived certificate tied to your identity, such as a CI workload, so you do not manage long-lived private keys.
# Sign by digest, not by tag
cosign sign registry.example.com/team/myapp@sha256:<digest>
# Verify, and require a specific signer and issuer
cosign verify registry.example.com/team/myapp@sha256:<digest> \
--certificate-identity "https://github.com/example/myapp/.github/workflows/release.yml@refs/heads/main" \
--certificate-oidc-issuer "https://token.actions.githubusercontent.com"Replace <digest> with the real digest of your image. Verification must name the expected identity. A check that only asks "is there any valid signature?" accepts a signature from anyone.
Generating an SBOM and attestations
BuildKit can attach an SBOM and provenance to the image at build time.
docker buildx build \
--sbom=true \
--provenance=mode=max \
-t registry.example.com/team/myapp:1.0 \
--push .The --push flag matters here. Attestations are stored as extra entries in the image index, so they need a registry to hold them. To inspect them:
docker buildx imagetools inspect registry.example.com/team/myapp:1.0 \
--format '{{ json .SBOM }}'You can also scan an SBOM instead of the image. When a new CVE is announced, you can search stored SBOMs to find which images contain the affected package, without pulling every image.
How the pieces fit together
Common errors
- Signing a tag. Tags move. Sign and verify the digest.
- Verifying without an identity. Always pass the expected certificate identity and issuer, or a public key.
- Signing but never verifying. A signature protects you only if something checks it. Enforce the check in the deploy step or in an admission controller, which is a cluster component that blocks unverified images.
- Treating provenance as proof of safety. Provenance says where an image came from. It does not say the code is free of bugs. Keep scanning.
- Trusting an SBOM blindly. SBOMs can be incomplete, especially for binaries copied in without package metadata. Treat them as a strong inventory, not a guarantee.
Exercise
Your CI signs images by tag (myapp:1.0), and the deploy step runs cosign verify with no identity flags. Name two problems with this setup and how to fix each.
Show answer
First, the tag can be moved to a different image after signing, so the signature may not match what you deploy. Sign and verify the digest (myapp@sha256:...). Second, verifying without --certificate-identity and --certificate-oidc-issuer (or a public key) accepts a valid signature from any signer. Specify the expected CI identity and issuer so only your pipeline's signatures pass.