TExcelTAD
Home › Software Supply Chain Security: SBOM, SLSA & Sigstore › Admission Control: Kyverno & policy-controller

Admission Control: Kyverno & policy-controller

Everything so far produces evidence: SBOMs, scan reports, signatures, provenance. Admission control is where the evidence is required. In Kubernetes, an admission webhook sees every Pod before it's created and can reject it, or rewrite it, if its images don't meet policy. The Admission Controllers lesson in the Kubernetes course covers the mechanism; this lesson covers the supply-chain policies people run there.

Note: Admission controllers run inside a Kubernetes cluster, so the policies below are non-run samples. The cosign verify and verify-attestation sessions earlier in the course are the same checks these controllers perform.

What a deploy-time policy checks

  1. The image is referenced by digest (or the controller resolves the tag and rewrites the Pod to the digest, so what was verified is what runs).
  2. The digest has a signature from a trusted identity or key.
  3. Required attestations exist and satisfy conditions: provenance from the release workflow of the right repository, an SBOM, a scan result without critical findings, VEX for accepted exceptions.
  4. Images from registries outside an allow-list are rejected outright.

Two open-source controllers dominate: Kyverno (a general policy engine with image verification built in) and Sigstore's policy-controller (only image verification, from the cosign authors). OPA Gatekeeper with external data providers, Ratify, and cloud features (GKE Binary Authorization, AKS image integrity) cover the same ground.

Kyverno

yaml
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: verify-acme-images
spec:
  webhookConfiguration:
    failurePolicy: Fail               # if Kyverno is down, don't admit unverified Pods
  rules:
    - name: signed-release-images
      match:
        any:
          - resources:
              kinds: [Pod]
      verifyImages:
        - imageReferences:
            - "ghcr.io/acme/*"
          mutateDigest: true          # rewrite image: ghcr.io/acme/shop:1.4.2 -> @sha256:…
          verifyDigest: true          # and require digests
          required: true
          attestors:
            - entries:
                - keyless:
                    issuer: "https://token.actions.githubusercontent.com"
                    subject: "https://github.com/acme/shop/.github/workflows/release.yml@refs/tags/*"
                    rekor:
                      url: https://rekor.sigstore.dev
          attestations:
            - type: https://slsa.dev/provenance/v1
              attestors:
                - entries:
                    - keyless:
                        issuer: "https://token.actions.githubusercontent.com"
                        subject: "https://github.com/acme/shop/.github/workflows/release.yml@refs/tags/*"
              conditions:
                - all:
                    - key: "{{ buildDefinition.externalParameters.workflow.repository }}"
                      operator: Equals
                      value: "https://github.com/acme/shop"

For key-based signatures, replace the keyless entry with keys: { publicKeys: "-----BEGIN PUBLIC KEY----- …" }, or a KMS reference. Newer Kyverno releases also offer a CEL-based ImageValidatingPolicy type; the concepts are the same, so check the documentation of the version you run.

Sigstore policy-controller

policy-controller applies to namespaces labelled policy.sigstore.dev/include=true and evaluates every matching ClusterImagePolicy:

yaml
apiVersion: policy.sigstore.dev/v1beta1
kind: ClusterImagePolicy
metadata:
  name: acme-release-images
spec:
  images:
    - glob: "ghcr.io/acme/**"
  authorities:
    - keyless:
        url: https://fulcio.sigstore.dev
        identities:
          - issuer: https://token.actions.githubusercontent.com
            subjectRegExp: '^https://github\.com/acme/shop/\.github/workflows/release\.yml@refs/tags/v[0-9.]+
  


      attestations:
        - name: release-provenance
          predicateType: https://slsa.dev/provenance/v1
          policy:
            type: cue
            data: |
              predicateType: "https://slsa.dev/provenance/v1"
              predicate: buildDefinition: externalParameters: workflow: repository: "https://github.com/acme/shop"

The CUE policy is the same language as cosign verify-attestation --policy (Checking Attestations with Policies), so you can test it in CI against the real attestation before deploying it. For a key pair, an authority is key: { data: "-----BEGIN PUBLIC KEY----- …" }.

