TExcelTAD
Home › Software Supply Chain Security: SBOM, SLSA & Sigstore › Checking Attestations with Policies

Checking Attestations with Policies

Verifying an attestation's signature tells you who made a claim. Policies check what the claim says: that the provenance names your CI as the builder, that the test results show zero failures, that the SBOM contains no banned component. cosign verify-attestation --policy evaluates a CUE or Rego policy against each verified statement, and admission controllers (Admission Control) use the same languages.

What the policy sees is the decoded statement: _type, subject, predicateType and predicate.

CUE: the statement must unify with the policy

A CUE policy is a partial document. Verification passes if the statement is compatible with it: every field the policy fixes must have that value, and constraints such as >100 must hold.

bash · try it yourself
crane push /opt/samples/images/alpine-3.18.0.tar localhost:5000/shop/app:1.4.2 > /dev/null 2>&1
IMG=localhost:5000/shop/app@$(crane digest localhost:5000/shop/app:1.4.2)
printf '{"suite": "integration", "passed": 214, "failed": 0, "commit": "3f2a9c1"}\n' > tests.json
cosign attest --key /opt/keys/cosign.key --signing-config /opt/sigstore/offline-signing-config.json \
  --type https://example.com/attestations/test-results/v1 --predicate tests.json "$IMG" > /dev/null 2>&1

cat > tests-pass.cue <<'CUE'
predicateType: "https://example.com/attestations/test-results/v1"
predicate: {
	suite:  "integration"
	failed: 0
	passed: >100
}
CUE
cat > tests-strict.cue <<'CUE'
predicate: passed: >500
CUE
for p in tests-pass.cue tests-strict.cue; do
  echo "--- $p"
  cosign verify-attestation --key /opt/keys/cosign.pub --insecure-ignore-tlog \
    --type https://example.com/attestations/test-results/v1 --policy $p "$IMG" 2>&1 > /dev/null \
    | grep -E '^(will be|- |Error)'
  echo "exit ${PIPESTATUS[0]}"
done
--- tests-pass.cue
will be validating against CUE policies: [tests-pass.cue]
exit 0
--- tests-strict.cue
will be validating against CUE policies: [tests-strict.cue]
- predicate.passed: invalid value 214 (out of bound >500)
Error: 1 validation errors occurred
exit 1

Rego: rules that must allow

Rego (the Open Policy Agent language) policies for cosign live in package signature and must make allow true. Rego is better than CUE at logic over lists ("no component may be named …", "every subject must…"):

bash · try it yourself
crane push /opt/samples/images/alpine-3.18.0.tar localhost:5000/shop/app:1.4.2 > /dev/null 2>&1
IMG=localhost:5000/shop/app@$(crane digest localhost:5000/shop/app:1.4.2)
syft scan "$IMG" -q -o cyclonedx-json=sbom.cdx.json
cosign attest --key /opt/keys/cosign.key --signing-config /opt/sigstore/offline-signing-config.json \
  --type cyclonedx --predicate sbom.cdx.json "$IMG" > /dev/null 2>&1

banned() {   # banned <package name>: write a policy that rejects SBOMs containing it
  cat > no-$1.rego <<REGO
package signature

import rego.v1

default allow := false

allow if {
  input.predicateType == "https://cyclonedx.org/bom"
  count([c | some c in input.predicate.components; c.name == "$1"]) == 0
}
REGO
}
for pkg in log4j-core busybox; do
  banned $pkg
  cosign verify-attestation --key /opt/keys/cosign.pub --insecure-ignore-tlog \
    --type cyclonedx --policy no-$pkg.rego "$IMG" > /dev/null 2>&1
  echo "policy no-$pkg: exit $?"
done
policy no-log4j-core: exit 0
policy no-busybox: exit 1

The image contains no log4j-core (pass) but does contain busybox (fail). Real policies of this kind ban known-malicious packages, end-of-life base images or components with forbidden licenses.

A model: the checks a release policy makes

Production policies combine several attestations. This model is the decision a deploy gate makes for one image, written out in plain code; CUE, Rego, Kyverno and policy-controller express the same checks declaratively.

python · try it yourself
EXPECTED = {
    "builder": "https://github.com/acme/shop/.github/workflows/release.yml@refs/tags/v1.4.2",
    "repo": "https://github.com/acme/shop",
}

def decide(image_digest, attestations):
    reasons = []
    by_type = {a["predicateType"]: a for a in attestations if a["verified"]}
    for a in attestations:
        if a["verified"] and all(s["digest"] != image_digest for s in a["subject"]):
            reasons.append(f"{a['predicateType']} is about another artifact")
    prov = by_type.get("https://slsa.dev/provenance/v1")
    if not prov:
        reasons.append("no verified provenance")
    else:
        p = prov["predicate"]
        if p["builder"] != EXPECTED["builder"]:
            reasons.append(f"unexpected builder {p['builder']}")
        if p["repo"] != EXPECTED["repo"]:
            reasons.append(f"built from {p['repo']}")
    if "https://cyclonedx.org/bom" not in by_type:
        reasons.append("no verified SBOM")
    return ("ALLOW", []) if not reasons else ("DENY", reasons)

good_prov = {"predicateType": "https://slsa.dev/provenance/v1", "verified": True, "subject": [{"digest": "sha256:aaa"}],
             "predicate": {"builder": EXPECTED["builder"], "repo": EXPECTED["repo"]}}
sbom = {"predicateType": "https://cyclonedx.org/bom", "verified": True, "subject": [{"digest": "sha256:aaa"}], "predicate": {}}
fork_prov = dict(good_prov, predicate={"builder": "https://github.com/mallory/shop/.github/workflows/release.yml@refs/heads/main",
                                       "repo": "https://github.com/mallory/shop"})
unsigned_sbom = dict(sbom, verified=False)
old_prov = dict(good_prov, subject=[{"digest": "sha256:old"}])

cases = {
    "release build":            ("sha256:aaa", [good_prov, sbom]),
    "built in a fork":          ("sha256:aaa", [fork_prov, sbom]),
    "SBOM signature invalid":   ("sha256:aaa", [good_prov, unsigned_sbom]),
    "provenance of old image":  ("sha256:aaa", [old_prov, sbom]),
}
for name, (digest, atts) in cases.items():
    verdict, why = decide(digest, atts)
    print(f"{name:24} {verdict}" + (f": {'; '.join(why)}" if why else ""))
release build            ALLOW
built in a fork          DENY: unexpected builder https://github.com/mallory/shop/.github/workflows/release.yml@refs/heads/main; built from https://github.com/mallory/shop
SBOM signature invalid   DENY: no verified SBOM
provenance of old image  DENY: https://slsa.dev/provenance/v1 is about another artifact

The "fork" case is the important one: the fork's provenance is validly signed (by GitHub's signing infrastructure, on behalf of the fork's workflow). Only the policy's check of who built it, from which repository, rejects it. A signature check without an identity check accepts anything anyone signed.

Test yourself

What does a CUE policy passed to cosign verify-attestation --policy require?

  1. That the statement exactly equals the policy
  2. That the statement unifies with it: fixed fields match and constraints hold
  3. That the policy is signed
  4. Nothing; CUE policies are documentation

In a cosign Rego policy, what must the policy define?

  1. package main with deny rules
  2. package signature with an allow rule that evaluates to true
  3. A JSON schema
  4. A CUE file

Why is checking only that provenance is validly signed insufficient?

  1. Signatures can be forged easily
  2. Anyone, including a fork's workflow, can produce validly signed provenance; the policy must check the builder and source identity
  3. Provenance is never signed
  4. Rekor rejects forks