Course contentsShow
← Docker, Kubernetes & CI/CD
Lesson 616 of 8029. CI/CD Pipeline EngineeringFree lesson

Signing Images with Cosign for Integrity

Learners will use Cosign to digitally sign container images, enabling verification of origin and integrity before deployment within a Kubernetes cluster.

In this lesson, you will learn how to leverage Cosign to cryptographically sign container images, ensuring that the software running in your Kubernetes cluster is exactly what you built and hasn't been tampered with.

The Problem: Trust in the Registry

In a standard CI/CD pipeline, your registry acts as a source of truth. However, even if you secure your registry, an attacker might attempt to perform a "tag-mutating" attack or inject unauthorized images if they gain access. Verification of origin is critical: how does the Kubernetes cluster know that a specific image was truly pushed by your CI system and not by a malicious actor?

Signing with Cosign

Cosign, part of the Sigstore project, allows you to sign container images using a private key (or via Keyless signing with OIDC). When you sign an image, Cosign attaches a digital signature as a separate object in the container registry, associated with the image's digest.

To sign an image in your CI pipeline, you would execute:

cosign sign --key cosign.key my-registry.com/my-app@sha256:abcd1234...

The image itself remains unchanged (the layer hashes stay the same), but a new artifact is pushed to the registry containing the cryptographic proof of authenticity.

Verification at the Edge

Once the image is signed, you must enforce the check at the deployment stage. In Kubernetes, this is typically handled by an admission controller (like Policy Agent or Kyverno). The cluster intercepts the deployment request and uses Cosign to verify the signature against your public key before allowing the pod to start:

cosign verify --key cosign.pub my-registry.com/my-app@sha256:abcd1234...

If the signature is missing or the key doesn't match, the deployment is rejected. This creates a "secure chain of custody" from your build runner all the way to the production runtime. By incorporating this into your CI/CD pipeline, you move beyond simple registry authentication and into true supply-chain integrity, ensuring that only trusted, verified code executes in your environment.

Key Takeaway: Cosign signatures act as a digital seal on your container images, providing an immutable guarantee of provenance that can be enforced by Kubernetes to prevent unauthorized or malicious code execution.