Sub topic 1
Why Sign Images: The Trust Problem in the Container Supply Chain
A container image is a bundle of code that your cluster will run with real privileges. Before you run it, you should be able to answer two questions. Did this image come from the party I think it came from? Is it byte-for-byte what that party published? A registry alone cannot answer either question. Image signing exists to answer both, and this chapter explains why.
Prerequisites
This chapter assumes you already have the following:
- You can build, tag, push, and pull container images with Docker or another OCI-compatible tool.
- You have used a container registry such as GHCR, Docker Hub, or Amazon ECR.
- You are comfortable in a shell.
- You know what a public/private key pair is, and that a signature made with a private key can be checked with the matching public key.
- You have a rough idea of how a CI pipeline such as GitHub Actions builds and publishes artifacts.
You do not need to have installed Cosign yet. This chapter has no required hands-on steps. It builds the mental model that the rest of the tutorial relies on.
The path an image takes
An image passes through several systems between a developer's commit and a running container. Each hop is a place where trust is assumed.
Every dotted arrow is a real class of incident. Signing does not remove all of them. It lets you detect the ones that happen after the build step, and it lets you tie an image to the build that produced it.
Where trust can break
The table lists the main ways an image can end up in your cluster without being what you expected.
| Risk | How it happens | Does signing help? |
|---|---|---|
| Registry compromise | An attacker gets push access, through a leaked token or a misconfigured permission, and replaces an image. | Yes. The replacement has no valid signature from your signer. |
| Tag overwrite | Someone, or a buggy pipeline, pushes a different image to an existing tag such as `1.0.0` or `latest`. | Yes, if you verify by digest and the new content is unsigned. |
| Man-in-the-middle or mirror tampering | An image is altered in a proxy, a mirror, or a pull-through cache. | Yes. The content no longer matches what was signed. |
| Typosquatting and look-alike repositories | You pull `team/app` from the wrong namespace or a similar-looking name. | Partly. Verification fails unless the signer identity matches the one you expect. |
| Compromised build system | The build runner is hijacked and builds a backdoored image. | Only partly. The image is correctly signed, but by a compromised signer. |
| Malicious source code | A bad commit is built and signed normally. | No. Signing proves origin, not intent. |
| Vulnerable dependency | A library inside the image has a known flaw. | No. Scanning and SBOMs address this. |
Read the last three rows carefully. A signature is a statement about who produced an artifact and whether it has changed. It is not a statement that the artifact is safe.
What a registry does and does not guarantee
A registry stores image content and serves it back. When you push, the registry computes a content digest, a SHA-256 hash of the image manifest. Clients can use that digest to confirm that the bytes they received match the bytes they asked for.
That check protects the transfer. It does not tell you who pushed the image. Anyone with push rights can upload a valid image under any tag. The pull will succeed, the digest check will pass, and the image will still be the wrong one.
This is the central gap. Transport security (TLS) and digest checks tell you the bytes arrived intact. They say nothing about whether the right party created those bytes. The next chapter covers the difference between tags and digests in detail. For now, remember that a tag is a name someone can reassign, so a tag by itself is not an identity for any particular content.
What signing proves
A digital signature binds three things together:
- The content. The signature covers a specific digest. If the image changes by one byte, the digest changes and the signature no longer matches.
- The signer. Verification uses a public key, or a certificate tied to an identity. Only the holder of the matching private key, or the holder of that identity, could have produced the signature.
- The signing act. In Sigstore's keyless mode, a public log can also record that the signature was created at a certain time. Later chapters cover this.
When verification succeeds, you can state something specific: "This exact image content was signed by this key or identity." That is much stronger than "this tag currently points at something."
What the signer is vouching for
The signer is saying "I produced this" or "I approve this for release." What that means depends on who the signer is:
- If a developer signs from a laptop, the signature says that developer approved the artifact.
- If your CI workflow signs, the signature says the artifact came out of that workflow, for example a specific pipeline on a specific branch.
- If a release team signs after testing, the signature says the artifact passed their gate.
You choose the meaning by deciding who or what is allowed to sign. Verification is only as meaningful as the signer identity you check for.
What signing does not prove
Be precise about the limits, because overclaiming is the most common mistake teams make with signing.
Signing also does not do the following:
- It does not stop an unsigned image from being pulled. Signing only produces evidence. Something must check that evidence, either a person running a verify command or an automated policy at deploy time. An image that nobody verifies is no safer than an unsigned one.
- It does not hide the image. Signatures are not encryption.
- It does not replace scanning, code review, or least-privilege access to the registry. It adds a layer to them.
Signing in the larger picture
Container supply chain security is usually described as a set of questions you can ask about an artifact. Signing answers the first two directly.
- Integrity: Is this the same content that was published? A signature over the digest answers this.
- Provenance: Who or what built it, from which source, in which pipeline? A signer identity gives a partial answer. Signed attestations, covered later, give a fuller one.
- Content: What is inside it? An SBOM (software bill of materials) lists the components, and a signed SBOM lets you trust that list.
- Policy: Is this artifact allowed to run here? An admission policy checks the previous answers automatically before a workload starts.
The rest of this tutorial follows that order. You will learn to sign and verify, then to prove identity without long-lived keys, then to attach signed claims, and finally to enforce all of it in a cluster.
What an unsigned image looks like
To see the problem concretely, try verifying an image that nobody has signed. The command below asks Cosign to check an image against a public key. It assumes you have Cosign installed and a public key file named cosign.pub. The next chapters show how to create both.
# Try to verify an image that has no signature
cosign verify --key cosign.pub registry.example.com/team/app:1.0.0Cosign exits with a non-zero status and an error saying it found no matching signatures. This is the behavior you want from a verifier: failing closed. When no evidence exists, the answer is "not verified," not "probably fine."
Because the exit status is non-zero, you can use the command in scripts and pipelines as a gate:
if cosign verify --key cosign.pub "$IMAGE" > /dev/null 2>&1; then
echo "verified: safe to deploy"
else
echo "verification failed: blocking deploy" >&2
exit 1
fiHere IMAGE stands for the reference you want to check. In practice it should be a digest reference, for the reasons the next chapter explains.
Common misconceptions
- "We use a private registry, so we are safe." A private registry reduces exposure. It does not stop a stolen credential, a compromised CI job, or an insider from pushing a bad image.
- "Our tags are immutable, so we do not need signatures." Tag immutability stops overwrites on that registry. It does not prove who created the original push, and not every registry or repository enforces it.
- "Signing slows down our pipeline." Signing and verifying take seconds. The real cost is operational: deciding who may sign, how keys or identities are managed, and what happens when verification fails. Later chapters address those points.
- "A signature means the code was reviewed." Only if your process makes it mean that. The signature records who signed. Your release process decides what that person or system checked first.
Key takeaways
- A registry guarantees that you receive the bytes you requested. It does not guarantee that the right party published them.
- A signature ties specific content (a digest) to a specific signer, so tampering and substitution become detectable.
- Signing only helps if something verifies. Verification must fail closed.
- Signing proves origin and integrity. It does not prove the software is safe.
Exercise
A teammate says, "We pull images over TLS and the registry checks digests, so a signature adds nothing." Explain in two or three sentences what risk remains that a signature would address.
Show answer
TLS and digest checks only show that the bytes you received match the content you asked for. They do not show who published that content. An attacker with a stolen registry credential can push a malicious image, and it will download over TLS with a valid digest. A signature lets you verify that the content was signed by your expected key or identity, so an image from anyone else fails verification.
Exercise
Your CI pipeline is compromised, and the attacker's build is signed by your normal pipeline signer. Does signature verification catch this? What does it tell you about the limits of signing?
Show answer
No. The signature is valid because it came from the trusted signer, so verification succeeds. Signing proves who produced the image and that it is unchanged since signing. It does not prove the build process was uncompromised or that the contents are safe. You need other controls alongside it, such as locked-down CI permissions, code review, and scanning.
Exercise
Why does it matter that a verification command fails closed when it finds no signature?
Show answer
A gate that passes when evidence is missing gives no protection, because an attacker's unsigned image would pass. Failing closed means unsigned or altered images are blocked by default. Only images with valid evidence from an expected signer proceed.