Sub topic 15
Attestations: provenance, SBOMs and signing
This chapter assumes you can already build and push an image from a GitHub Actions workflow, and that you know a tag points to a digest. A digest is the sha256: hash that identifies an image's content.
What an attestation adds
A pushed image tells a consumer nothing about where it came from or what is inside it. An attestation is a signed or attached statement about an image, stored in the registry next to it. Two kinds matter here:
- Provenance records how the image was built: the source repository, the commit, the workflow, and the builder.
- An SBOM (software bill of materials) lists the packages and libraries inside the image. When a new vulnerability is announced, you can check the list instead of rescanning every image.
A third step, signing, proves that a specific digest was published by a specific identity. The signature does not describe the contents. It ties the digest to the workflow that produced it.
Turning them on in the workflow
BuildKit can generate provenance and an SBOM during the build. You enable them with two inputs on docker/build-push-action. The signature comes from Cosign, using the workflow's own OIDC identity instead of a stored key. OIDC is a short-lived identity token that GitHub issues to each run.
name: publish-signed-image
on:
push:
tags: ["v*"]
permissions:
contents: read
packages: write
id-token: write
jobs:
release:
runs-on: ubuntu-latest
env:
IMAGE: ghcr.io/example-org/example-app
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: sigstore/cosign-installer@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
id: build
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ env.IMAGE }}:${{ github.ref_name }}
provenance: mode=max
sbom: true
- name: Sign the image by digest
run: cosign sign --yes "${IMAGE}@${{ steps.build.outputs.digest }}"Three details matter:
id-token: writelets the job request the OIDC token that Cosign uses for keyless signing. Without it, signing fails.provenance: mode=maxincludes more build detail than the defaultminmode. Review that detail before you publish it, because it can include build arguments.- The signing step uses the digest, not the tag. A tag can move after the signature is made. A digest cannot.
Checking the result
List what was attached to the image:
docker buildx imagetools inspect ghcr.io/example-org/example-app:v1.0.0 \
--format '{{ json .Provenance }}'
docker buildx imagetools inspect ghcr.io/example-org/example-app:v1.0.0 \
--format '{{ json .SBOM }}'Verify the signature by naming the identity you expect:
cosign verify ghcr.io/example-org/example-app:v1.0.0 \
--certificate-identity-regexp 'https://github.com/example-org/example-app/.*' \
--certificate-oidc-issuer https://token.actions.githubusercontent.comCommon errors
- Signing a tag instead of a digest, so the signature no longer matches after a retag.
- Forgetting
id-token: write, which produces an error about missing OIDC credentials. - Using a broad
--certificate-identity-regexp, which accepts signatures from other repositories. - Expecting attestations on a pull request build that does not push. Attestations live in the registry, so they exist only when
push: true.
Exercise
Why does the signing step use steps.build.outputs.digest rather than the version tag, and which workflow permission does keyless signing need?
Show answer
A tag can be moved to a different image after signing, so a signature on a tag could end up describing the wrong content. A digest identifies exactly one image. Keyless signing needs id-token: write so the job can request an OIDC token.