Marcio Cunha

Corrupted build? How to sign Docker images with Cosign

Learn how to protect your CI/CD pipeline against tampering by using Cosign to digitally sign Docker images and enforce immutable artifacts.

Marcio Cunha•3 min
Also available in:EspañolPortuguês
Summary
  • Digital container signing with Cosign ensures the provenance and integrity of software artifacts in production environments.
  • The use of cryptographic keys prevents tampered images from silently running on corporate infrastructure.
  • Automated pre-deploy validation blocks unverified software before it ever reaches the Kubernetes cluster.
  • Integrating this process into CI/CD turns security into an invisible yet impenetrable barrier.
  • Adopting immutable images streamlines compliance audits and drastically reduces supply chain breach risks.

The invisible danger hiding inside software containers

In modern software engineering, blindly trusting a container image coming straight out of an automation pipeline can be a fatal mistake. An attacker capable of compromising the code repository or the build server can inject malicious code without leaving obvious traces. In practice, this means the application reaching production might carry modified and completely unknown components that the development team never intended to ship.

To shield this critical phase, the industry now demands traceability and origin guarantees similar to physical tamper-evident seals. Build immutability stops being a mere architectural luxury and becomes an essential requirement for corporate survival, complementing strategies like optimizing CI/CD pipelines and container caches. Without a mathematical way to prove who built an image and when it was created, any infrastructure runs severe risks of silent breaches.

What is Cosign and how it works in practice

Built to simplify the signing, verification, and storage of OCI artifacts, Cosign is part of the Sigstore initiative and solves a historical problem of cryptographic complexity. Simply put, it acts as an automated digital notary that seals your software package with a unique cryptographic key. When a developer or an automated system generates an artifact, Cosign creates a digital signature directly tied to the image hash digest.

In practice, this means any minor change of a single byte inside the container instantly breaks the mathematical signature. Unlike legacy solutions that required complex management of certificates and expensive public key infrastructure, Cosign operates natively and integrates smoothly with popular registries. It supports both traditional private asymmetric keys and modern workflows based on open identities and short-lived tokens.

Implementing digital signatures in your CI/CD pipeline

To put this protection into action, the automation workflow must be adjusted to sign the image right after the packaging process finishes. This step takes place before pushing the package to the company's final container registry. The command below demonstrates how to sign an image using a key pair previously generated by the utility.

cosign sign --key cosign.private.key registry.company.internal/app/service:v1.2.3

This command reads the private key and generates a signature attached to the registry alongside the main image. If any failure happens mid-build, the automation halts immediately, preventing incomplete or corrupted artifacts from moving forward in the continuous delivery stream.

Pre-deploy validation in enterprise environments

Signing is useless if the target environment accepts running any software without checking the authenticity seal. Before releasing the container for execution in Kubernetes or virtual machines, the orchestrator must perform a rigorous check. This verification ensures that only approved artifacts signed by authorized teams are allowed to start.

The following command illustrates how to validate the image signature using the corresponding public key:

cosign verify --key cosign.pub registry.company.internal/app/service:v1.2.3

If the verification fails for any reason involving tampering or the absence of a valid signature, the deployment is aborted on the spot. This automated behavior shields production against human errors, process flaws, or targeted supply chain attacks. To complement this implementation in production environments, see our related technical analyses on AI hallucinating? How to build LlamaIndex guardrails and Node.js lagging? How to process heavy tasks without blocking the API.

Ensuring resilience and continuous compliance

Adopting digitally signed immutable artifacts raises the maturity level of any technology organization. Besides protecting against sophisticated intrusions, this approach simplifies regulatory audit processes by proving the exact lineage of every line of running code. By eliminating uncertainty about build integrity, teams gain speed and peace of mind to focus on delivering real value to users.