Sign everything, and plan for the day the key leaks
Commit, artifact and image signing is easy to switch on. Key custody and rotation are where teams get burned.
Turning on signing takes an afternoon. Deciding what happens when a signing key is compromised takes a lot more thought, and most teams skip it. Then the key leaks, and they learn that every verifier in the fleet trusts it, nobody knows where the copies are, and revoking it breaks production.
Three keys, three jobs
- Commit signing proves who wrote the change. Each engineer holds their own key, ideally on a hardware token, and the server rejects unsigned pushes to protected branches.
- Artifact signing proves the release came from your release process. That key never lives in a CI variable.
- Image signing proves what’s allowed to run. Admission control in the cluster rejects anything unsigned or signed by the wrong identity.
Mixing these up is the first mistake. If the key that signs container images is also an engineer’s personal key, a stolen laptop becomes a way to deploy anything.
Commit signing on a hardware token
Git can sign with SSH keys, and an SSH key generated on a FIDO2 token never leaves the token. That removes the most common leak, a private key copied off a laptop.
ssh-keygen -t ed25519-sk -O resident -C "kyle signing"
git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/id_ed25519_sk.pub
git config --global commit.gpgsign true
git config --global tag.gpgsign true
Each signature needs a touch on the token, so malware on the workstation can’t sign quietly in the background. On the server side, GitLab’s push rules can reject unsigned commits, and branch protection keeps anyone from rewriting history on the branches that matter. To check signatures locally, point gpg.ssh.allowedSignersFile at a file listing each engineer’s email and public key, then run git log --show-signature.
The allowed signers file is itself a trust list. Keep it in a repository that needs review to change, or a departing engineer’s key stays trusted forever.
Where the release key lives
The release key belongs in an HSM or a cloud KMS, with signing done by a call to that service. The pipeline gets permission to request a signature for one job on one protected branch. It never gets the key material. If a runner is compromised, the attacker can request signatures while they hold the runner, which is bad, but they can’t walk away with the key and sign things for the next year.
Cosign supports KMS keys directly. With AWS KMS, including GovCloud regions, it looks like this:
# one time, by a key administrator, not by the pipeline
cosign generate-key-pair --kms awskms:///alias/release-signing
# in the release job, by digest, never by tag
cosign sign --yes --key awskms:///alias/release-signing "$IMAGE@$DIGEST"
The IAM policy for the pipeline role grants kms:Sign, kms:GetPublicKey and kms:DescribeKey on that one key. Nobody gets kms:ScheduleKeyDeletion or key policy changes except a small break-glass group, and those calls alert.
Sign the digest, always. A tag is a pointer that anyone with push rights can move. A signature on app:1.4.0 tells a verifier nothing if 1.4.0 points somewhere else tomorrow.
Keyless signing with Sigstore
Keyless signing goes a step further. The signer proves an identity through OIDC, Fulcio issues a certificate that lives for minutes, and the signature is recorded in the Rekor transparency log. There’s no long-lived key to leak, and the log gives you a record of every signature made under your identity.
In GitLab CI, the job asks for an ID token with the sigstore audience and cosign picks it up from the environment:
sign-image:
stage: release
image: "$CI_REGISTRY/platform/tools/cosign:2" # internal image with a pinned cosign
id_tokens:
SIGSTORE_ID_TOKEN:
aud: sigstore
script:
- cosign sign --yes "$CI_REGISTRY_IMAGE@$IMAGE_DIGEST"
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
Verifiers then check who signed, so write those identity rules carefully. On GitLab.com the certificate identity is the pipeline definition at a specific ref:
cosign verify "$CI_REGISTRY_IMAGE@$IMAGE_DIGEST" \
--certificate-oidc-issuer "https://gitlab.com" \
--certificate-identity "https://gitlab.com/my-group/my-project//.gitlab-ci.yml@refs/heads/main"
The mistake I see most often is a regular expression that accepts any project in the group, or anything at all. That turns “signed by our release pipeline” into “signed by anyone who can create a project.” Match the exact project, file and branch.
Public Fulcio and Rekor aren’t always an option. In an air-gapped or restricted environment you either run a private Sigstore stack or fall back to KMS keys with a timestamp authority you control. Either is fine. What matters is deciding before the first release, not after.
Enforce it at admission
A signature nobody checks is decoration. In Kubernetes, the admission controller is where verification has teeth. A Kyverno policy for the keyless identity above looks like this:
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: require-release-signature
spec:
validationFailureAction: Enforce
webhookTimeoutSeconds: 30
rules:
- name: verify-release-signature
match:
any:
- resources:
kinds: [Pod]
verifyImages:
- imageReferences:
- "registry.gitlab.com/my-group/my-project*"
mutateDigest: true
attestors:
- entries:
- keyless:
issuer: "https://gitlab.com"
subject: "https://gitlab.com/my-group/my-project//.gitlab-ci.yml@refs/heads/main"
rekor:
url: https://rekor.sigstore.dev
Kyverno’s schema shifts between releases, so check field names against the version you run. Start in Audit mode for a week, read what it would have blocked, then switch to Enforce. The mutateDigest setting rewrites tags to digests at admission, which closes the moving-tag gap on the cluster side.
The rotation drill
Write down, before you need it:
- Who can revoke each key, and how long it takes.
- Which verifiers need the new public key or identity rule, and how it gets to them.
- Which already-signed artifacts must be re-signed or pulled.
- How you will tell signatures made before the compromise from those made after.
The fourth point is why timestamps matter. If signatures carry a trusted timestamp, or sit in a transparency log, you can keep trusting artifacts signed before the compromise window and reject the rest. Without them, a leaked key means distrusting everything it ever signed.
Then run the drill once. You’ll find the verifier that has the old key baked into an image nobody owns. Better to find it during a drill than during an incident.
How it goes wrong
- The private key is a CI variable. Masked, protected and still readable by any job on a protected branch. Move it to KMS or go keyless.
- Signing happens before the push. The digest you signed isn’t the digest in the registry, so verification fails and someone disables it “for now.”
- Verification fails open. The admission webhook times out, the failure policy is
Ignore, and unsigned images run whenever the cluster is busy. - One identity signs everything. Dev, test and release builds share an identity, so a test build passes production admission.
Signals worth alerting on
- A signature in the transparency log under your identity that no pipeline run produced. Rekor is searchable, so this can be a scheduled job.
- A signing request from a branch or job that isn’t on the allow list.
- Admission control rejecting images in a namespace that has never seen a rejection.
- Any change to a signing key’s policy or deletion schedule.
Where this lands in the standards
NIST SP 800-218 PS.2.1 asks you to make software integrity verification information available to the people who acquire your software, and PS.1.1 asks you to store code with least-privilege access. NIST SP 800-57 Part 1 covers how long a key should live and how to retire it. NIST SP 800-204D, on supply chain security in CI/CD pipelines, treats signed artifacts and attestations as core pipeline outputs, and SLSA’s build track describes the provenance a verifier can check. The DoD Container Hardening Guide expects images to be signed and verified before they run.
Signing satisfies the first sentence of each. The rotation drill is what makes it hold up on a bad day.
Want your signing chain checked?
Commit signing, release keys, image signing and admission policy are all in scope for a pipeline security review. I map who can sign what, where each key lives, and what a verifier actually checks. If you aren’t sure that’s the right starting point, book a free 30-minute fit call.