Sub topic 11
Turning verification into policy for consumers and clusters
This chapter assumes you can already generate attestations in a workflow and run gh attestation verify by hand. It covers how to turn that manual check into a rule that runs on every download, deploy, or pod start.
From a check to a policy
A verification command answers one question: does a valid signed attestation exist for this file? A policy answers a stricter one: does this artifact come from the builder I trust, and what happens if it doesn't?
A passing check that anyone can satisfy proves little. Anyone can run a workflow in their own repository and get a valid attestation for a malicious binary. Verification without a narrow identity requirement only shows that someone signed something.
A policy has three parts:
- Identity: which repository, owner, or workflow must have built the artifact.
- Content: which predicate type the attestation must carry, such as SLSA provenance.
- Action: what the system does on failure. It should block by default.
Choosing how narrow to be
Each flag you add to gh attestation verify narrows what a consumer accepts. Narrower rules are safer and break more often when you reorganize repositories.
| Flag | What it requires | Trade-off |
|---|---|---|
| `--owner OWNER` | Built by any repository in that organization or account | Easy to maintain, but any repository in the org passes |
| `--repo OWNER/REPO` | Built by one specific repository | Good default for a single project |
| `--signer-workflow` | Signed by one named workflow file | Strongest. Moving the workflow breaks verification |
| `--predicate-type` | The attestation has the expected type | Stops an SBOM attestation from passing as provenance |
| `--deny-self-hosted-runners` | The build did not run on a self-hosted runner | Useful when you can't vouch for those machines |
Start with --repo plus --signer-workflow. Loosen it only when you have a reason.
A consumer-side gate
Wrap the command in a script and run it before you install or deploy anything. The set -e line makes the script stop on the first failure, so a failed verification never reaches the install step.
#!/usr/bin/env bash
set -euo pipefail
artifact="$1"
gh attestation verify "$artifact" \
--repo OWNER/REPO \
--signer-workflow OWNER/REPO/.github/workflows/build.yml \
--predicate-type https://slsa.dev/provenance/v1 \
--deny-self-hosted-runners
echo "Verified: $artifact"gh attestation verify exits with a non-zero status when verification fails. Don't catch that status and continue. A policy that logs a warning and proceeds is not a policy.
Enforcing at the cluster
For container images, the check belongs where images are admitted, not where people remember to run it. A Kubernetes admission controller intercepts each pod creation and can reject the request.
The Sigstore policy-controller is one such admission controller. You give it a policy that names the image patterns it covers, the signing identity it accepts, and the attestation type it requires. Other tools can also enforce Sigstore-based rules, including Kyverno and Ratify with OPA Gatekeeper. They all check the same facts you check by hand.
Three points apply whichever tool you use:
- Scope the policy to your registry paths. A rule that covers
ghcr.io/OWNER/**does not cover images from other sources. Decide separately what happens to those. - Match the issuer and the identity. The GitHub Actions issuer is
https://token.actions.githubusercontent.com. The certificate subject names the workflow. Pin both. - Verify the digest, not the tag. The attestation is bound to a digest, and tags can be moved. Prefer deploying by digest so the image that was checked is the image that runs.
Check which trust root applies to your repositories before you write the policy. Public and private repositories can sign through different Sigstore instances, so your cluster tooling needs the matching trusted root.
Rolling a policy out safely
A strict policy that blocks everything on day one gets switched off by day two. Roll it out in stages:
- Run in audit mode first. Log what would be blocked and fix the gaps. Many tools offer a warn mode for this.
- Attest everything you build, including old images you still deploy, or add an explicit exception list.
- Switch to enforce mode for one namespace or one project.
- Widen the scope once the failure rate is near zero.
Keep exceptions in version control, with an owner and an expiry date. An exception list that nobody reviews turns into a hole in the policy.
What policy cannot fix
A policy only enforces what attestations say. If an attacker controls the trusted workflow, they can build a bad artifact and get a valid attestation for it. The policy will pass it. Protect the workflow file with branch protection and code review, and keep its permissions narrow. The final chapter covers these limits in more detail.
Exercise
Your cluster policy accepts any attestation whose issuer is the GitHub Actions OIDC issuer and whose predicate type is SLSA provenance. A teammate says this is enough because the signature is valid. Give one attack it allows, and one change that closes it.
Show answer
Anyone can fork a repository or create their own, build a malicious image in their own workflow, and get a valid, correctly signed provenance attestation from the same issuer. The policy accepts it because it never checks who built the image. Close the gap by requiring a specific identity, such as the certificate subject for your repository's build workflow (or --repo and --signer-workflow in gh attestation verify), and scope the policy to your registry paths.