Workflow: Signed by CI, Verified at Admission

Every image of the platform is built, signed and attested in its repository’s build.yml. The backend and the frontend go through these steps; the Guardian (k8s-ai-monitor) signs and attests the same way, but still scans after the push and pins some actions by tag - backlog:

  1. Build and scan before anything is pushed. The image is built locally in the job and scanned by Trivy; a fixable CRITICAL or HIGH finding stops the build - nothing unscanned is pushed. The runtime stage is never taken from the build cache, so its apk upgrade runs every time - a cached upgrade keeps an old package until the base image changes, which is how a pcre2 fix once missed the frontend.
  2. Push one digest. The scanned images are joined into one multi-platform image; from here on everything refers to its digest.
  3. Sign the digest, keyless. cosign sign asks GitHub for a short-lived OIDC token, Sigstore’s certificate authority (Fulcio) issues a certificate for exactly this workflow run, and the signature is recorded in a public transparency log (Rekor). No key to store, rotate or leak: the identity is the workflow - https://github.com/safeops-course/backend/.github/workflows/build.yml@refs/heads/main. The certificate is valid for ten minutes, yet the signature verifies weeks later: Rekor’s entry carries a signed timestamp that proves the signature was made while the certificate was valid.
  4. Attach the evidence. One SPDX SBOM per published platform (syft --platform, pinned and checksum-verified) attested with cosign attest - amd64 for the cloud nodes, arm64 for kind on Apple silicon: a scanner reads one platform of a multi-platform image, so a single SBOM would describe only one of them - and SLSA build provenance from GitHub, all signed by the same identity, about the same digest. A step after them verifies the SBOMs the way the cluster does and fails the build when a published platform has none.
  5. Promote without rebuilding. staging and production get the same digest under new tags (Chapter 10); the signatures are about the digest, so they come along.

The backend’s and frontend’s jobs, which hold signing rights, install nothing unpinned: every action is pinned by commit SHA, and tools are downloaded by version and checked against their checksum. A build step that runs a script from a moving branch could sign whatever that script decides.

What a Signature Proves - and What It Does Not

ProvesDoes not prove
this digest was signed by this workflow, in this repository, on this branchhow it was built - from which source, by which builder: that is the provenance’s claim, and this policy does not check it
that the code is free of vulnerabilities - Trivy and the SBOM are for that
nobody changed the image after the buildthat the workflow itself was not compromised - its actions are pinned for that
the signature existed at a time recorded in a public logthat the image is the one Git points at now - promotion and Flux are for that

The SBOM does not make an image safe either; it makes it answerable: when a CVE is published, the SBOMs of the running images say which of them contain the affected version. It lists what the scanner found - a catalogue, not a guarantee that nothing else is inside.

The Policy: Our Images, Our Signer, Our SBOM

One Kyverno ImageValidatingPolicy - the CEL-based policy type for images - checks every image from the platform’s registry, in containers, init containers and ephemeral containers:

  • a signature by the workflow of the repository the image is named after: a backend image by ^https://github\.com/safeops-course/backend/\.github/workflows/build\.yml@refs/heads/(main|develop)$, a frontend image by the frontend’s, k8s-ai-monitor by the Guardian’s - one attestor per repository, chosen by the image’s name. An image of any other repository in the registry has no signer and fails. Not one pattern for all three - that would accept a backend image signed by the frontend’s workflow - and never github.com/<org>/*, which would trust any workflow in any repository of the organisation;
  • an SPDX SBOM attestation signed by the same repository’s workflow.

Each image is verified once per request, even when a pod runs it twice - the backend’s migrate initContainer uses the app’s own image; verifying it twice took longer than the webhook allows (below).

Images from other registries are not its business - Chapter 16’s registry rule decides whether those may run at all.

The supply-chain policy (enforce copy)

