Sub topic 7
Verifying image signatures with Kyverno
This chapter assumes you can write a Kyverno ClusterPolicy with a match block (see the earlier chapters on policy structure and validate rules). It also assumes you know what a container registry and an image tag are.
What image verification does
A signed image carries a signature stored in the registry next to the image. The signature proves who built the image and that its content has not changed. Kyverno checks this signature at admission, before the Pod is created. It supports Sigstore Cosign and Notary signatures. This chapter uses Cosign.
Image verification is its own rule type, verifyImages. It runs in the same admission webhook as validate and mutate, but it contacts the registry, and sometimes the Sigstore transparency log, during the request.
A verification policy
This policy requires every image from one registry path to be signed by a specific GitHub Actions identity.
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: verify-image-signature
spec:
validationFailureAction: Enforce
webhookTimeoutSeconds: 30
rules:
- name: verify-signature
match:
any:
- resources:
kinds:
- Pod
verifyImages:
- imageReferences:
- "registry.example.com/myteam/*"
required: true
mutateDigest: true
verifyDigest: true
attestors:
- count: 1
entries:
- keyless:
issuer: "https://token.actions.githubusercontent.com"
subject: "https://github.com/example-org/*"
rekor:
url: https://rekor.sigstore.devReplace the registry path, issuer and subject with your own values. The fields work as follows:
imageReferencesselects which images are checked. Images that do not match are ignored, not rejected.attestorslists who may sign.count: 1means one matching entry is enough.keylesstrusts an identity (issuer and subject) recorded in a Sigstore certificate. Usekeyswith apublicKeysvalue instead if you sign with a key pair.mutateDigest: truerewrites a tag such asapp:1.0toapp@sha256:.... This matters because a tag can be moved after verification, but a digest cannot.verifyDigest: truerequires the image to be referenced by a digest.
Common errors
| Symptom | Likely cause |
|---|---|
| Every Pod is denied with "no signatures found" | The image was never signed, or it was signed under a different repository path. |
| Denied with an identity mismatch | The `subject` or `issuer` does not match the certificate. Cosign identities are exact unless you use a wildcard. |
| Admission times out | Slow registry or Rekor lookups. Raise `webhookTimeoutSeconds` or check network egress from the Kyverno pods. |
| Private image cannot be checked | Kyverno has no registry credentials. Configure image pull secrets for Kyverno. |
| Unsigned images still run | The image does not match `imageReferences`, or the policy is in `Audit` mode. |
Start in Audit mode and read the policy reports before you switch to Enforce. This catches unsigned images that already run in your cluster.
Exercise
Why would you set mutateDigest: true in a verification policy?
Show answer
Tags are mutable, so someone could repoint app:1.0 to a different image after Kyverno verified it. With mutateDigest: true, Kyverno rewrites the image to its immutable digest, so the Pod runs exactly the content that was verified.