Course contentsShow
← Docker, Kubernetes & CI/CD
Lesson 530 of 8028. Security and ObservabilityFree lesson

Signing Container Images with Cosign

Learners will cryptographically sign container images to ensure authenticity and integrity before they are deployed to the cluster.

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

The Problem: Trusting Your Supply Chain

When you pull an image like my-app:latest, how do you know it originated from your CI/CD pipeline and wasn't swapped by an attacker in the container registry? Just relying on tags is insufficient because tags can be overwritten. We need a way to verify the image's authenticity and integrity cryptographically.

The Solution: Cryptographic Signatures with Cosign

Cosign, part of the Sigstore project, allows you to sign container images using public-key cryptography. When you sign an image, Cosign generates a digital signature and stores it alongside your image in the registry as an associated object.

To sign an image, you first generate a key pair:

cosign generate-key-pair

Once you have your private key, you sign your image:

cosign sign --key cosign.key my-registry.com/my-app:v1.0.0

When your Kubernetes cluster (or a deployment tool) pulls this image, it can use the corresponding cosign.pub public key to verify that the signature is valid. If the signature doesn't match the image's content or if the signature is missing, the deployment can be rejected. This creates a "chain of custody" for your artifacts, ensuring that only images authorized by your private key ever make it into your production environment.

Why This Matters

By integrating Cosign into your CI/CD pipeline, you move away from trusting a registry to trusting the cryptographic signature attached to the image itself. This protects you against "Man-in-the-Middle" attacks or registry compromises, providing a foundational layer of security that ensures only verified, untampered images are executed by your runtime.

Key Takeaway: Signing images with Cosign provides a verifiable, tamper-proof audit trail that guarantees the integrity and origin of your container images before they are deployed to your cluster.