Show verify-images-enforce.yaml
# Chapter 17: every image from the platform's own registry (${image_registry}) must be signed - keyless,
# by the build.yml of its own repository (backend, frontend, k8s-ai-monitor) on main or develop - and
# carry an SPDX SBOM attestation signed the same way. Images from other registries are not this
# policy's business (Chapter 16's require-trusted-registries decides whether they may run at all).
#
# ImageValidatingPolicy (CEL), not a ClusterPolicy verifyImages rule: the CI signs with cosign v3,
# whose signatures are Sigstore bundles stored as OCI referrers; Kyverno's ClusterPolicy verifyImages
# finds none of them ("no signatures found"), the ImageValidatingPolicy verifies both the bundles and
# the older .sig format (checked with the Kyverno CLI against the real images).
#
# Two copies, identical but for the name, the namespaces, the action and the failure policy -
# tests/kyverno-supply-chain.test.sh fails when they drift apart:
#   verify-images-enforce  develop, staging, production - Deny, failurePolicy Fail
#   verify-images-audit    every other namespace         - Audit (PolicyReports), failurePolicy Ignore
#
# Tags are verified as they resolve at admission, and the verified digest is pinned into the pod
# (mutateDigest): the kubelet pulls exactly what was verified, even if the tag is moved a moment
# later. Needs Kyverno 1.19 (chart 3.9.x): 1.17 does not implement mutateDigest for
# ImageValidatingPolicy and silently did nothing.
# verifyDigest then fails an image the mutation did not pin - denied by the enforce copy, reported by
# the audit copy. It was turned on only after the mutation was seen on kind (2026-10-10: develop and
# staging backend pods, init container included, ran <tag>@sha256 equal to the registry's digest):
# the Kyverno CLI validates without mutating, so no test shows the mutation, and with verifyDigest on
# a cluster whose mutation does not run would refuse every pod deployed by tag.
apiVersion: policies.kyverno.io/v1
kind: ImageValidatingPolicy
metadata:
  name: verify-images-enforce
  annotations:
    policies.kyverno.io/title: Verify Image Signatures and SBOM (enforce)
    policies.kyverno.io/category: Supply Chain Security
    policies.kyverno.io/severity: high