A model: the admission decision

python · try it yourself
import re

SIGNED = {   # digest -> (signer identity, attestation types) as the controller would verify them
    "sha256:aaa": ("https://github.com/acme/shop/.github/workflows/release.yml@refs/tags/v1.4.2", {"slsa", "cyclonedx"}),
    "sha256:bbb": ("https://github.com/acme/shop/.github/workflows/ci.yml@refs/heads/main", {"cyclonedx"}),
}
TAGS = {"ghcr.io/acme/shop:1.4.2": "sha256:aaa", "ghcr.io/acme/shop:edge": "sha256:bbb"}
IDENTITY = re.compile(r"^https://github\.com/acme/shop/\.github/workflows/release\.yml@refs/tags/v[0-9.]+
quot;) ALLOWED_REGISTRIES = ("ghcr.io/acme/",) def admit(image): if not image.startswith(ALLOWED_REGISTRIES): return "DENY", image, "registry not allowed" if "@sha256:" in image: name, digest = image.split("@") else: name, digest = image.rsplit(":", 1)[0], TAGS.get(image) if digest is None: return "DENY", image, "tag not found" pinned = f"{name}@{digest}" # mutateDigest: what will actually run signer, atts = SIGNED.get(digest, (None, set())) if signer is None: return "DENY", pinned, "no signature" if not IDENTITY.match(signer): return "DENY", pinned, f"signed by {signer.split('workflows/')[1]}, not the release workflow" if "slsa" not in atts: return "DENY", pinned, "no provenance" return "ALLOW", pinned, "signed release with provenance" for image in ["ghcr.io/acme/shop:1.4.2", "ghcr.io/acme/shop:edge", "ghcr.io/acme/shop@sha256:ccc", "docker.io/library/nginx:1.29"]: verdict, ref, why = admit(image) print(f"{image:30} {verdict:5} -> {ref:30} ({why})")
ghcr.io/acme/shop:1.4.2        ALLOW -> ghcr.io/acme/shop@sha256:aaa   (signed release with provenance)
ghcr.io/acme/shop:edge         DENY  -> ghcr.io/acme/shop@sha256:bbb   (signed by ci.yml@refs/heads/main, not the release workflow)
ghcr.io/acme/shop@sha256:ccc   DENY  -> ghcr.io/acme/shop@sha256:ccc   (no signature)
docker.io/library/nginx:1.29   DENY  -> docker.io/library/nginx:1.29   (registry not allowed)

Note the first line: the Pod asked for a tag, and the controller admitted the digest it verified. Without that rewrite, the node would resolve the tag again when pulling, and a tag moved in between would run an unverified image.

Rolling it out

  • Audit first. Both controllers can warn instead of block (Kyverno's Audit mode, policy-controller's mode: warn). Run in audit mode until the logs show only expected violations.
  • Exclude the system. Policies that block kube-system or the controller's own images can make a cluster unrecoverable; scope by namespace.
  • Fail closed for production namespaces (failurePolicy: Fail), and make the controller highly available, so an outage of the controller doesn't become an outage of deployments or a bypass.
  • Test policies in CI with the same verification commands against the image you're about to deploy; a policy you first exercise in production is a production incident.

Test yourself

Why should an admission controller rewrite shop:1.4.2 to shop@sha256:… after verifying it?

  1. Digests are shorter
  2. So the node runs exactly the digest that was verified, even if the tag moves before the pull
  3. Kubernetes requires digests
  4. To skip signature checks next time

What does the namespace label policy.sigstore.dev/include=true do?

  1. Signs the namespace
  2. Opts the namespace into policy-controller's image verification
  3. Disables Kyverno
  4. Pins images

How should a new image-verification policy be rolled out?

  1. Enforce everywhere immediately
  2. Audit/warn mode first, exclude system namespaces, then enforce with failurePolicy Fail in production
  3. Only in development clusters forever
  4. Disable it during deploys