123DevOps··6 min read

Supply chain security: signing images with Cosign, generating SBOMs, and leveling up in SLSA

How to sign images without managing keys (keyless with OIDC), generate and attach SBOMs, publish provenance, verify signatures in the cluster with Kyverno, and progress through the SLSA levels.

CI/CD

Software supply chain attacks are no longer rare: malicious dependencies published to public registries, compromised CI actions, build credentials stolen to publish tampered versions. In every one of these cases, the code you reviewed is not exactly the code that ran.

The question supply chain security answers is simple: “how do I prove that this image running in production came from this commit, was built by this pipeline, with these dependencies?” Three pieces answer it together: signing, SBOM, and provenance — organized by the SLSA framework.

The three pieces

  • Signing (Cosign/Sigstore): proves the image was produced by a trusted identity and hasn’t been altered since.
  • SBOM (Software Bill of Materials): the ingredient list — every package and version inside the image, in SPDX or CycloneDX format.
  • Provenance: an attestation of how the artifact was built — repository, commit, workflow, parameters, and build environment.

SLSA in a nutshell

SLSA (Supply-chain Levels for Software Artifacts) organizes these practices into levels. In the build track of version 1.0:

Level Requires Protects against
Build L1 Provenance generated and available Mistakes and lack of traceability
Build L2 Build on a hosted platform, with provenance signed by that platform Tampering after the build
Build L3 A hardened build platform that isolates builds and protects signing keys Tampering during the build, including by other builds

With GitHub Actions (or other hosted CI systems) and the right tools, reaching L2 takes just a few lines of YAML — and L3 is achievable with isolated provenance generators.

Keyless signing: no keys to safeguard

Historically, the biggest obstacle to signing was managing private keys. Sigstore solves this with keyless signing:

  1. CI obtains an OIDC token that identifies the workflow (repository, branch, workflow file).
  2. Sigstore’s certificate authority (Fulcio) issues a short-lived certificate for that identity.
  3. Cosign signs the image, and the signature is recorded in the public transparency log (Rekor).

There is no long-lived private key to leak. Trust comes from the workflow identity.

The complete pipeline in GitHub Actions

name: signed-build
on:
  push:
    branches: [main]

permissions:
  contents: read
  packages: write
  id-token: write         # required for keyless signing (OIDC)
  attestations: write     # required for provenance attestations

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      IMAGE: ghcr.io/your-org/api
    steps:
      - uses: actions/checkout@v4

      - uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and push
        id: build
        uses: docker/build-push-action@v6
        with:
          push: true
          tags: ${{ env.IMAGE }}:${{ github.sha }}

      - name: Generate SBOM
        uses: anchore/sbom-action@v0
        with:
          image: ${{ env.IMAGE }}@${{ steps.build.outputs.digest }}
          format: spdx-json
          output-file: sbom.spdx.json

      - uses: sigstore/cosign-installer@v3

      - name: Sign image and attach SBOM as an attestation
        env:
          REF: ${{ env.IMAGE }}@${{ steps.build.outputs.digest }}
        run: |
          cosign sign --yes "$REF"
          cosign attest --yes --type spdxjson --predicate sbom.spdx.json "$REF"

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

Three important details:

  • Everything operates on the digest, not the tag. Tags can be moved; digests can’t.
  • BuildKit can also generate the SBOM and provenance during the build (sbom: true and provenance: mode=max in build-push-action) — pick one approach and standardize on it.
  • Pin third-party actions by commit SHA, not by tag. A compromised action in the middle of your chain invalidates everything else.

Verifying: a signature only counts if someone checks it

Signing without verifying is theater. Verify manually:

cosign verify ghcr.io/your-org/api@sha256:3f1c... \
  --certificate-identity-regexp '^https://github.com/your-org/api/\.github/workflows/' \
  --certificate-oidc-issuer https://token.actions.githubusercontent.com

And, above all, in the cluster, blocking unsigned images at admission time. With Kyverno:

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: require-signed-image
spec:
  validationFailureAction: Enforce   # in recent versions, set failureAction on the rule itself
  webhookTimeoutSeconds: 30
  rules:
    - name: verify-signature
      match:
        any:
          - resources:
              kinds: [Pod]
      verifyImages:
        - imageReferences:
            - "ghcr.io/your-org/*"
          attestors:
            - entries:
                - keyless:
                    subject: "https://github.com/your-org/*"
                    issuer: "https://token.actions.githubusercontent.com"
                    rekor:
                      url: https://rekor.sigstore.dev

From then on, an image built on someone’s laptop — or tampered with in the registry — simply won’t start. The Sigstore policy-controller and Connaisseur are alternatives to Kyverno.

Start with the policy in audit mode (it only records violations), fix the images that don’t pass, and then switch to enforce.

Actually using the SBOM

An SBOM is only valuable if someone queries it. Practical uses:

  • Fast vulnerability response: when a critical CVE drops in a popular library, the question “which production images use that version?” gets answered in minutes, without rescanning everything.
  • Continuous scanning: tools such as Grype and Trivy scan the SBOM, including for old images that are still running.
  • Licenses: identifying dependencies whose licenses are incompatible with your product.
  • Customer requirements: contracts and regulations increasingly require SBOMs from software vendors.

Platforms such as Dependency-Track centralize the SBOMs of every service and continuously cross-reference them with vulnerability databases.

What else is part of the chain

Signing and SBOMs are at the core, but the chain has other links:

  • Least-privilege CI tokens (explicit permissions in every workflow) and cloud credentials via OIDC instead of static keys;
  • Pinned dependencies with lockfiles and reviewed updates (Dependabot, Renovate);
  • Branch protection and mandatory review, including for workflow files;
  • Minimal base images (distroless, hardened images) and multi-stage builds;
  • OpenSSF Scorecard to automatically assess the security practices of your repositories and your dependencies.

Adoption roadmap

  1. Week 1: generate SBOMs and provenance in every build (without blocking anything).
  2. Week 2: sign images with Cosign keyless.
  3. Week 3: install the verification policy in audit mode.
  4. Week 4: fix the exceptions and turn on enforcement in production.
  5. Afterwards: centralize SBOMs and automate CVE response.

Checklist

  • Images referenced and signed by digest
  • Keyless signing with the workflow identity
  • SBOM generated and attached as an attestation
  • Provenance published (SLSA Build L2)
  • Admission policy verifying signatures in the cluster
  • Third-party actions pinned by SHA
  • SBOMs centralized and continuously scanned

Trusting the code you reviewed isn’t enough. A secure supply chain guarantees that this exact code is what’s running.

Get updates on new posts and stay in the loop!