Signing a container image with cosign only protects you when the signing identity is tightly controlled and every cluster refuses images whose signature does not match that identity. This guide walks through the practical steps: deciding between keyless and key-based signing, signing by digest in a pipeline, keeping keys in a KMS, writing verification commands that pin the right identity, and enforcing the result at Kubernetes admission with the Sigstore policy-controller.
The conceptual model of Sigstore, its components and its admin surface are covered in the Sigstore Guide. This page is the hands-on companion. It treats the signer as what it really is: a non-human identity, either a CI workload holding a short-lived OIDC token or a service holding a long-lived private key, and it focuses on how to govern that identity so a signature means something.
Key takeaways
- A signature proves only that a particular identity signed a particular digest. Verification must pin both the expected identity and the expected issuer, or any valid Sigstore signature will pass.
- Keyless signing binds an ephemeral key to an OIDC identity through a short-lived Fulcio certificate and records the event in the Rekor transparency log. There is no long-lived private key to steal, but the CI identity becomes the thing to protect.
- Key-based signing is still valid for private or air-gapped environments. Keep the key in a cloud KMS, HashiCorp Vault or OpenBao and grant sign permission to one pipeline identity only.
- Always sign and deploy by digest (
@sha256:...), never by tag. The cosign project itself warns that signing a tag can mean signing something you did not intend. - Enforcement happens at admission. The Sigstore policy-controller blocks non-compliant images in opted-in namespaces and, by default, rejects images that match no policy.
- Start policies in
warnmode, measure, then switch to blocking namespace by namespace.
What a cosign signature actually proves
Cosign signs the image manifest digest, not the tag and not the layers individually. According to the cosign README, signed payloads include the digest of the container image, which is how a detached signature is tied to the correct image. When you run cosign verify, cosign by default validates that this digest matches the container being checked.
That gives you three facts after a successful verification:
- Integrity: the manifest, and therefore every layer it references, is byte-for-byte what was signed.
- Identity: a specific key, or a specific OIDC identity from a specific issuer, produced the signature.
- Transparency (keyless and public Rekor): the signing event was recorded in a public, append-only log, so it can be audited later.
It does not prove the image is free of vulnerabilities, that it was built from reviewed source, or that the build ran on a trusted runner. Those claims need attestations such as SLSA provenance, which cosign can attach and verify alongside the signature (covered below). For the difference between the two ideas, see Code Signing vs Artifact Attestation.
From an identity point of view, the important consequence is that whoever controls the signing identity controls what your clusters will run. A signing key or a CI identity able to sign production images deserves the same governance as a production admin credential.
Choosing keyless or key-based signing
The Sigstore documentation describes keyless signing as associating "identities, rather than keys, with an artifact signature", and makes identity-based signing the default because managing and distributing keys securely is hard. The trade-offs for a platform team look like this.
| Question | Keyless (OIDC and Fulcio) | Key-based (local key or KMS) |
|---|---|---|
| What signs | An ephemeral key, certified for minutes to an OIDC identity, then destroyed | A long-lived private key you generate and store |
| Identity to protect | The CI workload identity or human account that obtains the OIDC token | The key itself and every principal allowed to use it |
| What the verifier pins | Certificate identity plus OIDC issuer | The public key |
| Transparency log | Signing event recorded in Rekor | Optional, depending on configuration |
| Typical fit | Public or internet-connected CI on GitHub, GitLab, Google or Microsoft identities | Private registries, air-gapped estates, regulated environments wanting their own key custody |
Neither is universally right. Many organisations use keyless for internally built images on hosted CI and a KMS-held key for images produced in isolated build networks. The deeper design discussion is in Keyless vs Key-Based Code Signing.
One consideration specific to keyless signing on the public Sigstore instance: the docs state that clients upload signing events to the transparency log "so that the events are publicly auditable". The certificate in that log contains the signing identity, so workflow paths, repository names or email addresses become public. If that is unacceptable, use a private Sigstore deployment or key-based signing.
Signing an image by digest in CI
The basic keyless command is simply cosign sign $IMAGE. Interactively, cosign opens a browser so you can authenticate with Google, GitHub or Microsoft. In automation, cosign can use OIDC identity tokens from supported issuers directly. Per the Sigstore signing overview, a token can be passed with --identity-token or through the SIGSTORE_ID_TOKEN environment variable, and its audiences claim must contain sigstore.
A sound pipeline sequence looks like this:
- Build and push, then capture the digest. Read the digest from your build tool output (for example the image ID or metadata file) rather than resolving a tag afterwards, so there is no window in which the tag could move.
- Sign the digest reference.
cosign sign registry.example.com/team/app@sha256:<digest>. The README advises: "you should always sign images based on their digest", warning that otherwise you "might sign something you didn't intend to!" - Add annotations that help verification.
cosign sign -a repo=team/app -a pipeline=release $IMAGE. Verifiers can later require these with-a, and the docs note that every specified key-value pair must exist and match in the verified payload. - Attach provenance or SBOM attestations in the same job (see the attestations section).
- Verify immediately in the same pipeline using the exact policy production will use. A pipeline that cannot verify its own output will not pass admission either.
Identity hygiene in the signing job matters more than the command line:
- Only the release job should be able to obtain a token that your verification policy accepts. On GitHub Actions, grant
id-token: writeto that job alone, not the whole workflow. See the GitHub Actions OIDC Federation Hardening Guide. - Sign from protected branches or tags only. Your verification identity should encode that, for example a workflow path pinned to a release ref.
- Do not let pull request builds from forks reach the signing step.
- Treat the runner as part of the trust boundary. A compromised self-hosted runner can request a valid token. See Self-hosted CI/CD Runners and Build Agents.
Running cosign sign more than once attaches multiple signatures to the same image. That is useful for counter-signing (for example a build signature and a later security review signature), but it also means an extra, unexpected signature will not be noticed unless verification pins identities.
Key-based signing with a KMS
For key-based signing, cosign generate-key-pair creates cosign.key and cosign.pub, and cosign sign --key cosign.key $IMAGE signs. A key file on a build agent is exactly the kind of long-lived secret that leaks, so for anything beyond a lab use a key manager. Cosign accepts go-cloud style key URIs documented on the Sigstore signing page:
awskms://[ENDPOINT]/[ID/ALIAS/ARN]gcpkms://projects/[PROJECT]/locations/global/keyRings/[KEYRING]/cryptoKeys/[KEY]/versions/[VERSION]azurekms://[VAULT_NAME][VAULT_URI]/[KEY]hashivault://[KEY]andopenbao://[KEY]k8s://[NAMESPACE]/[KEY]for a key held in a Kubernetes secretenv://[ENV_VAR], which should be reserved for testing
Export the public key for verifiers with cosign public-key --key <provider>://<key> > kms.pub. With a KMS, the private key never leaves the service, and the control point becomes the KMS permission to sign. Govern it like this:
- Grant the sign permission on the key to one pipeline role, ideally federated through OIDC so the pipeline holds no static cloud credential.
- Deny key administration (policy changes, deletion scheduling, import) to that same role. Separation of duties stops a compromised pipeline from replacing the key.
- Alert on every sign operation that does not originate from the expected role, and on any key policy change.
- Use separate keys per environment or trust tier, so a development key cannot produce signatures production accepts.
- Plan rotation: publish the new public key to verifiers before switching the pipeline, accept both during a transition window, then remove the old key from policy.
Avoid k8s:// keys in the same cluster that enforces the policy. Anyone who can read that secret can sign images the cluster will accept.
Verifying signatures with cosign
Verification is where most deployments are weakest. The general form is cosign verify [--key <key path>|<key url>|<kms uri>] <image uri>.
Keyless verification
Always pin both the identity and the issuer:
cosign verify registry.example.com/team/app@sha256:<digest> --certificate-identity=<expected identity> --certificate-oidc-issuer=<expected issuer>
The Sigstore verify page lists issuer values including https://accounts.google.com, https://login.microsoftonline.com, https://github.com/login/oauth and https://gitlab.com. For GitHub Actions workloads, the cosign README example uses the issuer https://token.actions.githubusercontent.com. The certificate identity for a workflow is the workflow reference, so pin it to the exact repository, workflow file and release ref you expect.
Cosign also accepts --certificate-identity-regexp and --certificate-oidc-issuer-regexp. Use regular expressions sparingly and anchor them. An unanchored pattern such as .*my-org.* will match identities in repositories you do not own whose names merely contain your string.
Key-based verification
cosign verify --key cosign.pub <image>, or point --key at the KMS URI. Distribute public keys through configuration management or policy, not by downloading them from the same registry as the image.
Other useful checks
-a key=valuerequires annotations to be present and matching.--local-imageverifies an image saved to disk.--ca-rootsand--ca-intermediates, or--certificate-chain, support private certificate authorities (the docs note these options are mutually exclusive).SIGSTORE_ROOT_FILEpoints cosign at a custom root CA for private deployments.--check-claims=falseskips digest claim checks. Do not use it in production policy.
Cosign verifies the signature against the public key, the certificate against the Fulcio roots for keyless signatures, and the transparency log entry or its signed entry timestamp. The bundle format, which stores signature, certificate and log proof together, supports offline verification, which matters for disconnected clusters.
Enforcing signatures at admission with policy-controller
A verify step in CI protects only the paths that run it. Admission enforcement protects the cluster from anything deployed by any route, including a developer with kubectl or a compromised deployment tool. For the wider trade-offs, see Admission Control vs Runtime Security.
Opt namespaces in
By default the Sigstore policy-controller validates only namespaces labelled policy.sigstore.dev/include: "true":
kubectl label namespace payments policy.sigstore.dev/include=true
An opt-out model is possible by editing the matchExpressions in the validating and mutating webhook configurations to use the policy.sigstore.dev/exclude label instead. Opt-out is safer for mature estates because new namespaces are protected by default.
Write a ClusterImagePolicy
A ClusterImagePolicy contains:
spec.images: glob patterns matched against image references, for example your production registry path.spec.authorities: one or more ofkeyless(withurl,ca-certandidentities, each identity havingissuerandsubject, orissuerRegExpandsubjectRegExp),key(withdata,hashAlgorithm,secretRef.nameorkms) orstatic(passorfail).spec.mode: setwarnto admit non-compliant images with a warning. Without it, non-compliant images are blocked.spec.policy: optional CUE or Rego checks evaluated against attestations.
Evaluation logic matters when you design policies: every ClusterImagePolicy that matches an image must pass (AND), while within one policy any single authority passing is enough (OR). Adding a permissive authority to an existing policy therefore widens it; adding a second policy that matches the same images narrows it.
Decide what happens to unmatched images
The no-match-policy key in the config-policy-controller ConfigMap (in the cosign-system namespace by default) accepts warn, allow or deny. If it is not set, images that match no policy are rejected. Keep that default in production namespaces, and explicitly list approved third-party images with their own policy, for example verified against the publisher's identity, or with a static pass for a short, reviewed list.
The controller also resolves tags to digests so the image that runs is the one that was admitted. Even so, write deployment manifests with digests; it makes reviews and incident response simpler.
Protect the controller
The admission webhook is now a security boundary. Restrict who can edit ClusterImagePolicy objects, the webhook configurations, the namespace labels and the cosign-system namespace. Removing a namespace label silently switches enforcement off, so alert on label changes in protected namespaces.
Attestations, storage and registry housekeeping
Attestations let verification go beyond "who signed". Attach a predicate with cosign attest --type <type> --predicate <file> $IMAGE and check it with cosign verify-attestation, optionally with --policy. In the policy-controller, spec.policy can require, for example, that a provenance attestation names your build platform and source repository. The SLSA levels describe what provenance should contain at each maturity step.
Storage details that affect operations:
- Signatures use the OCI 1.1 referrers specification.
cosign tree $IMAGElists them andcosign clean $IMAGEremoves them, although some registries do not support deletion. - By default cosign stores signatures in the same repository as the image. The
COSIGN_REPOSITORYenvironment variable stores them elsewhere, which is useful when the image repository is read-only for the signer or when signatures for third-party images are kept internally. - For disconnected flows,
cosign sign --bundle=bundle.sigstore.json --upload=false $IMAGEwrites a bundle locally. The Sigstore docs suggest attaching it later withoras attach. - Image promotion between registries must copy referrers too, or verification will fail in the destination.
Registry permissions are part of the model. If the signing identity can also overwrite tags and delete signatures, an attacker with that identity can both push and sign. Separate push, sign and delete rights where your registry allows.
Rolling out signing across a platform
- Inventory signers. List every pipeline that builds production images and decide its signing method and identity.
- Sign everything first. Turn on signing for all builds before enforcing anything, and backfill signatures for currently deployed digests that you trust.
- Verify in CI. Add the production verification command to release pipelines.
- Deploy the policy-controller in warn mode. Collect warnings for two to four weeks (an NHI Mgmt Group recommendation) and fix unsigned or wrongly signed images.
- Enforce per namespace. Start with new or low-risk namespaces, then payments, identity and other crown-jewel workloads.
- Handle third-party images. Mirror them, verify publisher signatures where available, and re-sign with your own identity after review so policy has a single internal authority.
- Write a break-glass procedure. Define who can temporarily set
warnon a policy, how it is logged and how quickly it must be reverted.
Upgrades deserve attention too. The cosign README notes that the project supports the most recent release and the last v2 release, with future development based on sigstore-go, and that some errors arise when verifying signatures that need Rekor v2 support. Keep cosign versions aligned between signers and verifiers, including the controller.
Common failure patterns
- Verifying without identity pinning. Accepting any Fulcio-issued certificate means any GitHub or Google user can produce a passing signature.
- Loose regular expressions. Unanchored identity patterns that match other organisations' repositories.
- Signing tags. The tag moves between build and sign, and the signature covers a different image.
- Key files on runners.
cosign.keyand its password stored as CI secrets that every job can read. - Over-broad OIDC permission. Every workflow job, including pull request builds, can request an identity token the policy trusts.
- Namespaces never opted in. The controller is installed but most namespaces lack the include label.
- Permanent warn mode. Policies stay in
warnafter rollout and nobody reads the warnings. - Policy objects editable by deployers. Teams that deploy workloads can also relax the policy that governs them.
- Promotion drops signatures. Copying images between registries without their referrers, then disabling policy to get releases out.
Practitioner checklist
- Every production image is signed by digest in a release job, never by tag.
- Keyless verification pins both
--certificate-identityand--certificate-oidc-issuer, with any regular expressions anchored. - OIDC token permission is granted only to the signing job, on protected branches or release tags.
- Signing keys, where used, live in a KMS, Vault or OpenBao, with sign rights for one pipeline role and key administration held elsewhere.
- The policy-controller covers all production namespaces, ideally in opt-out mode, and
no-match-policyis not set toallowthere. - ClusterImagePolicy objects, webhook configurations and namespace labels are change-controlled and alerted on.
- Provenance attestations are attached and checked in policy for crown-jewel workloads.
- Image promotion copies signatures and attestations, and destination clusters verify them.
- Cosign and controller versions are kept aligned and tested before upgrades.
- A logged, time-limited break-glass process exists for policy exceptions.
Standards and references
- Sigstore: Signing containers with cosign
- Sigstore: Verifying signatures with cosign
- Sigstore: Cosign signing overview (keyless signing)
- Sigstore: Policy-controller overview
- sigstore/cosign README
- OpenSSF: SLSA v1.0 Security Levels
- NIST: SP 800-204D, Strategies for the Integration of Software Supply Chain Security in DevSecOps CI/CD Pipelines
- NIST: SP 800-53 Rev. 5 (CM-14 Signed Components, SR-4 Provenance, SR-11 Component Authenticity), and MITRE ATT&CK: Compromise Software Supply Chain (T1195.002)
Related NHI Mgmt Group resources: Sigstore Guide · Keyless vs Key-Based Code Signing · Code Signing vs Artifact Attestation · CI/CD Pipeline Identity Security Guide