TExcelTAD
Home › Software Supply Chain Security: SBOM, SLSA & Sigstore › Tags vs Digests: Pinning by Digest

Tags vs Digests: Pinning by Digest

A tag (alpine:3.18, app:1.4.2, latest) is a name that a registry maps to a manifest digest. Anyone with push rights can move it to another digest at any time, and registries normally keep no history of where it pointed. A digest (app@sha256:…) names exact bytes and can never mean anything else.

Tag Digest
Readable yes no
Changes when the publisher re-pushes yes never
Survives a registry compromise no, the attacker can retarget it yes, the client verifies the bytes
What signatures are attached to (nothing: cosign signs digests) the digest

A moved tag

This session plays both sides: the publisher pushes app:1.0 and a deployment records it; later, someone with push access (an attacker with a stolen token, or a well-meaning colleague rebuilding) pushes a different image under the same tag.

bash · try it yourself
mkdir work && cd work
n=0
mk_image() {   # mk_image <message> <tag>: alpine + one script that prints the message
  n=$((n + 1)); d=layer$n
  mkdir -p "$d/usr/local/bin"
  printf '#!/bin/sh\necho "%s"\n' "$1" > "$d/usr/local/bin/app"
  chmod 755 "$d/usr/local/bin/app"
  tar --sort=name --mtime=@$SOURCE_DATE_EPOCH --owner=0 --group=0 --numeric-owner -C "$d" -cf "$d.tar" .
  crane append -b localhost:5000/base/alpine:3.18.0 -f "$d.tar" -t "$2" > /dev/null 2>&1
}
run_app() { crane export "$1" - | tar -xOf - usr/local/bin/app | tail -1; }
crane push /opt/samples/images/alpine-3.18.0.tar localhost:5000/base/alpine:3.18.0 > /dev/null 2>&1

mk_image "app 1.0, the reviewed build" localhost:5000/shop/app:1.0
PINNED=localhost:5000/shop/app@$(crane digest localhost:5000/shop/app:1.0)
echo "deployment pins: ${PINNED#*@}" | cut -c1-36

mk_image "app 1.0, something else entirely" localhost:5000/shop/app:1.0     # the tag moves

echo "by tag:    $(run_app localhost:5000/shop/app:1.0)"
echo "by digest: $(run_app "$PINNED")"
crane ls localhost:5000/shop/app
deployment pins: sha256:e0397651f8f1
by tag:    echo "app 1.0, something else entirely"
by digest: echo "app 1.0, the reviewed build"
1.0

The pinned reference still returns the reviewed build; the tag now returns whatever was pushed last. Nothing in the registry records that 1.0 used to mean something else. (The old manifest is still there, untagged; registries garbage-collect such manifests eventually, so pinned digests should also be protected from deletion by retention rules.)

Pinning in practice

Resolve the tag once, at a moment you control (when you review an update), and write the digest down. Keep the tag as a comment or prefix for humans: most tools accept name:tag@sha256:… and use only the digest.

bash · try it yourself
crane push /opt/samples/images/alpine-3.18.0.tar localhost:5000/library/alpine:3.18.0 > /dev/null 2>&1
REF=localhost:5000/library/alpine:3.18.0
DIGEST=$(crane digest $REF)
cat > Dockerfile <<EOF
FROM $REF@$DIGEST
RUN adduser -D app
USER app
EOF
cat Dockerfile | sed 's/sha256:\(.\{12\}\).*/sha256:\1…/'
crane manifest "$REF@$DIGEST" > /dev/null && echo "the pinned reference resolves"
crane manifest "${REF%:*}@sha256:$(printf '0%.0s' $(seq 64))" > /dev/null 2>&1 || echo "an unknown digest fails instead of falling back to anything"
FROM localhost:5000/library/alpine:3.18.0@sha256:f04ffda0b140…
RUN adduser -D app
USER app
the pinned reference resolves
an unknown digest fails instead of falling back to anything

Where to pin:

Place Pin
FROM in Dockerfiles FROM alpine:3.18.0@sha256:…
Kubernetes manifests, Helm values image: registry.example.com/shop/app@sha256:… (see Admission Control to enforce it)
CI job images and service containers image: node:24@sha256:…
GitHub Actions uses: owner/action@<40-char commit SHA> (the same idea for actions; Field Notes)
Base images in build tools (Jib, ko, Buildpacks) their base-image setting, by digest

The cost, and how to pay it

A pinned digest never gets security updates by itself: alpine:3.18 would have moved to the next patch release, your digest won't. Pinning only works together with automated updates: Renovate (docker:pinDigests preset) and Dependabot open pull requests that bump the digest when the tag moves, and your CI scans the new image before anyone merges (Dependabot, Renovate & Scorecard). You get the updates, but as reviewed, recorded changes instead of silent ones.

Two registry-side controls complement pinning:

  • Immutable tags (Amazon ECR, Harbor, Artifactory, Google Artifact Registry and others can refuse to overwrite an existing tag). Good for release tags such as 1.4.2; useless for moving tags such as latest by definition.
  • Signatures on digests: even when you deploy by tag, an admission controller can resolve the tag, check that the resulting digest is signed by your CI, and rewrite the pod spec to the digest.

Test yourself

A deployment uses shop/app:1.0 and someone re-pushes 1.0. What runs after the next pod restart?

  1. The original image, tags are immutable
  2. The newly pushed image
  3. Neither, the pull fails
  4. Both

What does FROM alpine:3.18.0@sha256:abc… use when building?

  1. The tag; the digest is a comment
  2. The digest; the tag is only for humans
  3. Whichever is newer
  4. Both must match or the build uses latest

What is the main downside of pinning base images by digest, and the usual remedy?

  1. Slower pulls; use a cache
  2. No automatic security updates; use a bot that opens digest-bump PRs
  3. Digests expire; renew them
  4. Registries reject digests; use tags