spec:
  validationActions: [Deny]
  failurePolicy: Fail
  validationConfigurations:
    mutateDigest: true    # Kyverno >= 1.19 - see the header
    verifyDigest: true
  # Verifying a signature and an SBOM costs about ten seconds when the result is not cached (ghcr.io,
  # Sigstore): on kind the default 10 s timeout cut every first verification off, and the pod was
  # refused although its image was signed. 30 s is the maximum; a verified digest is then cached
  # for an hour (Kyverno's image verify cache) and admission is fast.
  webhookConfiguration:
    timeoutSeconds: 30
  # Verified at admission only - the moment a pod's image is decided. A background scan re-verified
  # every image of every running pod (cosign signature + SBOM, against ghcr.io and Sigstore) on every
  # resync: on kind the reports controller averaged 1.3 cores, peaked at 6.6, lost its leader lease
  # under its own load and restarted - 49 times in 29 hours - each time scanning everything again.
  # A running pod's image does not change, so the re-check bought nothing. What it costs: a pod
  # admitted while Kyverno could not answer (the audit copy fails open) gets no report until it is
  # recreated; the enforce copy fails closed, so in develop/staging/production no such pod exists.
  evaluation:
    background:
      enabled: false
  # Pods only - no autogen for Deployments, Jobs and the other pod controllers. The generated
  # controller rules verified every image again on each Flux dry-run of a Deployment (seen on kind: a
  # timeout on a slow network blocked backend and frontend). Before 1.19 they also required an
  # image-verification-outcomes annotation that only the pod mutation wrote (minio's Job was denied
  # even by the audit copy, while kind still ran 1.17); 1.19 neither writes nor trusts it. A refused
  # pod still shows on its ReplicaSet (FailedCreate) and in Flux's health check.
  autogen:
    podControllers:
      controllers: []
  matchConstraints:
    resourceRules:
      - apiGroups: [""]
        apiVersions: [v1]
        operations: [CREATE, UPDATE]
        resources: [pods]
    namespaceSelector:
      matchExpressions:
        - key: kubernetes.io/metadata.name
          operator: In
          values: [develop, staging, production]
  matchImageReferences:
    - glob: "${image_registry}/*"
  # One signer per repository: an image is verified against the workflow of the repository it is
  # named after - a backend image against backend's build.yml, not "any of the three". The single
  # regex this replaced admitted a backend image signed by the frontend's workflow.
  attestors:
    - name: backend
      cosign:
        keyless:
          identities:
            - issuer: "https://token.actions.githubusercontent.com"
              subjectRegExp: '^https://github\.com/${git_owner}/backend/\.github/workflows/build\.yml@refs/heads/(main|develop)$'
    - name: frontend
      cosign:
        keyless:
          identities:
            - issuer: "https://token.actions.githubusercontent.com"
              subjectRegExp: '^https://github\.com/${git_owner}/frontend/\.github/workflows/build\.yml@refs/heads/(main|develop)$'
    - name: guardian
      cosign:
        keyless:
          identities:
            - issuer: "https://token.actions.githubusercontent.com"
              subjectRegExp: '^https://github\.com/${git_owner}/k8s-ai-monitor/\.github/workflows/build\.yml@refs/heads/(main|develop)$'
  attestations:
    - name: sbom
      intoto:
        type: "https://spdx.dev/Document"
  variables:
    # Every container, init container and ephemeral container (kubectl debug) whose image is ours -
    # each image once (distinct): the backend's migrate initContainer runs the app's own image, and
    # verifying it twice per request (signature, then two SBOMs per image) took past the webhook's 30 s
    # on kind - every new backend pod was refused with a timeout.
    - name: ours
      expression: >-
        (images.?containers.orValue([]) + images.?initContainers.orValue([]) + images.?ephemeralContainers.orValue([]))
        .filter(image, image.startsWith('${image_registry}/')).distinct()
    # Which signer each repository of the registry has. A repository not listed has none, so its images
    # fail both checks (unsigned-demo, or anything pushed there by hand): the enforce copy refuses them,
    # the audit copy reports them.
    - name: signers
      expression: >-
        {'backend': attestors.backend, 'frontend': attestors.frontend, 'k8s-ai-monitor': attestors.guardian}
  validations:
    # The repository of an image: what follows the registry, up to the tag or digest.
    - expression: >-
        variables.ours.all(image,
          image.replace('${image_registry}/', '').split('@')[0].split(':')[0] in variables.signers
          && verifyImageSignatures(image, [variables.signers[image.replace('${image_registry}/', '').split('@')[0].split(':')[0]]]) > 0)
      message: "every ${image_registry} image must be signed by the build.yml of the repository it is named after (cosign, keyless)"
    - expression: >-
        variables.ours.all(image,
          image.replace('${image_registry}/', '').split('@')[0].split(':')[0] in variables.signers
          && verifyAttestationSignatures(image, attestations.sbom, [variables.signers[image.replace('${image_registry}/', '').split('@')[0].split(':')[0]]]) > 0)
      message: "every ${image_registry} image must carry an SPDX SBOM attestation signed by the build.yml of the repository it is named after"

The policy exists in two copies, identical but for where they act and what they do:

CopyNamespacesActionWhen Kyverno cannot answer
verify-images-enforcedevelop, staging, productionrefuses the podrefuses (fail closed)
verify-images-auditevery other namespacerecords a PolicyReport entryadmits

An ImageValidatingPolicy has one action for all its namespaces - there is no per-namespace override - so the split is two copies, the same pattern as Chapter 16’s guardrails. The policy’s test fails when they drift apart.

Tags Resolved - and the Digest Pinned

Git holds tags; Flux image automation writes them (Chapter 10). A tag is a pointer that can be moved. The policy resolves the tag at admission and verifies that digest; the kubelet pulls the tag a moment later. A tag moved in between would run an image nobody verified.

The policy closes it: with mutateDigest: true, admission writes the verified digest into the pod (<tag>@sha256:…), so the kubelet pulls exactly what was verified - whatever the tag points to a moment later. verifyDigest: true then refuses an image the mutation did not pin. It was switched on only after the mutation was seen working on kind - every container, the migrate init container too, carried the registry’s digest: the policy’s test cannot show the mutation (the Kyverno CLI validates without mutating), and with verifyDigest on, a mutation that did not run would refuse every pod deployed by tag. Git and the Deployment keep the tag; only the pod carries the digest. The platform first ran Kyverno 1.17, which does not implement mutateDigest for ImageValidatingPolicy: set to true, it silently did nothing - found by running the lab on kind, not by reading the policy. The gap was written down as tech debt until the cluster moved to Kyverno 1.19, the version the policy’s tests already ran. Each pod’s status.containerStatuses[].imageID still shows the digest that actually runs - on kind the index digest; other runtimes may record the platform manifest’s digest, so check which one you compare before calling a tag moved. Moving a tag needs write access to the registry - the same access an unsigned image would need.

