TExcelTAD
Home › Software Supply Chain Security: SBOM, SLSA & Sigstore › Field Notes: Keys, CI & Pinning

Field Notes: Keys, CI & Pinning

Signing is easy to switch on and easy to get wrong in ways that leave you with signatures nobody checks or keys anybody could use. These are the habits that make signing mean something.

1. Prefer keyless in CI; if you must hold keys, put them in a KMS

A private key in a CI secret is available to every step of every job that can read the secret, including a compromised dependency's install script. Keyless signing (Keyless Signing) removes the long-lived secret entirely: the job's OIDC identity is the credential, valid for minutes, and every use is in a public log. Where keyless isn't possible (air-gapped networks, identities you can't publish), use a KMS key (--key awskms://…, gcpkms://, azurekms://, hashivault://) so the key can sign but never be copied, and restrict the IAM permission to the release job.

2. Rotate keys with an overlap

Keys get rotated on a schedule, when people leave, and immediately when a leak is suspected. Verifiers must accept the old and new keys during a transition, and then stop accepting the old one. Because cosign stores several signatures per digest, you can sign with both:

bash · try it yourself
crane push /opt/samples/images/alpine-3.18.0.tar localhost:5000/shop/app:1.4.2 > /dev/null 2>&1
IMG=localhost:5000/shop/app@$(crane digest localhost:5000/shop/app:1.4.2)
SC=/opt/sigstore/offline-signing-config.json
COSIGN_PASSWORD=new-pass cosign generate-key-pair --output-key-prefix release-2027 > /dev/null 2>&1

# 1. overlap: the release job signs with the old and the new key
cosign sign --key /opt/keys/cosign.key --signing-config $SC "$IMG" > /dev/null 2>&1
COSIGN_PASSWORD=new-pass cosign sign --key release-2027.key --signing-config $SC "$IMG" > /dev/null 2>&1
v() { cosign verify --key "$1" --insecure-ignore-tlog "$IMG" > /dev/null 2>&1 && echo "verifies with $2" || echo "does NOT verify with $2"; }
v /opt/keys/cosign.pub "the old key"
v release-2027.pub "the new key"
echo "signatures stored: $(cosign tree "$IMG" 2> /dev/null | grep -c '🍒')"

# 2. verifiers switch to the new public key; 3. the old key is destroyed; the next release is signed with the new key only
printf 'release 1.4.3\n' > VERSION && tar --mtime=@$SOURCE_DATE_EPOCH --owner=0 --group=0 -cf layer.tar VERSION
crane append -b "$IMG" -f layer.tar -t localhost:5000/shop/app:1.4.3 > /dev/null 2>&1
IMG=localhost:5000/shop/app@$(crane digest localhost:5000/shop/app:1.4.3)
COSIGN_PASSWORD=new-pass cosign sign --key release-2027.key --signing-config $SC "$IMG" > /dev/null 2>&1
echo "--- 1.4.3"
v /opt/keys/cosign.pub "the old key"
v release-2027.pub "the new key"
verifies with the old key
verifies with the new key
signatures stored: 2
--- 1.4.3
does NOT verify with the old key
verifies with the new key

Release 1.4.2 carries two signatures and verifies with either key, so verifiers can switch whenever they're ready; 1.4.3, built after the rotation, verifies only with the new key.

What breaks rotation in practice is not cosign but distribution of the public key: if every cluster policy, script and README embeds the key, rotation becomes a project. Reference keys from one place (a KMS public-key endpoint, a config repository, a policy CRD), or use keyless identities, which don't need distributing at all.

3. Sign the digest you pushed, after the last copy

Sign IMG@sha256:… taken from your own push output, never a tag, and sign after the final push to the registry users pull from (or copy with referrers afterwards). Tools that rewrite manifests (format conversion, some mirroring setups) produce a different digest that your signature doesn't cover.

4. Verify where it matters, with an identity

A signature is checked by someone or it is decoration. For every artifact you sign, name the place that verifies it (an admission policy, a deploy script, a download page with instructions) and make that check require a specific key or identity: the release workflow at a release tag in your repository, not "any GitHub workflow", not .*. Test the negative case in CI: an unsigned image, or one signed by another workflow, must fail.

5. Pin actions by SHA, and give jobs least privilege

The CI system is part of the build platform. Third-party actions referenced by tag are mutable code running with your token and secrets (the tj-actions incident):

  • uses: owner/action@<40-hex SHA> # vX.Y.Z for every third-party action, kept current by Dependabot or Renovate;
  • permissions: {} at the top of each workflow, then only what each job needs (contents: read, id-token: write only in the signing job, packages: write only where you push);
  • no secrets in workflows triggered by pull_request_target on untrusted code;
  • separate the build job (runs untrusted dependency code) from the sign/publish job (holds the identity), passing only the artifact digest between them. This is the structure of SLSA Build L3 generators, and you can copy it.

6. Don't sign what you haven't checked

Signing after the gate, not before: build → SBOM → scan gate → sign and attest → push → verify. A signature on an image that failed its scan is a statement that you approved it. If you need to sign before scanning (for example to store the image), use a different identity or annotation for "built" vs "released" and let policies require the "released" one.

Test yourself

During a key rotation, what lets verifiers accept the old and new keys at the same time?

  1. Re-tagging the image
  2. Signing the digest with both keys; cosign stores several signatures per digest
  3. Deleting the old signature
  4. Using --insecure-ignore-tlog

Why separate the build job from the signing job in CI?

  1. Signing is slow
  2. The build runs untrusted dependency code; keeping the signing identity out of that job stops it from signing anything else
  3. GitHub requires two jobs
  4. To save cache space

Which permissions setting should a workflow start from?

  1. write-all
  2. permissions: {} (none), then grant per job
  3. read-all only
  4. Defaults are fine