Why pin container images by digest, not by tag
A tag and a digest are not the same thing
When you write postgres:16 in a compose file, 16 is a tag: a readable nickname that points to an image. The problem is that this nickname is mutable. Whoever publishes the image can move the 16 tag to new content tomorrow — a fix, a minor version or, in the worst case, a tampered image. Your docker pull postgres:16 today and next week may bring different bytes, with nothing in your file changing.
The digest fixes this. It is the SHA-256 hash of the image manifest: postgres:16@sha256:abcd…. A digest is a content address — if a single byte changes, the digest changes. Pinning by digest means saying “I want exactly this content, and no other.” See digest and OCI image in the glossary.
Why this matters for security
Three concrete risks disappear when you pin by digest:
- Reproducibility. The machine that came up yesterday and the one that comes up tomorrow run the same binary. Without that, an incident is hard to investigate: you do not know which code was actually running.
- Real rollback. To go back a version, you point to the previous digest. With a tag, “go back to :16” may bring different content than you had.
- The link to verification. Scanning and signing an image is useless if the deploy pulls “the latest one with tag X.” The scan and the signature apply to a digest. Pinning by digest is what ties what was audited to what is running.
The classic case is :latest: nobody knows what it points to on two different hosts, nor how to roll back. Half the containers in a typical estate run on :latest or no tag — exactly what we found in the survey that led to the ZTGIT image strategy.
How ZTGIT does it
The ZTGIT rule is blunt: every container runs a registry.ztgit.com/… image pinned by digest, built in our CI from our git, with an SBOM and a signature. Concretely:
- the pipeline builds the image, generates the SBOM and scans it with ZTGIT-SBOMscan;
- the image is signed with cosign. Because promotion creates a multi-architecture OCI index, we sign both the index and the inner manifest, so that
cosign verifyon the tag’s digest also passes; - the deploy compose references only the digest, never the moving tag;
- a daily audit (ZTGIT-CoverageAudit) flags every container that is not on
registry.ztgit.comor has no digest.
A pitfall: the tag moves on rebuild
Pinning by digest has a surprising effect: when you rebuild the image (for example, to inherit a security patch from the base), the tag 2.5.1-ztgit.1 now points to the new digest. The old image still exists by its digest, but loses the tag. This is correct — production should not follow the tag — but it means that, before turning on a garbage collection that “deletes untagged images,” you must mark the digests that are in production. It is a direct consequence of taking the rule seriously.
The takeaway
A tag is convenience for humans; a digest is a contract for machines. In development, use the tag. In production, pin by digest — and require it to be the same one that was scanned and signed. It is the difference between “it should be the right version” and “it is, provably, this content.”