For most platform teams, the Software Bill of Materials (SBOM) is a passive artifact. It is generated by a CI job, uploaded to a registry or a database, and then ignored until a security auditor asks for it or a Zero-Day vulnerability forces a frantic grep across a thousand JSON files. This is security theater.

True supply chain security requires moving from generation to enforcement. If an image does not have a verified SBOM attestation, it should never reach a production node. This transforms the SBOM from a post-mortem report into a hard admission gate.


graph TD
    A[Source Code] --> B[CI Build Pipeline]
    B --> C[Trivy/Syft: Generate SBOM]
    C --> D[Cosign: Sign & Attest SBOM]
    D --> E[OCI Registry]
    E --> F[K8s Admission Request]
    F --> G{Kyverno Policy}
    G -- "No Verified SBOM" --> H[Reject Pod]
    G -- "Verified SBOM" --> I[Allow Pod]
    I --> J[Runtime Node]

The Technical Stack: The Enforcement Trinity

Implementing a block-at-admission policy requires three distinct components working in concert: a generator, an attestor, and an enforcer.

Role Tool Primary Output Production Reality
Generator Trivy / Syft CycloneDX / SPDX JSON False positives in dependency trees are common; require a VEX (Vulnerability Exploitability eXchange) loop.
Attestor Cosign In-toto Statement (Signed) Key management is the bottleneck. Keyless (Fulcio/Rekor) is the standard for CI, but requires OIDC.
Enforcer Kyverno K8s Admission Decision Admission webhooks add latency. Improper caching can lead to "thundering herd" registry calls.

Step 1: Generating and Attesting the SBOM

An SBOM is useless for enforcement if it exists as a separate file in S3. To be verifiable at the admission level, the SBOM must be an attestation—a signed statement attached to the image digest in the OCI registry.

The standard workflow uses trivy for the scan and cosign to wrap the output in an in-toto statement.


# 1. Generate the SBOM in CycloneDX JSON format
trivy image --format cyclonedx -o sbom.json ghcr.io/platform-monkey/api-gateway:latest

# 2. Attest the SBOM using a private key (or keyless OIDC)
# The --type flag is critical; it defines the predicateType for the enforcer
cosign attest --key cosign.key \
  --type cyclonedx \
  --predicate sbom.json \
  ghcr.io/platform-monkey/api-gateway:latest

Cosign creates an OCI artifact at sha256-<digest>.att. This artifact contains the signed payload, which Kyverno will later fetch and verify.

Step 2: Implementing the Admission Gate with Kyverno

Modern Kyverno (v1.19+) has transitioned toward the ImageValidatingPolicy API, which uses CEL (Common Expression Language) for high-performance verification. The policy must verify two things: that the attestation is signed by a trusted entity and that the payload is actually a valid SBOM.


apiVersion: policies.kyverno.io/v1
kind: ImageValidatingPolicy
metadata:
  name: enforce-sbom-attestation
spec:
  matchConstraints:
    resourceRules:
      - apiGroups: [""]
        apiVersions: ["v1"]
        operations: ["CREATE"]
        resources: ["pods"]
    matchImageReferences:
      - glob: "ghcr.io/platform-monkey/*"
  attestors:
    - name: platform-pipeline
      cosign:
        keyless:
          identities:
            - subject: "github.com/platform-monkey/api-gateway/.github/workflows/ci.yml"
              issuer: "token.actions.githubusercontent.com"
              ctlog: "rekor.sigstore.dev"
  attestations:
    - name: sbom
      intoto:
        type: "cyclonedx.org/bom"
  validations:
    - expression: >-
        images.containers.map(image, 
          verifyAttestationSignatures(image, attestations.sbom, [attestors.platform-pipeline])
        ).all(e, e > 0)
      message: "Image lacks a signed SBOM attestation from the official pipeline."
    - expression: >-
        images.containers.map(image, 
          extractPayload(image, attestations.sbom).predicate.bomFormat == 'CycloneDX'
        ).all(e, e)
      message: "SBOM attestation found, but the format is not CycloneDX."

Deep Dive: The Logic Flow

  • verifyAttestationSignatures: This function fetches the .att artifact from the registry, verifies the signature against the Rekor transparency log (for keyless) or a public key, and returns a boolean.
  • extractPayload: This extracts the in-toto predicate. Crucially, extractPayload will fail if the signature verification hasn't already passed, preventing the policy from acting on untrusted data.
  • .all(e, e): Since a Pod can have multiple containers, we map the verification across all images and ensure every single one returns true.

Production Realities: Where This Breaks at Scale

Moving to a "Block-at-Admission" model is a high-friction event. If your CI pipeline fails to sign an image, your production deployments stop. Here is the operational toil you will encounter:

1. The Registry Bottleneck

Every Pod creation request now triggers a network call to the OCI registry to fetch the attestation. In a large cluster with frequent scaling events, this can put significant load on your registry. Enable ImageVerify caching in Kyverno to reduce this overhead, but be wary of the TTL—if you rotate a key or revoke an attestation, the cache can hide the change.

2. The "Emergency Break" Pattern

There will be a moment when a critical security patch must ship, but the SBOM generator is down. You cannot wait for the CI to be fixed. Implement a break-glass annotation in your policy:


# Add to validations expression
- expression: >-
    request.object.metadata.annotations['platform-monkey.com/skip-sbom-verify'] == 'true' || 
    images.containers.map(...)

This allows SREs to bypass the gate for a specific deployment, provided they have the RBAC permissions to add the annotation. This should be audited via a separate alert.

3. OCI 1.1 Referrers vs. Tag-based Attestations

Cosign traditionally writes attestations to sha256-digest.att tags. The OCI 1.1 specification introduces a Referrers API. If your registry is old, the Referrers API will 404, and Kyverno must fall back to the tag-based lookup. If you configure Kyverno to use referrer: instead of intoto: on a registry that doesn't support it, the policy will report the attestation as missing even when it exists.

Who Should Skip This Pattern?

Do NOT implement hard SBOM enforcement if:

  • You have a legacy mono-repo with hundreds of undocumented dependencies that produce massive, unstable SBOMs. You will spend months tuning false positives.
  • Your registry is a bottleneck and you cannot implement a local cache/proxy. The latency added to Pod startup can trigger liveness probe failures during scale-up.
  • You lack OIDC-based CI. Managing long-lived Cosign private keys across multiple teams is an operational nightmare that often leads to keys being committed to Git.

References & Further Reading