Sub topic 14
Verifying images: signing, SBOMs, and provenance
Earlier chapters hardened the image contents and the way containers run. This chapter covers a different question: how do you know the image you are about to run is the one your pipeline built, and what is inside it? It assumes you can build and push images, you know what a digest is (from the pinning chapter), and you have used a CI system such as GitHub Actions.
What verification adds
A digest pins an image to exact bytes, but it doesn't say who produced those bytes. An attacker who can push to your registry, or who compromises a build step, can publish a malicious image with its own valid digest. Three kinds of evidence close that gap:
- A signature says a specific identity vouches for a specific digest.
- An SBOM (software bill of materials) lists the packages and libraries inside the image.
- A provenance attestation records how the image was built: the source repository, commit, builder, and build parameters.
Each is stored as metadata attached to the image, usually in the same registry. Evidence helps only if something checks it. A signature nobody verifies protects nothing.
Signing images with Cosign
Cosign, from the Sigstore project, is the most widely used tool for signing OCI images. It stores the signature in the registry next to the image, so you need no separate signature server.
There are two signing modes.
Key-based signing uses a key pair that you generate and protect:
cosign generate-key-pair
cosign sign --key cosign.key registry.example.com/team/app@sha256:<digest>
cosign verify --key cosign.pub registry.example.com/team/app@sha256:<digest>You must store cosign.key as a secret, rotate it, and distribute cosign.pub to every verifier. If the private key leaks, every past and future signature is suspect.
Keyless signing removes long-lived keys. The signer authenticates with an OpenID Connect (OIDC) identity, such as a GitHub Actions workflow token. Sigstore's certificate authority, Fulcio, issues a short-lived certificate bound to that identity. The signing event is recorded in a public transparency log, Rekor. In CI:
cosign sign --yes registry.example.com/team/app@sha256:<digest>The verifier then states which identity and issuer it trusts:
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/team/app@sha256:<digest>This binds trust to "the release workflow on the main branch of this repository" instead of to a key file.
Choosing between the modes
| Aspect | Key-based | Keyless |
|---|---|---|
| Secret to protect | Private key | None long-lived |
| Verifier trusts | A public key | An identity and issuer |
| Needs public services | No | Fulcio and Rekor, unless self-hosted |
| Works in an air-gapped network | Yes | Only with a private Sigstore deployment |
| Key rotation burden | You | None |
Use keyless for public CI systems that already issue OIDC tokens. Use key-based, ideally with keys held in a KMS or hardware module, when you run offline or must avoid public infrastructure.
Docker Content Trust and Notary
Docker Content Trust (DCT) is the older built-in mechanism. You turn it on with export DOCKER_CONTENT_TRUST=1, after which docker pull and docker run refuse unsigned tags. It is built on Notary v1 and signs tags, not digests. Adoption has been limited, tooling support has declined, and it needs a Notary server. Treat it as legacy. If you already depend on it, plan a move to Sigstore or Notation, the Notary Project's newer signing tool, which also works with OCI registries.
Generating SBOMs
An SBOM answers "what is in this image?" That matters on the day a new vulnerability is announced. Instead of rebuilding and rescanning everything, you search stored SBOMs for the affected package.
Two common formats are SPDX and CycloneDX. Most tools can emit either.
You can generate an SBOM from an existing image with Syft:
syft registry.example.com/team/app@sha256:<digest> -o spdx-json=sbom.spdx.jsonYou can also let BuildKit create it during the build. BuildKit attaches SBOM and provenance as attestations in the image index:
docker buildx build \
--sbom=true \
--provenance=mode=max \
--push \
-t registry.example.com/team/app:1.0 .This needs a builder that supports attestations, and you must push to a registry (or use an OCI exporter), because the default local image store may not keep them. Inspect the results:
docker buildx imagetools inspect registry.example.com/team/app:1.0 \
--format '{{ json .SBOM }}'
docker buildx imagetools inspect registry.example.com/team/app:1.0 \
--format '{{ json .Provenance }}'You can feed an SBOM to a scanner, which reuses the work of cataloguing packages:
grype sbom:./sbom.spdx.json --fail-on highLimits of SBOMs
- An SBOM generated by scanning a finished image can miss statically linked code or vendored libraries that leave no package metadata. Build-time generation sees more.
- An SBOM is a claim. Unless it is signed and tied to the image digest, anyone can swap it.
- It lists components, not vulnerabilities. You still need the scanning workflow from the earlier chapter.
Provenance and attestations
Provenance describes the build itself. An attestation is a signed statement about an artifact, in the in-toto format: a subject (the image digest), a predicate type (such as SLSA provenance or SPDX), and the predicate content. Signing the statement is what makes the SBOM or provenance trustworthy.
SLSA (Supply-chain Levels for Software Artifacts) defines levels for build integrity. At a high level, lower levels require provenance to exist, and higher levels require that a hardened, isolated build platform generates it, so a developer or a compromised build step cannot forge it. Provenance from docker buildx with mode=max records the source, build arguments, and builder, but its trustworthiness depends on where the build ran and who signed the result.
Attach a signed SBOM to an image with Cosign:
cosign attest --yes \
--type spdxjson \
--predicate sbom.spdx.json \
registry.example.com/team/app@sha256:<digest>Verification checks both the signature and the identity, and can print the payload:
cosign verify-attestation \
--type spdxjson \
--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/team/app@sha256:<digest>A CI workflow that produces the evidence
The following GitHub Actions job builds, pushes, and signs by digest. It uses the workflow's OIDC token, so no signing key is stored.
name: release
on:
push:
tags: ["v*"]
permissions:
contents: read
packages: write
id-token: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: build
uses: docker/build-push-action@v6
with:
push: true
tags: ghcr.io/${{ github.repository }}:${{ github.ref_name }}
sbom: true
provenance: mode=max
- uses: sigstore/cosign-installer@v3
- run: cosign sign --yes ghcr.io/${{ github.repository }}@${{ steps.build.outputs.digest }}id-token: write lets the job request the OIDC token that keyless signing needs. Pin the actions themselves to commit SHAs in production, for the same reasons you pin base images.
Enforcing verification at deploy time
Verification must happen where images are admitted. Options by environment:
- Plain Docker hosts: run
cosign verifyin your deploy script and abort on a non-zero exit code. Then start the container by the verified digest. - Kubernetes: use an admission controller such as Sigstore's policy-controller or Kyverno to reject pods whose images lack a valid signature from an approved identity.
- Registries: some registries can block pulls of unsigned or non-compliant images.
Common errors:
- Verifying a tag and then running a different resolved image. Resolve the tag to a digest once, verify that digest, and run it.
- Accepting any valid signature. Without
--certificate-identityand the issuer, a keyless signature from any GitHub user would pass. - Signing only the final image. Base images you pull also need pinning, and verifying their signatures where available.
- Letting the signing job run on untrusted pull requests, which lets attackers obtain signatures for their own builds.
Exercise
Your deploy script runs cosign verify --key cosign.pub registry.example.com/app:1.0 and then docker run registry.example.com/app:1.0. Name two weaknesses and fix them.
Show answer
First, the tag is mutable, so the image that docker run pulls could differ from the one that was verified, since the tag may be repointed between the two commands. Second, even a successful check only shows the key signed something for that reference, and a leaked key would make forged signatures pass. Fix the first by resolving the tag to a digest, verifying registry.example.com/app@sha256:<digest>, and running that same digest. Reduce the second by keeping the private key in a KMS or switching to keyless signing with a pinned --certificate-identity and --certificate-oidc-issuer.
Exercise
What is the difference between an SBOM and a provenance attestation, and why must both be signed?
Show answer
An SBOM lists what is inside the image (packages and libraries). A provenance attestation records how the image was built (source, builder, parameters). Both are only claims until signed and bound to the image digest. Without a signature, an attacker who can write to the registry could replace them with false data that hides a malicious component or a fake build origin.