Sub topic 1
Why sign images: the trust problem in the container supply chain
Prerequisites
This chapter assumes you can do the following:
- Build, tag, push and pull container images.
- Use a registry such as GHCR, Docker Hub or ECR.
- Work in a terminal.
- Explain a key pair and a digital signature in one sentence.
- Read a basic CI pipeline, such as a GitHub Actions workflow.
No Cosign commands appear in this chapter. It explains the problem that the later chapters solve.
What you trust when you pull an image
When you run docker pull registry.example.com/team/app:1.0.0, you trust several things at once:
- The registry returned the content the publisher pushed.
- The publisher's account and build system were not compromised.
- The network did not alter the data in transit.
- The name you typed refers to the image you intended.
TLS protects the connection. It does not tell you who built the image or whether the registry now holds something different from what the publisher intended. Your deployment then runs that content with whatever privileges the container has.
Where the chain can break
An image passes through several stages. An attacker needs to compromise only one of them.
| Stage | Example attack | Why it works without signatures |
|---|---|---|
| Registry | An attacker with stolen push credentials overwrites `app:1.0.0` | The tag is the same, so nothing looks different |
| Build | A compromised runner injects a backdoor | The registry accepts any image from an authorized pusher |
| Naming | A typo-squatted image such as `team/appp` is pulled | The cluster has no record of which images are approved |
| Mirror or cache | A proxy serves modified layers | The consumer cannot check who produced them |
In each case the pull succeeds and the deployment looks normal.
What a signature proves
A digital signature is created with a private key and checked with the matching public key or certificate. For an image, a verified signature tells you two things:
- Integrity. The content you are about to run is the same content that was signed. Changing even one byte of the image breaks verification.
- Origin. The signature came from a specific key or identity that you chose to trust.
A signature binds an identity to specific content. Later chapters show how Cosign records this in the registry and how you check it.
What a signature does not prove
Signing is often oversold, so be clear about its limits:
- It does not prove the image is free of vulnerabilities. A signed image can contain an outdated library.
- It does not prove the code is benign. A trusted signer can sign bad code, and a compromised build system can sign it automatically.
- It does not help if nobody verifies. A signature that no one checks changes nothing.
- It only helps if you trust the right signer. Verifying "signed by anyone" is almost useless.
The shape of the solution
Signing and verifying involve three parts:
- Sign at build time. The signer produces a signature over the image's content.
- Store the signature next to the image in the registry, so it travels with it.
- Verify before use. Verification can be a manual command, a CI step or an automatic check in the cluster that rejects unsigned images.
Sigstore is an open-source project that provides tooling for this workflow. Cosign is its command-line tool for container images. The rest of the tutorial covers how each part works. Two questions come first. What exactly does a signature refer to? Why is a tag not a safe answer?
Exercise
A team's registry is breached. The attacker pushes a malicious image over the existing tag app:1.0.0. The team had signed the original image. Describe two things that must be true for signature verification to protect the cluster, and one thing it still would not protect against.
Show answer
First, the cluster (or deploy process) must actually verify signatures before running the image, and it must reject images that fail. Second, it must verify against the expected signer's key or identity, not accept any valid signature. The malicious image has no valid signature from the trusted signer, so verification fails. Verification would not protect against a vulnerability or backdoor in the original image that the trusted team signed, or against a compromised build system that signs malicious content with the legitimate identity.