Distribuée
Cloud & AI Security
← All insights

Supply chain

Signing and attesting container images with cosign, blocking the rest with Kyverno

Full chain from build to keyless signature to registry to admission: GitHub Actions workflow, Kyverno policies and proof commands to deploy only images that came out of your CI.

· 6 min · #cosign#sigstore#kyverno#slsa#supply-chain#kubernetes#admission-control

In most clusters I audit, anyone with push rights on the registry, or a kubectl apply on a namespace, can run whatever image they like. The CI pipeline is hardened, but nothing proves at deploy time that the image about to start is the one that pipeline built.

Image signing closes exactly that gap. This article describes the minimum chain for an SMB: sign in CI with no key to manage, attest provenance, and have Kyverno reject everything else at admission. It builds on the article about GitHub Actions misconfigurations: hardening the workflow is pointless if the cluster also accepts images that did not come from it.

Build, keyless signature, registry, Kyverno admission chain

The threat: the cluster trusts a tag name

Three scenarios come up in practice:

  • Direct registry push with stolen credentials (a developer’s access key, an exfiltrated CI token): the attacker overwrites an existing tag and the next rollout pulls their image.
  • Image built outside the pipeline: a “temporary” local build promoted to production with no review and no scan.
  • Third-party or public image referenced directly in a manifest with no provenance check.

A tag is a mutable pointer. Only the digest (sha256:…) identifies content, and only a signature bound to an identity says who produced it. Sigstore provides that second piece without private-key management: in keyless mode, cosign gets a short-lived certificate from the Fulcio CA in exchange for the workflow’s OIDC token, signs, and records the operation in the Rekor transparency log (cosign keyless documentation). The signing identity is therefore not a key that can be stolen, but “this workflow, in this repository, on this branch”.

The CI control: sign by digest, attest provenance

Two complementary proofs:

  1. a cosign signature of the image (who produced it);
  2. a SLSA provenance attestation via actions/attest-build-provenance (how, from which commit and workflow). GitHub documents these artifact attestations; using reusable workflows brings you closer to level 3 of the SLSA Build track.
name: build-sign-push
on:
  push:
    branches: [main]

permissions: {}

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write        # push + store signature/attestation
      id-token: write        # OIDC token for Fulcio
      attestations: write    # provenance attestation
    env:
      IMAGE: ghcr.io/${{ github.repository }}
    steps:
      - uses: actions/checkout@<40-char-SHA> # v5 — pin with pinact
        with:
          persist-credentials: false

      - uses: docker/login-action@<40-char-SHA> # v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - id: build
        uses: docker/build-push-action@<40-char-SHA> # v6
        with:
          push: true
          tags: ${{ env.IMAGE }}:${{ github.sha }}

      - uses: sigstore/cosign-installer@<40-char-SHA> # v3

      - name: Sign by digest (keyless)
        env:
          DIGEST: ${{ steps.build.outputs.digest }}
        run: cosign sign --yes "${IMAGE}@${DIGEST}"

      - uses: actions/attest-build-provenance@v3
        with:
          subject-name: ${{ env.IMAGE }}
          subject-digest: ${{ steps.build.outputs.digest }}
          push-to-registry: true

Points to watch:

  • Sign the digest returned by the build, never a tag: a tag can be moved between push and signature.
  • id-token: write and attestations: write are granted to the build job only, never at workflow level.
  • Replace the <40-char-SHA> placeholders with real SHAs (pinact run does it); this is rule 4 of the previous article. The job must run on a push or workflow_dispatch event on main, not on pull_request_target.
  • On a private repository, recording in the public Rekor log exposes the repository and workflow names. If that matters, GitHub provides a dedicated Sigstore instance for its attestations on private repositories; document it in your risk analysis.

The cluster control: Kyverno rejects what is not signed

