Sub topic 12
Enforcing signatures at deploy time with admission policies
This chapter assumes you can sign and verify an image with cosign verify, including pinning a certificate identity and OIDC issuer. It also assumes you know basic Kubernetes objects (Pods, Deployments, namespaces) and have used kubectl apply. Earlier chapters covered signing. Here you move the verification step from a person's terminal into the cluster, so unsigned images cannot start.
Why verification must happen at admission
A signature protects nothing if nobody checks it. If verification is a manual step, it gets skipped under pressure. It also covers only the images that the person checked, not every image the cluster runs.
Kubernetes has a built-in place for automatic checks: the admission control phase. After a request is authenticated and authorized, but before the object is stored in etcd, the API server can call out to webhooks. A validating webhook can reject the request. A mutating webhook can change it first.
An admission policy for signatures uses these webhooks to do three things:
- Intercept every Pod (or workload) creation.
- Extract each image reference in the Pod spec.
- Run the equivalent of
cosign verifyand reject the Pod if verification fails.
What a policy needs to express
Whatever tool you use, a signature policy answers the same questions:
- Which images does it apply to? Usually a registry or repository pattern, such as
ghcr.io/OWNER/*. Images outside the pattern are either allowed or blocked by a separate default rule. - Who must have signed? A public key, a KMS key, or a keyless identity and issuer pair.
- What else must be present? Optionally, an attestation such as an SBOM.
- What happens on failure? Block the request (enforce) or log it (audit).
The identity rule is the part that matters most. A policy that only says "has a valid Sigstore signature" accepts anyone's signature, because anyone can obtain a Fulcio certificate. The policy must pin the identity and issuer, exactly as you did with --certificate-identity and --certificate-oidc-issuer.
Option 1: Sigstore policy-controller
The Sigstore project ships policy-controller, an admission controller that reads ClusterImagePolicy resources. It is opt-in per namespace, which makes gradual rollout easy.
Enable it for a namespace with a label:
kubectl label namespace production policy.sigstore.dev/include=trueThen define a policy that accepts only images built by your release workflow:
apiVersion: policy.sigstore.dev/v1beta1
kind: ClusterImagePolicy
metadata:
name: require-signed-app
spec:
images:
- glob: "ghcr.io/OWNER/REPO**"
authorities:
- name: github-actions-main
keyless:
url: https://fulcio.sigstore.dev
identities:
- issuer: https://token.actions.githubusercontent.com
subject: https://github.com/OWNER/REPO/.github/workflows/build.yml@refs/heads/mainThe identities entry is the admission equivalent of the cosign verify flags from the CI chapter. The issuer matches the OIDC issuer. The subject matches the certificate identity, which for GitHub Actions is the workflow file path and ref.
If you use key-based signing, replace keyless with a key entry:
apiVersion: policy.sigstore.dev/v1beta1
kind: ClusterImagePolicy
metadata:
name: require-key-signed-app
spec:
images:
- glob: "registry.example.com/team/**"
authorities:
- key:
data: |
-----BEGIN PUBLIC KEY-----
<contents of cosign.pub>
-----END PUBLIC KEY-----A KMS-backed key works the same way, using key.kms with a URI such as awskms:///<key-arn>. The controller then needs permission to call the KMS verify operation.
Option 2: Kyverno verifyImages
If you already use Kyverno for other policies, its verifyImages rule covers signature checks without a second controller. It can also mutate the Pod so that each tag is replaced by its verified digest.
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: verify-image-signature
spec:
validationFailureAction: Enforce
webhookTimeoutSeconds: 30
rules:
- name: verify-keyless-signature
match:
any:
- resources:
kinds:
- Pod
verifyImages:
- imageReferences:
- "ghcr.io/OWNER/REPO*"
mutateDigest: true
verifyDigest: true
required: true
attestors:
- entries:
- keyless:
issuer: https://token.actions.githubusercontent.com
subject: https://github.com/OWNER/REPO/.github/workflows/build.yml@refs/heads/main
rekor:
url: https://rekor.sigstore.devField names vary between Kyverno versions. Newer releases deprecate validationFailureAction in favor of a per-rule failure action setting, so check the documentation for the version you run.
Both tools perform the same checks as the CLI: signature validity, certificate chain to Fulcio, identity match, and Rekor inclusion.
Comparing the options
| Aspect | policy-controller | Kyverno `verifyImages` |
|---|---|---|
| Scope | Image signature and attestation policy only | General-purpose policy engine |
| Rollout model | Namespace label opt-in | Match rules and namespace selectors |
| Digest rewriting | Yes, resolves tags to digests | Yes, with `mutateDigest` |
| Extra work if you already run it | New component to operate | None |
| Policy language for attestations | CUE or Rego | JMESPath conditions |
Pick the tool that matches what your team already operates. Running two admission controllers adds failure points and webhook latency to every Pod creation.
Tags, digests and the time-of-check problem
Recall that tags are mutable. A policy that verifies app:1.0.0 and then lets the kubelet pull app:1.0.0 has a gap: the tag could be moved between the check and the pull.
This is why both tools rewrite the image to a digest during admission. After mutation the Pod spec contains ghcr.io/OWNER/REPO@sha256:..., so the kubelet pulls exactly the content that was verified.
Also note that admission runs when a Pod is created, not continuously. An already running Pod is not stopped if you tighten the policy later. Existing workloads are only re-checked when they are recreated, for example during a rollout or node drain.
Rolling out without breaking the cluster
Turning on enforcement in all namespaces at once is a common cause of outages. A safer sequence:
- Audit first. Set the policy to warn or audit mode, and read the violation reports. Typical findings are third-party images, init containers, and sidecars injected by service meshes.
- Sign what you own. Make sure your CI signs every image you build, including base images you rebuild yourself.
- Decide on third-party images. Either mirror and sign them in your own registry, write a separate policy that trusts the vendor's identity, or explicitly exempt them.
- Enforce in one namespace. Start with a low-risk namespace, then widen.
- Protect system namespaces. Exclude
kube-systemand the admission controller's own namespace so the cluster can still recover if the webhook fails.
Check which images a namespace currently runs with:
kubectl get pods -n production \
-o jsonpath='{range .items[*].spec.containers[*]}{.image}{"\n"}{end}' | sort -uFailure modes
Admission controllers sit in the critical path of the API server, so their failure modes matter.
- Webhook unavailable. Webhook configurations have a
failurePolicy. WithFail, an unreachable controller blocks Pod creation. WithIgnore, signature checks are silently skipped.Failis safer but needs a highly available controller (multiple replicas, a PodDisruptionBudget).Ignoremakes enforcement bypassable by anything that can take the controller down. - Registry or Rekor outage. The controller must reach the registry to fetch signatures and, for keyless verification, may need Rekor and the Sigstore trust root. If the controller cannot reach them, valid images may be denied. Use a private registry mirror for signatures, and consider offline verification with bundles where your tool supports it.
- Timeouts. Verification involves network calls. A slow registry can exceed the webhook timeout (default 10 seconds, maximum 30), and the request then follows
failurePolicy. Raise the timeout carefully. - Private registries. The controller needs credentials to read signatures, not only the kubelet. Configure image pull secrets or workload identity for the controller itself.
- Identity drift. If you rename the workflow file or change the release branch, the certificate identity changes and every new image fails the policy. Update the policy together with the workflow.
- Overly broad globs. A glob like
ghcr.io/**combined with a permissive identity regex can accept images from other owners. Keep globs and identities as narrow as the real set of images.
Troubleshooting a denial
When a Pod is rejected, kubectl prints the webhook's message. Typical messages and causes:
| Message theme | Likely cause |
|---|---|
| No matching signatures | Image was never signed, or it was signed under a different digest than the one pulled |
| Certificate identity does not match | The signer's workflow path or ref differs from the policy subject |
| Issuer mismatch | Policy lists the wrong OIDC issuer URL |
| Could not fetch signature | Controller lacks registry credentials or network access |
| Rekor entry not found | Image was signed without transparency log upload, or the controller cannot reach Rekor |
To reproduce a denial, run the same check by hand from your terminal:
cosign verify \
--certificate-identity https://github.com/OWNER/REPO/.github/workflows/build.yml@refs/heads/main \
--certificate-oidc-issuer https://token.actions.githubusercontent.com \
ghcr.io/OWNER/REPO@sha256:<digest>If the CLI succeeds with the policy's values but the cluster denies the Pod, the problem is in the controller's environment, such as credentials, networking or trust root, and not in the signature. If the CLI also fails, the signature or identity is the issue.
Summary of design choices
- Pin identity and issuer in every policy. Do not accept "any signature".
- Rewrite to digests so the verified content is what runs.
- Roll out in audit mode, then enforce namespace by namespace.
- Treat the controller as critical infrastructure: replicate it, exclude system namespaces, and decide
failurePolicydeliberately. - Admission checks happen at creation time only, so combine them with image rebuilds and rollouts when you change policy.
Exercise
Your cluster runs policy-controller with a ClusterImagePolicy that uses a keyless authority and pins the subject to https://github.com/OWNER/REPO/.github/workflows/build.yml@refs/heads/main. A teammate renames the workflow file to release.yml and merges. The next deployment is rejected, although the image was signed successfully. Why did this happen, what is the fix, and why must the policy not be loosened to accept any identity from the GitHub issuer?
Show answer
The keyless certificate identity is the workflow path and ref, so images signed by the renamed workflow carry .../release.yml@refs/heads/main, which no longer matches the pinned subject. The fix is to update the policy subject to the new workflow path, ideally in the same change as the rename. Accepting any identity from the GitHub issuer would trust every workflow in every repository on GitHub, because anyone can get a valid certificate for their own workflow. The identity pin is what ties the signature to your repository and release process.