Lab: keyless signing and provenance in CI
Implement Sigstore keyless cryptographic signing with Cosign in continuous integration pipelines, attach in-toto provenance attestations, and verify signatures against the Rekor transparency log.
Contentsand lesson path
On this page
- The Sigstore Ecosystem: Eliminating Long-Lived Private Signing Keys
- OIDC Identity Claims, Cosign Verification, and In-Toto Attestations
- Lab Execution: Keyless Cosign Signing, Attestation, and Verification
- Check your understanding
- Apply it
- Review prompt
Lessons of Supply Chain Security
- How build pipelines get attacked Concept · 20 min
- SLSA in practice: hardened builds and provenance Concept · 20 min
- Lab: SBOMs and a vulnerability triage policy Lab · 25 min
- Lab: keyless signing and provenance in CI Lab · 25 min
- Enforcing trust at the cluster door Worked example · 20 min
- Check: supply-chain audit of a sample pipeline Knowledge check · 6 questions
What you will learn
- Sign images and attach build provenance with Sigstore cosign in CI, then verify signatures and attestations before deployment with an admission policy.
01. The Sigstore Ecosystem: Eliminating Long-Lived Private Signing Keys
Traditional digital signing of software artifacts historically depended on long-lived cryptographic key pairs (such as PGP/GPG keys or enterprise private keys). In continuous integration environments, storing a private signing key as an encrypted repository secret or injecting it into build runners causes several problems: keys rarely expire, they are vulnerable to exfiltration by compromised dependencies, revocation is cumbersome, and if a key is stolen, an attacker can sign trojanized binaries until someone notices and revokes it.
The Sigstore project (an OpenSSF project) offers keyless signing instead. In keyless signing, no long-lived private signing key is stored, managed or rotated by your team: each signature uses a fresh key that exists only for that signing. Sigstore combines three open-source services and tools:
-
Fulcio (Ephemeral Public Key Infrastructure): A root Certificate Authority (CA) that issues short-lived X.509 digital certificates (valid for ten minutes). Fulcio issues a certificate only after it has validated an OpenID Connect (OIDC) identity token from a supported identity provider: a CI system such as GitHub Actions, GitLab CI or Google Cloud Build, or a user account such as Google, Microsoft or GitHub when a person signs from a laptop. The certificate records that identity, which is what verifiers check later.
-
Rekor (Immutable Transparency Log): A tamper-evident, append-only ledger backed by a cryptographic Merkle tree (similar to Certificate Transparency logs in TLS). Each signature, certificate and attestation is recorded in Rekor with the time it was logged. Rekor signs checkpoints of the tree and issues inclusion proofs, which show that an entry is in the log without reading all earlier entries.
-
Cosign (Developer and CLI Tooling): The client utility used by build pipelines and Kubernetes controllers to sign container images, attach in-toto provenance attestations, and verify signatures prior to deployment.
02. OIDC Identity Claims, Cosign Verification, and In-Toto Attestations
A keyless signature is only as secure as the identity policy enforced during verification. When Fulcio generates a certificate for a GitHub Actions workflow, it embeds rich identity claims directly into custom X.509 certificate extensions using registered Object Identifiers (OIDs):
- OIDC Issuer (
--certificate-oidc-issuer): Identifies the token authority (https://token.actions.githubusercontent.com). - Certificate Identity (
--certificate-identityor--certificate-identity-regexp): Records the specific repository, workflow file, and Git reference that requested the token (e.g.https://github.com/corp/payments/.github/workflows/release.yaml@refs/heads/main). - Repository and Ref Claims: Fulcio embeds custom OIDs recording the Git commit SHA, event name (push, release), and runner environment, so a verifier can check the build context too.
A critical verification anti-pattern is configuring cosign verify with an unpinned identity regular expression (such as .*). Because anyone in the world can create a public GitHub repository and receive a valid Fulcio certificate from GitHub's OIDC provider, verifying only the issuer without pinning the exact repository identity lets workflows in anyone's repository pass your verification gate.
Beyond signing raw container digests, Cosign enables pipelines to attach in-toto provenance attestations using the cosign attest command. Where cosign stores them depends on its version. Cosign 2 pushed signatures and attestations as extra tags named after the image digest (sha256-<digest>.sig and sha256-<digest>.att). Cosign 3 uses the new Sigstore bundle format by default and attaches it to the image through the OCI 1.1 referrers mechanism, with no extra tags; cosign tree shows both layouts. Check that your registry supports referrers (or its tag-based fallback) before you rely on it. GitHub's actions/attest also stores its attestations as Sigstore bundles, in GitHub's attestation API and optionally in the registry.
name: release
on:
push:
tags: ["v*"]
permissions:
contents: read
jobs:
build-sign-attest:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write # push the image and its signature to GHCR
id-token: write # OIDC token for the Fulcio certificate
attestations: write # store the provenance attestation
env:
IMAGE: ghcr.io/${{ github.repository }} # e.g. ghcr.io/<owner>/payments
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
id: build
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: .
push: true
tags: ${{ env.IMAGE }}:${{ github.ref_name }}
# cosign-installer v4.1.4 installs cosign v3.1.5.
# Split only to fit this page. In double quotes, a trailing `\` drops the
# line break and the next line's leading spaces; without it YAML puts a
# space after "@" and the ref breaks. In a real workflow keep the value
# and its tag comment on one line, so Dependabot and Renovate update both.
- uses: "sigstore/cosign-installer@\
881c63bd87e38389154debd8331404ce7ca8a3ab" # v4.1.4
- name: Sign the image digest (keyless)
env:
DIGEST: ${{ steps.build.outputs.digest }}
run: cosign sign --yes "${IMAGE}@${DIGEST}"
- name: Attest SLSA build provenance and push it to the registry
uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2
with:
subject-name: ${{ env.IMAGE }}
subject-digest: ${{ steps.build.outputs.digest }}
push-to-registry: true
create-storage-record: false # storage records need an organisation03. Lab Execution: Keyless Cosign Signing, Attestation, and Verification
The lab has two parts. In part A you sign and attest your own image in a public GitHub repository; in part B you practise verification against images that real projects have already signed, so you can see both passing and failing checks today.
Part A: sign and attest your own image. Create a public repository named payments with a Dockerfile (any small image will do), add the workflow above as .github/workflows/release.yaml, and push a tag such as v1.2.0. The job logs in to GHCR with the job's GITHUB_TOKEN, builds and pushes the image (the build step's digest output is what everything else uses), signs that digest keylessly with cosign, and creates a SLSA provenance attestation with actions/attest, pushed to the registry next to the image. Artifact attestations work on public repositories on every GitHub plan; private repositories need GitHub Enterprise Cloud. Then verify it from your machine with cosign 3.x and the GitHub CLI.
The identity check is the whole point. For a GitHub Actions certificate, the identity is the workflow file and the ref that ran it, for example https://github.com/<owner>/payments/.github/workflows/release.yaml@refs/tags/v1.2.0. Pin the repository, the workflow file and the kind of ref. A regex such as ^https://github.com/org/ accepts a signature from any workflow, in any repository of the organisation, on any branch, tag or pull-request ref, which is barely better than no check.
OWNER=<your-github-user>
IMAGE=ghcr.io/$OWNER/payments
DIGEST=sha256:<digest printed by the build step>
ID_RE='^https://github\.com/'"$OWNER"'/payments/\.github/workflows/release\.yaml'
ID_RE+='@refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$'
cosign verify "$IMAGE@$DIGEST" \
--certificate-oidc-issuer https://token.actions.githubusercontent.com \
--certificate-identity-regexp "$ID_RE"
gh attestation verify "oci://$IMAGE@$DIGEST" --repo "$OWNER/payments" \
--signer-workflow "$OWNER/payments/.github/workflows/release.yaml"Part B: verify images that are already signed. Install cosign 3.x and jq. The first script checks a Trivy release image: with the exact identity of its release workflow, with the identity of a different workflow file in the same repository (rejected, and cosign shows the identity it actually found), and with an organisation-wide regex, which also passes and is the trap described above.
ISSUER=https://token.actions.githubusercontent.com
DIGEST=sha256:790fd66d1697395d8693d1acaa1ea702406a20f109b6fc7bac8db623eca6c06c
REF="ghcr.io/aquasecurity/trivy@$DIGEST"
WF=https://github.com/aquasecurity/trivy/.github/workflows
# 1. exact identity of the release workflow at the release tag
cosign verify "$REF" --certificate-oidc-issuer "$ISSUER" \
--certificate-identity "$WF/reusable-release.yaml@refs/tags/v0.76.1" >/dev/null 2>&1
echo "exact identity: exit $?"
# 2. negative: a different workflow file in the same repository
cosign verify "$REF" --certificate-oidc-issuer "$ISSUER" \
--certificate-identity "$WF/release.yaml@refs/tags/v0.76.1" 2>&1 >/dev/null \
| grep -o 'got "[^"]*"' | head -1 | fold -w 80
# 3. the loose org-wide regex also passes: it would pass for ANY workflow, branch
# or pull request in ANY repository of the organisation
cosign verify "$REF" --certificate-oidc-issuer "$ISSUER" \
--certificate-identity-regexp '^https://github.com/aquasecurity/' >/dev/null 2>&1
echo "org-wide regex: exit $?"exact identity: exit 0
got "https://github.com/aquasecurity/trivy/.github/workflows/reusable-release.ya
ml@refs/tags/v0.76.1"
org-wide regex: exit 0The second script verifies a provenance attestation, which is what an admission policy should also require. Kyverno's release images carry SLSA provenance produced by the SLSA GitHub generator, so the certificate identity is the generator's reusable workflow, and the repository that ran it is a separate certificate claim, checked with --certificate-github-workflow-repository. The script prints where the build came from, then shows that the same check for another repository fails.
ISSUER=https://token.actions.githubusercontent.com
DIGEST=sha256:c8c4dd09e720d2cd7fd24ca73ac28e46651001372f988e0cba3f2f612f04b955
KREF="ghcr.io/kyverno/kyverno@$DIGEST"
GEN=https://github.com/slsa-framework/slsa-github-generator/.github/workflows
# 4. provenance: signed by the trusted SLSA generator, run for kyverno/kyverno
cosign verify-attestation "$KREF" --type slsaprovenance \
--certificate-oidc-issuer "$ISSUER" \
--certificate-identity "$GEN/generator_container_slsa3.yml@refs/tags/v2.1.0" \
--certificate-github-workflow-repository kyverno/kyverno 2>/dev/null \
| head -1 | jq -r '.payload' | base64 -d \
| jq -r '.predicate.invocation.configSource | .uri, .entryPoint'
# 5. negative: the same check for a different repository
cosign verify-attestation "$KREF" --type slsaprovenance \
--certificate-oidc-issuer "$ISSUER" \
--certificate-identity "$GEN/generator_container_slsa3.yml@refs/tags/v2.1.0" \
--certificate-github-workflow-repository attacker/kyverno >/dev/null 2>&1
echo "wrong repository: exit $?"git+https://github.com/kyverno/kyverno@refs/tags/v1.19.2
.github/workflows/release.yaml
wrong repository: exit 1Run cosign tree on both images to see where the material lives. The Trivy image lists its signatures as "artifacts via OCI referrer", which is how cosign 3 stores a Sigstore bundle; the Kyverno image lists a sha256-<digest>.att tag, the older layout. Because the bundle carries the certificate and the Rekor inclusion proof, cosign reports that the transparency-log entry "was verified offline".
04. Check your understanding
05. Apply it
Implement these Sigstore keyless signing and provenance practices across your CI/CD delivery pipelines:
- Transition to Keyless Signing: Eliminate static long-lived private keys in CI by adopting Cosign with GitHub Actions OIDC identity tokens.
- Pin Certificate Identities: Always verify both
--certificate-oidc-issuerand an exact--certificate-identity(or a regex anchored to one repository, one workflow file and release tags), never an organisation-wide prefix. - Attach and Verify SLSA Provenance: Attach provenance to the image digest (
actions/attest, the SLSA generator orcosign attest) and verify it before deployment withcosign verify-attestationorgh attestation verify. - Verify Rekor Inclusion Proofs: Ensure verification policies validate that signatures exist in the public Rekor transparency log.
- Plan for Offline Verification: Sigstore bundles carry the certificate and the Rekor inclusion proof, so verification can check log inclusion without calling Rekor; the verifier still needs the Sigstore trusted root, so distribute it to air-gapped tiers.
- Audit Fulcio OID Claims: Review parsed X.509 certificate extensions in pipeline audit logs to ensure Git reference and commit SHA hashes match expected release tags.
- Automate Admission Verification: Integrate Sigstore Policy Controller or Kyverno in staging clusters to block unsigned images before production rollout.
- Restrict Workflow Permissions: Declare
permissions: id-token: writestrictly on dedicated signing jobs to follow least-privilege principles.
06. Review prompt
Explain the collaborative roles of Fulcio, Rekor, and Cosign in enabling keyless cryptographic artifact signing without persistent private keys. Describe how the Rekor transparency log resolves the problem of verifying signatures after ephemeral X.509 certificates expire, and explain why failing to strictly pin certificate identity regular expressions allows arbitrary external CI workflows to compromise verification gates.
References
- Sigstore documentation
- SLSA: Supply-chain Levels for Software Artifacts
- in-toto: A framework to secure software supply chains
- Sigstore Docs: Verifying signatures (cosign)
- Sigstore Docs: Verifying in-toto attestations
- Sigstore blog: Cosign 3.0 available
- actions/attest
- GitHub CLI manual: gh attestation verify
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
6 questions · about 5 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.