Sub topic 13
Operational practices: key rotation, failure modes and troubleshooting
This chapter assumes you can sign and verify images with Cosign, in both key-based and keyless modes. It assumes you have seen the Rekor log and certificate identity checks, and that you know the CI and admission policy setup from earlier chapters. Here the focus is on keeping signing working over time and on diagnosing it when it fails.
Key rotation
Rotate a key pair when it is exposed, when a person with access leaves, or on a fixed schedule. Rotation has a cost. Old signatures stay valid only for verifiers that still trust the old public key.
A safe rotation follows these steps:
- Generate a new key pair, or create a new KMS key version.
- Distribute the new public key to every verifier: CI jobs, admission policies and developer machines.
- Run a period where verifiers accept both the old and new public keys.
- Re-sign images that must stay deployable, using the new key.
- Remove the old public key from verifiers.
# Generate the replacement pair
cosign generate-key-pair
# Re-sign an existing image by digest with the new key
cosign sign --key cosign.key "$IMAGE"
# Verify against the new public key
cosign verify --key cosign.pub "$IMAGE"Signing the same digest again adds a second signature. It does not change the image. If a key was compromised, removing trust in that public key is what protects you. A signature made with a leaked key cannot be told apart from a genuine one.
Keyless signing removes most of this work. Certificates last about ten minutes, so there is no long-lived private key to rotate. What you maintain instead is the list of trusted identities and issuers.
Failure modes
| Failure | Typical cause | What it means |
|---|---|---|
| `no signatures found` | Image was never signed, or you verified a different digest | Nothing is stored for that digest |
| `no matching signatures` | Wrong public key, or the signature was made by another key | A signature exists, but it does not verify |
| Identity or issuer mismatch | Verifying with the wrong `--certificate-identity` or `--certificate-oidc-issuer` | The signer is not who you expected |
| Tag verified, wrong image deployed | Verification used a mutable tag | The tag moved after the check |
| Signing step fails in CI | Missing `id-token: write` permission | The job cannot get an OIDC token |
| Rekor lookup errors | Network block, or the log is unreachable | Transparency log check cannot complete |
| Signature missing after a copy | Image was copied without its signature artifact | Signatures live as separate registry artifacts |
The last row catches many teams. A signature is stored next to the image in the same repository. When you mirror an image to another registry, copy the signature too.
# Copy the image together with its signature and attestations
cosign copy registry.example.com/team/app@sha256:<digest> \
mirror.example.com/team/appTroubleshooting steps
Start by confirming what is stored for the digest. Cosign can show the signature tree.
# List signatures, attestations and SBOMs attached to the image
cosign tree "$IMAGE"
# Inspect the certificate of a keyless signature to see the real identity
cosign verify \
--certificate-identity-regexp '.*' \
--certificate-oidc-issuer-regexp '.*' \
"$IMAGE" | headThe second command is a diagnostic only. It accepts any signer, so it shows who actually signed. Never use broad regular expressions in a deployed policy, because they accept signatures from anyone.
Other habits help:
- Pin cosign versions in CI so that flag changes do not break pipelines unexpectedly.
- Log the digest in every build so you can tie a deployed image back to a signing run.
- Keep private keys and KMS permissions limited to the signing job.
- Test verification in a pipeline stage before the deploy stage, so failures show up early.
- Alert on admission denials, since a sudden rise can mean either an attack or a broken signing job.
Exercise
A team mirrors an image to a second registry and then verification there fails with "no signatures found", though verification works in the source registry. What is the likely cause and the fix?
Show answer
The signature is a separate artifact in the source repository, and the mirror copied only the image. Copy the signature as well, for example with cosign copy, then verify the same digest again.
Exercise
Why does keyless signing reduce rotation work, and what must you still maintain?
Show answer
Keyless certificates are short-lived, so there is no long-lived private key to rotate or leak. You still maintain the trusted certificate identities and OIDC issuers used in verification and admission policies.