Our Kubernetes clusters pulled images by tag from a registry that about forty CI pipelines and a handful of humans could push to. If any of those credentials leaked, someone could push a modified image under a valid tag and the cluster would run it on the next restart. Pinning digests in manifests helped, but it did not answer the question that matters: did this image come from our pipeline, built from our repository?

Image signing answers that question. With Sigstore's cosign in keyless mode, the CI job signs the image using its own OIDC identity, so there are no signing keys to store or rotate. Attaching a provenance attestation adds "built from which commit, by which workflow". An admission policy then refuses any image that lacks a valid signature from the expected identity. This guide walks through all three. Scanning (SAST, SCA, IaC) is a separate layer covered in post 297, and pinning third-party actions is in post 159.

What keyless signing actually does

"Keyless" does not mean there is no key. It means the key is short-lived and nobody stores it:

  1. The CI job generates a temporary key pair in memory.

  2. It sends its OIDC token to Fulcio, Sigstore's certificate authority. Fulcio checks the token and issues a certificate valid for about ten minutes. The certificate embeds the identity from the token: for GitHub Actions, the workflow file path and ref; for GitLab, the project path and ref.

  3. cosign signs the image digest with the temporary key and records the signature and certificate in Rekor, a public append-only transparency log.

  4. The signature is stored in the registry next to the image.

  5. The private key is thrown away.

Verification later checks that the signature matches the digest, that the certificate chains to Fulcio, that Rekor recorded it during the certificate's validity window, and, most importantly, that the identity in the certificate is the one you expect.

Signing in GitHub Actions

jobs:
  build:
    runs-on: ubuntu-24.04
    permissions:
      contents: read
      packages: write
      id-token: write        # needed for keyless signing
      attestations: write    # needed for GitHub artifact attestations
    steps:
      - uses: actions/checkout@v4
      - uses: docker/setup-buildx-action@v3
      - uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - id: build
        uses: docker/build-push-action@v6
        with:
          push: true
          tags: ghcr.io/example-org/api:${{ github.sha }}
          provenance: mode=max
          sbom: true
      - uses: sigstore/cosign-installer@v3
      - name: Sign image by digest
        run: cosign sign --yes "ghcr.io/example-org/api@${{ steps.build.outputs.digest }}"
      - uses: actions/attest-build-provenance@v2
        with:
          subject-name: ghcr.io/example-org/api
          subject-digest: ${{ steps.build.outputs.digest }}
          push-to-registry: true

Always sign the digest, never a tag. A tag can be moved after signing; a digest cannot.

provenance: mode=max makes BuildKit attach its own SLSA provenance to the image index, and sbom: true attaches an SBOM. actions/attest-build-provenance creates a separate, signed provenance statement tied to the workflow run, which you can verify with the GitHub CLI.

Signing in GitLab CI

GitLab issues the OIDC token through id_tokens with the audience Sigstore expects:

sign-image:
  image: alpine:3.21
  needs: [build-image]
  id_tokens:
    SIGSTORE_ID_TOKEN:
      aud: sigstore
  variables:
    COSIGN_YES: "true"
  before_script:
    - apk add --no-cache cosign
    - echo "$CI_REGISTRY_PASSWORD" | cosign login "$CI_REGISTRY" -u "$CI_REGISTRY_USER" --password-stdin
  script:
    - cosign sign "$CI_REGISTRY_IMAGE@$IMAGE_DIGEST"
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

cosign detects SIGSTORE_ID_TOKEN automatically. IMAGE_DIGEST comes from the build job through a dotenv artifact report.

What SLSA provenance adds

A signature says "this identity vouched for this digest". Provenance says how the artifact was made: source repository and commit, build platform, workflow, parameters and dependencies. SLSA (Supply-chain Levels for Software Artifacts) defines levels for the build track:

Level

Requirement in short

What it protects against

Build L1

Provenance exists

Mistakes, unknown origins

Build L2

Provenance is signed by a hosted build platform

Tampering after the build

Build L3

Hardened build platform; build cannot forge its own provenance

Tampering by the build's own steps

