Quick Start (5 min): Sign and Verify Your First Image
At 2:15 AM on a Tuesday, PagerDuty woke our on-call team to a critical alert: an AWS m5.2xlarge worker node had hit 100% CPU utilization. A rogue container disguised as an analytics worker was mining Monero and siphoning cluster bandwidth. During triage, we found the cause: an engineer had pushed an unverified debug build to our shared registry, overwriting a trusted release image. We had zero cryptographic proof of who built the binary or when it slipped into production.
Cosign, developed under the Linux Foundation’s Sigstore project, solves this exact problem. It attaches cryptographic signatures, SBOMs, and attestation metadata directly to container registries as standard OCI artifacts.
To try the workflow, grab the Cosign binary and generate a signing keypair:
# Install cosign on Linux (v2.4.1)
curl -LO https://github.com/sigstore/cosign/releases/download/v2.4.1/cosign-linux-amd64
sudo install cosign-linux-amd64 /usr/local/bin/cosign
# Generate a local keypair
cosign generate-key-pair
Enter a password when prompted for cosign.key. Cosign will generate two files on disk: your private key (cosign.key) and your public key (cosign.pub).
Next, authenticate to your container registry and sign a test image by its exact SHA256 digest:
# Log in to your container registry
docker login registry.example.com
# Sign the image digest
cosign sign --key cosign.key registry.example.com/apps/web-api@sha256:45b23d063f025e5b66b975d048408f6d72ebf8ab4f9fb5222ef45b40cf7c6d6d
Cosign pushes a signature payload to your registry without altering the underlying image layers. You can verify it immediately against your public key:
cosign verify --key cosign.pub registry.example.com/apps/web-api@sha256:45b23d063f025e5b66b975d048408f6d72ebf8ab4f9fb5222ef45b40cf7c6d6d
If the signature is valid, Cosign prints the verification claims JSON and exits with return code 0. If anyone swaps a binary layer or modifies the image bytes, the cryptographic verification fails immediately.
Deep Dive: How Sigstore and Cosign Work Under the Hood
Understanding why this blocks rogue workloads requires looking at how OCI registries store signatures during a cosign sign run.
OCI Artifacts and Detached Signatures
Legacy systems like Docker Content Trust (Notary v1) required standalone metadata servers, complex key hierarchies, and dedicated infrastructure. Cosign bypassed that complexity by storing signatures as standard OCI artifacts alongside the image.
For an image with the digest sha256:45b23d0..., Cosign uploads a detached signature tag named sha256-45b23d0...sig to the exact same repository. This design reuses your existing registry RBAC. If a compromised credential or unauthorized pipeline lacks push rights to that repository, it cannot write or overwrite signature tags.
Key-Based vs. Keyless Signing
Managing static private keys works fine for local testing. In enterprise environments, however, long-lived keys stored on disk inevitably leak into Git commits, CI logs, or developer laptops. Sigstore solves this with keyless signing, which relies on two core services:
- Fulcio: An ephemeral Certificate Authority. It issues short-lived X.509 certificates (valid for roughly 10 minutes) bound to an OpenID Connect (OIDC) identity, such as a GitHub Actions workflow or a Google Cloud service account.
- Rekor: A tamper-resistant, append-only transparency log. Rekor records every signed claim and certificate in a public, searchable ledger inspired by Certificate Transparency logs.
During a CI/CD run, Cosign requests an OIDC token from the build runner, exchanges it for a short-lived cert from Fulcio, and signs the image digest in memory. It then registers the entry in Rekor and discards the private key. Attackers have no static private keys to target. This same identity-based trust model is also gaining traction across developer workflows, such as keyless Git commit signing with Gitsign and Sigstore to verify code author authenticity.
Advanced Usage: Enforcing Signatures in Kubernetes with Kyverno
Signing images in CI/CD is only step one. If someone with cluster access runs kubectl run rogue --image=evil/miner:latest, Kubernetes pulls and runs the pod anyway. You need an admission controller at the cluster gate. To build a defense-in-depth posture alongside admission control, teams often pair proactive gating with runtime behavioral monitoring like deploying Falco on Kubernetes for real-time intrusion detection.
1. Deploy the Kyverno Admission Controller
# Add the Helm repository and install Kyverno v1.12+
helm repo add kyverno https://kyverno.github.io/kyverno/
helm repo update
helm install kyverno kyverno/kyverno -n kyverno --create-namespace
2. Create a ClusterPolicy to Verify Signatures
Save this manifest as verify-image-policy.yaml. The admission webhook intercepts every Pod creation request in the production namespace and validates its signature before admission:
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: verify-cosign-image
spec:
validationFailureAction: Enforce
background: false
rules:
- name: check-image-signature
match:
any:
- resources:
namespaces:
- production
kinds:
- Pod
verifyImages:
- imageReferences:
- "registry.example.com/apps/*"
key: |-
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE7p9N2t58H1g8x7gWJ0bTqW6gK...
-----END PUBLIC KEY-----
mutateDigest: true
required: true
Apply the manifest to your cluster:
kubectl apply -f verify-image-policy.yaml
3. Test Policy Enforcement
Spin up an unsigned container inside the protected namespace to test the boundary:
kubectl run test-fail --image=registry.example.com/apps/unverified-worker:v1.0 -n production
The Kyverno webhook catches the unsigned image and rejects the request immediately:
Error from server: admission webhook "mutate.kyverno.svc-fail" denied the request:
policy ClusterPolicy/verify-cosign-image: rule check-image-signature failed:
image registry.example.com/apps/unverified-worker:v1.0 failed signature verification
Notice the mutateDigest: true setting in our policy. Kyverno resolves mutable tags like :v1.0 into their immutable @sha256:... digests before writing the pod specification to etcd. This closes the window on tag-mutability attacks.
Practical Tips for Stable Production Deployments
Enforcing strict cryptographic boundaries across dozens of production services takes deliberate planning. A few best practices keep builds green and clusters secure.
Always Sign Digests, Never Mutable Tags
Tags such as :latest or :v1.4.2 are easily overwritten. An attacker with compromised credentials can re-tag a vulnerable binary without triggering a build alert. Always pin and sign the exact SHA256 digest:
# Extract the immutable repo digest from your local build
IMAGE_DIGEST=$(docker inspect --format='{{index .RepoDigests 0}}' registry.example.com/apps/web-api:1.4.2)
# Sign the digest directly
cosign sign --key cosign.key "${IMAGE_DIGEST}"
Sign and Attach SBOMs Directly to Images
Cosign does more than sign container layers. It can attach vulnerability scans and Software Bills of Materials (SBOMs) to the image manifest. You can learn more about integrating these components into automation pipelines in our guide to securing the software supply chain with SBOM using Syft and Grype:
# Generate an SPDX SBOM with Syft
syft registry.example.com/apps/web-api:1.4.2 -o spdx-json=sbom.spdx.json
# Attach and sign the SBOM artifact
cosign attach sbom --sbom sbom.spdx.json registry.example.com/apps/web-api:1.4.2
cosign sign --key cosign.key --attachment sbom registry.example.com/apps/web-api:1.4.2
Roll Out in Audit Mode First
Keep your admission controller in validationFailureAction: Audit for at least 14 days before switching to Enforce. Use this burn-in period to review Kyverno policy reports in Grafana or Datadog. You will often discover third-party telemetry sidecars, log shippers, or older cron jobs that engineers forgot to include in the signing pipeline.