Why an ImageValidatingPolicy, and Why the Format Matters

Signatures and attestations live in the registry next to the image, and there are two ways to store them:

  • the older way - extra tags named after the digest (sha256-<digest>.sig, .att);
  • the newer way - Sigstore bundles attached to the image as OCI referrers. cosign 3 signs this way by default, and GitHub’s provenance is stored this way.

Kyverno’s older policy type, a ClusterPolicy with verifyImages, does not find signatures stored the newer way - no signatures found for a correctly signed image. The ImageValidatingPolicy reads both. And an image with evidence in both formats - an old-style SBOM next to new-style provenance - fails the SBOM check: once a referrer is present, the verifier reads only the referrers. Both were found on this platform by running the cluster’s verifier against the real images; neither by cosign verify alone.

Tested Against Real Images

tests/kyverno-supply-chain.test.sh runs the Kyverno engine against images pinned by digest - not fixtures, the registry’s real evidence:

ImageExpected
backend (newer format), frontend (older format) and the Guardian, each signed by its own CIpass
the backend image twice in one pod (initContainer and app)pass
a signed image with a foreign sidecar (busybox)pass - foreign images are not this policy’s business
an image that was never signedfail, also as an init container
a signed frontend with its SBOM in the older format next to a newer-format referrerfail

A second run maps backend images to the frontend’s signer: the real backend image must then fail. No real image is signed by another repository’s workflow, so this is how the test proves that each image is checked against its own signer. It runs in pre-commit and in CI, and needs the network. A pipeline change that alters the evidence - a new signing tool, a new attestation step - is exactly what it is for. The test runs the cluster’s Kyverno version (1.19), but not the cluster’s network: a new kind of evidence is also tried against the cluster, with a server dry-run in develop that must be admitted within the webhook’s 30 s.

When the Verifier Cannot Answer

Admission now depends on Kyverno reaching the registry and Sigstore’s public trust root. In the application namespaces, a failed lookup refuses the pod: no proof, no admission - the right default for this rule, and the reason an outage of either service blocks new pods there. Running pods are not affected. Elsewhere the audit copy admits and reports nothing for that pod.

Verification is not free. Uncached, a signature plus its SBOM took about ten seconds on kind - exactly the default webhook timeout, so every first verification was cut off and signed pods were refused. The policy sets the maximum, 30 seconds. With one SBOM per platform an image takes about fifteen seconds; verified twice in one request - the backend’s app and its migrate initContainer - it went past 30 seconds, and every new backend pod was refused until the policy verified each image once. Kyverno caches a verified digest for an hour, so the next pod with the same image is admitted quickly. And as with every Kyverno policy, stopping Kyverno on purpose removes its webhooks and switches this check off too (Chapter 16) - only the break-glass kubeconfig can.

There is no exception path for this policy: an image that cannot be verified is rebuilt by its pipeline. A PolicyException could technically name it; scripts/check-policy-exceptions.sh accepts only Chapter 16’s admission guardrails, so a pull request with one for verify-images-* fails.

Instructions for Your AI Agent

The rules this chapter adds:

  1. Never build or push an image from a workstation, and never sign one by hand: an image reaches the registry only through its repository’s build.yml. Enforced by: the policy refuses, in the application namespaces, any image of the platform’s registry not signed by its own repository’s workflow.
  2. When a signed image is refused, find out why before anything else (cosign verify, cosign verify-attestation --type spdxjson, the policy’s test) - never widen the signer identity, switch the policy to Audit or add an exception to get it through. Enforced by: tests/kyverno-supply-chain.test.sh (pre-commit and CI) fails when a verdict changes; review of the policy diff.
  3. A change that touches signing - a cosign or attest action version, the signing step - is verified against the policy with a real signed image before it merges. Enforced by: instruction; the test’s real images.

This builds on: Admission Policy Guardrails (Chapter 16) - the same engine, with Audit and Enforce applied by namespace - and Version Promotion (Chapter 10): one digest from staging to production. This enables: Rollback and Data Migrations (Chapter 18) - a rollback to a digest whose origin is proven.