GitHub-hosted runners with artifact attestations and GitLab's hosted runners can reach Build L2 out of the box. L3 requires that signing material is isolated from user-defined build steps, for example with reusable workflows that perform the build and sign, so a compromised step in a calling repository cannot fabricate provenance.

Verifying on the command line

Verification must pin the identity. Checking only that "some valid signature exists" accepts signatures from any GitHub repository in the world.

cosign verify ghcr.io/example-org/api@sha256:4b7a... \
  --certificate-identity-regexp '^https://github.com/example-org/api/\.github/workflows/release\.yml@refs/heads/main$' \
  --certificate-oidc-issuer https://token.actions.githubusercontent.com

For GitLab-signed images, the identity is the pipeline's project URL with ref and the issuer is your GitLab URL:

cosign verify registry.gitlab.com/example-group/api@sha256:9d1e... \
  --certificate-identity 'https://gitlab.com/example-group/api//.gitlab-ci.yml@refs/heads/main' \
  --certificate-oidc-issuer https://gitlab.com

GitHub attestations verify with the CLI:

gh attestation verify oci://ghcr.io/example-org/api@sha256:4b7a... --owner example-org

Enforcing at admission

Signing without enforcement is documentation. The enforcement point is the Kubernetes admission controller: reject pods whose images are not signed by the expected identity. Two common options are Kyverno and the Sigstore policy controller.

With Kyverno:

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: require-signed-images
spec:
  validationFailureAction: Enforce
  webhookTimeoutSeconds: 15
  rules:
    - name: verify-ghcr-signatures
      match:
        any:
          - resources:
              kinds: [Pod]
      verifyImages:
        - imageReferences:
            - "ghcr.io/example-org/*"
          mutateDigest: true
          verifyDigest: true
          attestors:
            - entries:
                - keyless:
                    subject: "https://github.com/example-org/*/.github/workflows/release.yml@refs/heads/main"
                    issuer: "https://token.actions.githubusercontent.com"
                    rekor:
                      url: https://rekor.sigstore.dev

mutateDigest: true rewrites the tag in the pod spec to the verified digest, so the node pulls exactly what was verified. Newer Kyverno releases also offer a dedicated image validation policy type; check the docs for your version.

The Sigstore policy controller uses a ClusterImagePolicy with the same identity and issuer fields and applies to namespaces you opt in with a label.

Roll it out in stages: start in audit mode, look at which workloads would be rejected (third-party images, init containers, old deployments), fix or exempt them explicitly, then switch to enforce.

Operational details we learned

  • Third-party images. Many upstream projects sign their images with cosign. Add their identities as separate policy rules instead of exempting them. For those that do not sign, mirror them into your registry through a pipeline that verifies checksums and signs the mirrored digest.

  • Admission availability. If the admission webhook is down, the failure policy decides whether pods start. For signature checks we fail closed in production and keep two or more replicas of the controller.

  • Private infrastructure. The public Fulcio and Rekor instances record your identity (repository and workflow names) publicly. For private repositories where that matters, a private Sigstore deployment or key-based signing with a KMS key is an alternative.

  • Air-gapped clusters. Verification needs Rekor and the trust root; mirror the TUF root and use offline bundle verification if clusters cannot reach the internet.

Common mistakes

Mistake

Why it hurts

Do this instead

Signing a tag

Tag can be moved to an unsigned image

Sign and deploy by digest

Verifying without identity constraints

Any repo's signature passes

Pin identity and issuer

Identity regexp that matches any branch

Feature branches can produce "valid" images

Anchor to the release workflow and refs/heads/main

Enforcing on day one

Third-party and legacy workloads fail to start

Audit first, then enforce

Signing in a step any job can reach

Compromised steps can sign anything

Isolate signing in a protected or reusable workflow

Key takeaways

  • Keyless cosign signs with the CI job's OIDC identity; no key storage or rotation.

  • Sign digests, and attach provenance so you know which commit and workflow built the image.

  • Verification is only as strong as the identity you pin.

  • Enforce at admission with Kyverno or the Sigstore policy controller, starting in audit mode.

  • Plan for third-party images, webhook availability and public log visibility.

References