Sub topic 11
Turning verification into policy for consumers and clusters
This chapter covers how to turn a one-off gh attestation verify into a rule that is applied automatically. It assumes you can already generate attestations for files and images, run gh attestation verify by hand, and read a basic GitHub Actions workflow. It also assumes you know what an image digest is and have used kubectl or a Kubernetes manifest.
From a check to a policy
A successful gh attestation verify tells you that some workflow signed a statement about an artifact's digest. Whether that is good enough depends on which workflow, in which repository, on which trigger. A policy is the written-down answer, enforced by a machine.
An attestation made by any repository on GitHub passes the basic signature check. If your policy is only "has a valid attestation", an attacker can build a malicious file in their own repository, attest it, and satisfy that policy. So a policy must name what you trust.
The table lists the questions a policy can ask and the gh options that enforce them.
| Question | What it protects against | `gh attestation verify` option |
|---|---|---|
| Was it built in this repository? | Artifacts attested by an unrelated repository | `--repo OWNER/REPO` |
| Was it built in this organization? | Artifacts from outside your organization | `--owner OWNER` |
| Was it built by this workflow file? | A different workflow in the same repository, such as a test or experiment workflow | `--signer-workflow OWNER/REPO/.github/workflows/build.yml` |
| Is the statement a provenance statement? | Accepting an SBOM or custom attestation where provenance is expected | `--predicate-type https://slsa.dev/provenance/v1` |
| Did it run on a GitHub-hosted runner? | Builds on self-hosted machines you do not control | `--deny-self-hosted-runners` |
Run gh attestation verify --help on your version. Some options, such as those that match the source ref or commit, have been added over time.
Choosing the strictness of a policy
Each added constraint reduces the number of artifacts that pass, so pick the narrowest rule that still matches how you actually build. These are common tiers:
- Owner level.
--owner my-orgaccepts anything built by any repository in the organization. It is easy to roll out and a reasonable first step. It trusts every team's workflows equally. - Repository level.
--repo my-org/my-appaccepts only that repository's builds. Any workflow in that repository can satisfy it, including one that a contributor added in a branch. - Workflow level.
--signer-workflow my-org/my-app/.github/workflows/release.ymlties the artifact to one file. With branch protection and required review on that file, this is the strongest practical rule.
A workflow-level rule is also where reusable workflows pay off. If your release builds run through a shared reusable workflow, you can pin the policy to that shared workflow. Every product then passes through the same reviewed build logic.
A verification gate for file downloads
The simplest enforcement point is a script that runs before anything is installed or deployed. Exit codes do the work here. gh attestation verify exits non-zero when verification fails, so set -e stops the script.
#!/usr/bin/env bash
set -euo pipefail
# Usage: fetch-and-verify.sh vX.Y.Z
TAG="${1:?usage: fetch-and-verify.sh TAG}"
REPO="my-org/my-app"
WORKFLOW="my-org/my-app/.github/workflows/release.yml"
mkdir -p download
gh release download "$TAG" --repo "$REPO" --pattern 'app' --dir download
gh attestation verify download/app \
--repo "$REPO" \
--signer-workflow "$WORKFLOW" \
--predicate-type https://slsa.dev/provenance/v1 \
--deny-self-hosted-runners
chmod +x download/app
echo "Verified $TAG, installing"
install -m 0755 download/app /usr/local/bin/appReplace my-org/my-app, the workflow path and the app file name with your own values. The script verifies the exact bytes on disk. It does not trust the release page or the file name, because the attestation is matched by SHA-256 digest.
The same gate fits in a downstream workflow, so that a deployment job refuses to proceed without a valid attestation:
name: deploy
on:
workflow_dispatch:
inputs:
tag:
description: Release tag to deploy
required: true
jobs:
verify-and-deploy:
runs-on: ubuntu-latest
permissions:
contents: read
env:
GH_TOKEN: ${{ github.token }}
steps:
- name: Download release asset
run: gh release download "${{ inputs.tag }}" --repo my-org/my-app --pattern app --dir dl
- name: Verify attestation
run: |
gh attestation verify dl/app \
--repo my-org/my-app \
--signer-workflow my-org/my-app/.github/workflows/release.yml
- name: Deploy
run: echo "deploying verified artifact"gh needs GH_TOKEN so it can call the attestations API. Passing the tag through an inputs expression directly in run: can allow script injection when the input is untrusted. For a real pipeline, assign it to an environment variable first and reference "$TAG" in the script.
Policy for container images
For images, the object to check is the digest, not the tag. A tag such as v1.4.0 is a mutable pointer. Someone with push access can retarget it after you verified it. The attestation is bound to a digest, so the policy must also be applied to that digest.
A safe sequence is:
- Resolve the tag to a digest once, at deploy time.
- Verify the image by that digest.
- Deploy the digest, for example
ghcr.io/my-org/my-app@sha256:..., not the tag.
IMAGE="ghcr.io/my-org/my-app"
DIGEST="sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" # example value
gh attestation verify "oci://${IMAGE}@${DIGEST}" \
--repo my-org/my-app \
--signer-workflow my-org/my-app/.github/workflows/release.ymlIf the image check passes, put ${IMAGE}@${DIGEST} into your manifest. Deploying by tag after verifying by digest leaves a gap between the check and the use.
Enforcing in a Kubernetes cluster
A script in a pipeline protects only the people who run it. Someone with kubectl access can still apply a manifest that points at an unverified image. To close that gap, enforce the policy at the cluster's admission step. An admission controller is a webhook that the API server calls before it stores an object. It can accept or reject a new Pod.
Two widely used choices can check Sigstore-signed attestations:
- Sigstore policy-controller. You write
ClusterImagePolicyresources that name image patterns and the certificate identity required to sign them. - Kyverno. Its image verification rules can check signatures and attestations as part of general cluster policy.
Whichever tool you use, the policy has the same four parts:
- Scope. Which images the rule applies to, for example
ghcr.io/my-org/**. - Issuer. The OIDC issuer in the signing certificate. For GitHub Actions this is
https://token.actions.githubusercontent.com. - Subject. The workflow identity, such as
https://github.com/my-org/my-app/.github/workflows/release.yml@refs/tags/v1.4.0, usually matched with a pattern over the tag or branch. - Trust root. The certificate authority and transparency log that the cluster accepts.
The trust root deserves attention. Attestations for public repositories are signed through the public-good Sigstore instance. Attestations for private repositories use GitHub's own Sigstore instance. A cluster that verifies private-repository images must be configured with GitHub's trust root, or every image fails verification. Check your tool's documentation, and GitHub's guide on enforcing attestations with an admission controller, for the current setup.
The identity in the certificate also carries the ref the workflow ran on. If your policy accepts only refs/tags/v*, a build from a feature branch is rejected even if the workflow file is correct.
Rolling out a policy safely
Switching straight to enforcement tends to break deployments, because older images were built before attestations existed. A staged rollout avoids that.
- Inventory. List the images and files running today and note which have attestations.
- Audit mode. Run the verification and log failures without blocking. Policy-controller supports a warn mode, and Kyverno policies can be set to audit.
- Fix the gaps. Add attestation steps to the workflows that failed, or rebuild old images from a tagged commit.
- Enforce by namespace. Start with one non-critical namespace, then expand.
- Keep an exception path. Emergency fixes happen. Use a documented, logged exemption, not a disabled policy.
Plan for these operational problems too:
- Offline or air-gapped environments.
gh attestation verifycan read a downloaded bundle with--bundle, and you can supply a custom trusted root, so consumers without live access to GitHub can still verify. - Rate limits and outages. Fetching attestations at every Pod start adds a network dependency. Admission controllers usually cache results, but test what happens when the registry or API is slow.
- Trust root rotation. Sigstore rotates keys and certificate authorities. Tools that fetch the root through TUF update automatically. A root pinned by hand goes stale, and verification starts failing without any change to the artifact.
What a policy cannot enforce
Verification checks that the artifact came from the workflow you named. It does not check that the source code was safe, that the build steps were free of malicious dependencies, or that the workflow itself was not edited by someone who should not have edited it. Policy narrows who may produce an acceptable artifact. It does not make the producer trustworthy. The final chapter covers these limits in full.
Exercise
Your cluster policy accepts any image with a valid GitHub attestation. A teammate says this is safe because "everything is signed". Give one way an attacker passes this policy, and name the two kinds of constraint you would add.
Show answer
The attacker creates their own GitHub repository, builds a malicious image there, and attests it with actions/attest-build-provenance. The signature is valid, so a policy that checks only for a valid attestation admits it. Add an identity constraint that names who may sign (your repository or owner, ideally the specific signer workflow and a protected ref such as a version tag), and a digest constraint, so the image is verified and deployed by digest instead of by a mutable tag.
Exercise
A deployment script runs gh attestation verify oci://ghcr.io/my-org/my-app:v2 --repo my-org/my-app and then applies a manifest that references ghcr.io/my-org/my-app:v2. What weakness does this leave, and how do you fix it?
Show answer
A tag is mutable. Between verification and the Pod pulling the image, the tag can be repointed to a different image that has no valid attestation, or the registry can serve a different image at pull time. Resolve the tag to a digest once, verify oci://ghcr.io/my-org/my-app@sha256:<digest>, and put that same digest reference in the manifest so the verified bytes are the deployed bytes.