Sub topic 3
Attesting and Verifying Container Images
Assume you know GitHub Actions jobs, permissions, the GitHub CLI, container registries, hashes, and digital signatures. This chapter focuses on images, reusable workflows, and consumer policy.
Attest an Image by Its Digest
A container tag, such as v1, can move. A digest identifies one exact image manifest. Attest the digest produced by the push step, not a tag.
- name: Build and push image
id: push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ghcr.io/OWNER/APP:${{ github.ref_name }}
- name: Attest image provenance
uses: actions/attest-build-provenance@v2
with:
subject-name: ghcr.io/OWNER/APP
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: trueThe job needs id-token: write and attestations: write. It also needs packages: write when it pushes the image. The attestation is stored with the registry’s image metadata.
Verify the image with its registry reference:
gh attestation verify oci://ghcr.io/OWNER/APP:v1 \
--owner OWNER \
--format jsonThe command checks that the attestation matches the image digest and that its signature and certificate are valid.
From Build Level 2 to Level 3
A centrally maintained reusable workflow can standardize the build and attestation process. SLSA Build Level 2 generally provides hosted build provenance. Level 3 adds stronger isolation and prevents the build definition from being modified by the project being built. Use a reusable workflow owned by a trusted organization, restrict its callers, and pin action references where practical.
SBOM and Custom Predicates
An SBOM, or software bill of materials, lists components inside an artifact. Attach one to the same subject:
- uses: actions/attest-sbom@v2
with:
subject-path: dist/app
sbom-path: sbom.spdx.jsonCustom predicates can record approved test results or license data. Consumers must understand the predicate type before trusting its claims.
Turn Verification into Policy
A release process can reject images without valid provenance from an approved repository and workflow. A cluster admission policy can require that verification before allowing deployment. Check the digest, repository, workflow identity, and expected builder. Do not accept a signature alone.
What Provenance Does Not Prove
Provenance describes how an artifact was produced. It does not prove that the source code was secure, dependencies were harmless, tests were comprehensive, or the resulting image has no vulnerabilities. Verify the builder and source, scan the image, and define separate security requirements.
Exercise
Why should a policy verify an image digest instead of only its tag?
Show answer
A tag can point to different manifests over time, while a digest identifies the exact image that was attested.