Kyverno verifies signatures at admission through verifyImages rules (Kyverno Sigstore documentation). The policy below has two rules: the image’s cosign signature, then the GitHub provenance attestation (Sigstore bundle format, supported since Kyverno 1.13).

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: verify-images-from-ci
spec:
  background: false
  webhookConfiguration:
    timeoutSeconds: 30
  rules:
    - name: verify-signature
      match:
        any:
          - resources:
              kinds: [Pod]
      exclude:
        any:
          - resources:
              namespaces: [kube-system, kyverno]
      verifyImages:
        - imageReferences:
            - "ghcr.io/ACME/*"
          failureAction: Audit   # switch to Enforce after 1-2 weeks
          mutateDigest: true
          attestors:
            - entries:
                - keyless:
                    issuer: "https://token.actions.githubusercontent.com"
                    subject: "https://github.com/ACME/app/.github/workflows/build-sign-push.yml@refs/heads/main"
                    rekor:
                      url: https://rekor.sigstore.dev

    - name: verify-provenance
      match:
        any:
          - resources:
              kinds: [Pod]
      exclude:
        any:
          - resources:
              namespaces: [kube-system, kyverno]
      verifyImages:
        - imageReferences:
            - "ghcr.io/ACME/*"
          failureAction: Audit
          type: SigstoreBundle
          attestations:
            - type: https://slsa.dev/provenance/v1
              attestors:
                - entries:
                    - keyless:
                        issuer: "https://token.actions.githubusercontent.com"
                        subject: "https://github.com/ACME/app/.github/workflows/build-sign-push.yml@refs/heads/main"
                        rekor:
                          url: https://rekor.sigstore.dev
              conditions:
                - all:
                    - key: "{{ buildDefinition.buildType }}"
                      operator: Equals
                      value: https://actions.github.io/buildtypes/workflow/v1

Replace ACME/app with your organization and repository. Several choices matter:

  • Exact subject, no wildcards. ACME/* would accept any repository in the organization, including a compromised test repo. Pin the workflow file and the main branch. If you use regular expressions (subjectRegExp), note that Kyverno 1.13.0 to 1.13.5 ignored them: CVE-2025-29778, fixed in 1.13.6 and 1.14.0. Check your version.
  • mutateDigest: true rewrites the tag to a digest after verification; what runs is exactly what was verified, and the tag can no longer move under you.
  • Audit first. Deploy in Audit, read the PolicyReports for one to two weeks to find third-party images and forgotten jobs, then switch to Enforce. Public images (cert-manager, ingress…) need their own rules with the publisher’s identity, or a documented exclusion.
  • Webhook availability. An Enforce policy with an unreachable webhook can block deployments. Run Kyverno in high availability (3 admission controller replicas) and exclude system namespaces.
  • API evolution. Current Kyverno documentation marks ClusterPolicy as deprecated in favor of ImageValidatingPolicy (the policies.kyverno.io API). The logic (issuer, subject, attestations) carries over; check the ImageValidatingPolicy documentation for the version you run before building a new baseline.

The proof: what you show an auditor

Three commands the auditor can reproduce themselves, with no access to your CI:

# 1. Signature: exact expected identity
cosign verify \
  --certificate-identity "https://github.com/ACME/app/.github/workflows/build-sign-push.yml@refs/heads/main" \
  --certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
  ghcr.io/ACME/app@sha256:<digest>

# 2. Provenance: source repository and workflow
gh attestation verify oci://ghcr.io/ACME/app@sha256:<digest> --repo ACME/app

# 3. Admission denial: an unsigned image must be rejected
kubectl run test-unsigned --image=docker.io/library/nginx:latest -n prod
kubectl get policyreport -A | head

The third test is the most telling: keep a capture of the denial (after switching to Enforce) and an export of the PolicyReports as evidence of continuous operation. For SOC 2 or ISO 27001 this feeds change-management and software-integrity controls; for NIS2, supply chain control.

What a signature does not guarantee

  • A signed image is not a healthy image. The signature proves origin, not absence of vulnerabilities: keep scanning (Trivy, Inspector) and the SBOM in the pipeline.
  • A compromised workflow signs perfectly well. If an external contributor gets code running in your build job (see pull_request_target), the malicious image will be signed with the right identity. Hence pinning the identity to the main branch and enforcing branch protection.
  • Plaintext secrets inside the image are not caught by a signature.
  • An admission control does not cover upstream access: also restrict registry push rights to the CI roles only.

Rolling it out in one week

  1. Days 1-2: add signature and attestation to the build workflow of a pilot service.
  2. Day 3: install Kyverno in HA, deploy the policy in Audit on that one namespace.
  3. Days 4-5: read the PolicyReports, handle third-party images (dedicated rule or justified exclusion).
  4. Following week: Enforce on the pilot, then extend namespace by namespace; consider requiring digest-based deployment in your ArgoCD manifests.

If you want to scope this chain end to end (workflow, registry, admission, audit evidence), that is the remit of our Supply Chain & CI/CD Security offer.

Found this useful? Share it.

Go further

A topic, a project, a question?

Distribuée supports demanding SMBs on cloud security, CI/CD supply chain and AI security.

Book 15 min