Skip to content

Reproducing the Build

Sam Bent edited this page Oct 30, 2026 · 15 revisions

Reproducing the Build

HiddenForge builds bit-for-bit reproducibly. Given the same source commit, you can build the image yourself and get the same OCI index digest as the release. That digest is what the ML-DSA-65 and hardware signatures cover, so a match proves the published image came from the published source. For the signature checks themselves, see Verifying the Image.

Reproduce 2.1.4

Build from a fresh clone. This is not optional (reason below). A two-platform OCI build needs a docker-container builder (the default docker driver cannot export one), and an amd64 host needs arm64 emulation for the arm64 half:

docker run --privileged --rm tonistiigi/binfmt --install arm64   # once per boot
docker buildx create --name repro --driver docker-container \
  --driver-opt image=moby/buildkit:v0.30.0 --use   # the BuildKit the release used
git clone https://sambent.dev/sam/HiddenForge.git /tmp/hf && cd /tmp/hf
git checkout v2.1.4
docker buildx version   # record this; buildx behaviour here is version-sensitive
export SOURCE_DATE_EPOCH=$(git log -1 --format=%ct v2.1.4)
docker buildx build --platform linux/amd64,linux/arm64 \
  --build-arg SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH \
  --provenance=false --output type=oci,dest=out.tar,rewrite-timestamp=true .
tar -xOf out.tar index.json | python3 -c 'import json,sys;print(json.load(sys.stdin)["manifests"][0]["digest"])'

The last line prints the digest to compare. The 2.1.4 index digest is:

sha256:7732c01f505ba7826b422e2579d56f20c3f5ae11950336fb83507c1a35419582

If your output matches, you have reproduced the release. Then confirm that this is also the digest the registry serves:

skopeo inspect --raw docker://sambent.dev/sam/hiddenforge:2.1.4 | sha256sum   # bare hex: compare without the sha256: prefix

Which digest gets compared

Compare the OCI index digest from index.json inside the archive (manifests[0].digest). Never compare docker image inspect --format '{{.Id}}'. The .Id is the image config digest, while the index digest covers the manifest list. A check that compares .Id reports a false "NOT REPRODUCIBLE".

Why each flag is there

Flag Why
--platform linux/amd64,linux/arm64 The release index is multi-platform. An amd64-only build produces a different index digest, and that is expected. Use the same --platform value the release used.
--provenance=false buildx puts wall-clock timestamps in the SLSA provenance attestation, which lives inside the image index. Left on, the digest changes on every build.
--output type=oci,...,rewrite-timestamp=true Clamps file timestamps to SOURCE_DATE_EPOCH.
--build-arg SOURCE_DATE_EPOCH=... The commit time. The build uses it for the one clock-derived field it cannot otherwise control (explained in the table further down).

Both --provenance=false and rewrite-timestamp behave differently across buildx releases. The 2.1.4 reproduction used buildx v0.19.3 with a docker-container builder running BuildKit v0.30.0. Record the versions you build with, because a digest mismatch you cannot attribute to a version is impossible to diagnose.

Why a fresh clone is required

rewrite-timestamp clamps file modification times to SOURCE_DATE_EPOCH, as min(mtime, epoch). It does not set them equal.

In a fresh clone, every file's mtime is the checkout time, which is newer than the commit. All of them clamp to the same value, so the build is deterministic. In a working tree where files were edited at different times, any file older than SOURCE_DATE_EPOCH keeps its own mtime and lands in the layer unchanged. That produces a digest only that particular tree can generate. Releases are built from a pristine checkout for this reason.

Your umask does not matter (from 2.1.1)

A fresh clone takes its file modes from the umask of whoever cloned it. Up to 2.1.0 the Dockerfile's COPY lines recorded those modes in their layers, so a clone under umask 007 and one under 022 built different digests from the same commit, and 2.1.0 reproduces only under the umask it was released from. From 2.1.1 every COPY states its mode with --chmod. Two two-platform builds of v2.1.4, cloned under umask 007 and under 022, gave byte-identical archives.

What the Dockerfile does to stay reproducible

Source of non-determinism Fix in the Dockerfile
apk stamps a new account's /etc/shadow "last-change" field with the current day A sed pins every account's field to the SOURCE_DATE_EPOCH day. It applies to every row, so a future package that adds a user cannot reintroduce the drift.
/var/log/apk.log records wall-clock operation times Deleted after each apk add or apk del.
apk add --virtual gives each virtual package a self-generated checksum that differed between two builds of identical source py3-pip is installed by name, then removed with apk del py3-pip.
mkp224o's upstream configure injects -march=native CFLAGS="-O3" is set explicitly. This also keeps the binary from faulting on a different CPU.

What is verified, and what is not

The reproduction above is run on an amd64 builder. The 2.0.4 documentation says only its amd64 manifest was reproduced and treats arm64 as unverified until it is reproduced on a builder that can run it. For 2.1.4, two clean two-platform builds of the v2.1.4 tag, cloned from the public repository under two different umasks, gave the same index digest. The arm64 image (the same software as 2.1.0's) booted in a full-system arm64 VM under QEMU. It has not run on real ARM hardware.

Old tags may no longer rebuild

Alpine prunes superseded package versions from its index. The build file pins exact apk versions (for example tor=0.4.9.14-r0), and apk add --no-cache fetches the index at build time, so digest-pinning the base image does not freeze it. A pin that was valid at release time stops resolving once a security update lands.

When that happens the build fails at apk add. It does not produce a different image. That is the intended failure mode, and the consequence is that a source build of an older tag will not necessarily reproduce.

A concrete case: v2.0.4 pins tor=0.4.9.11-r0 and python3=3.12.14-r0, and both have been pruned from Alpine's v3.23 index. Rebuilding v2.0.4 today fails. The 2.0.4 image is still verifiable through its signatures; what is gone is the ability to rebuild it from source. The same pruning broke this project's own master several times (a build with a warm cache hid it, because the packages were still cached).

These guards exist so the next pruned pin is found early:

Guard What it does
scripts/check_pins.py Reads the Alpine index and checks every apk add pin in the Dockerfile. Exit 2 means a pinned version is gone (the build will fail). A newer version available is reported with exit 0, because a bump is a reviewed decision. Exit 3 means the check could not be made (the index could not be fetched, was empty or unreadable, or the arguments were bad), never a false pass.
CI pin-freshness job Runs check_pins.py on a schedule or on dispatch, so the next pruned pin is found before a build needs it.
CI reproducibility job Clones the commit twice, under umask 007 and 022, builds each for linux/amd64, and fails if the index digests differ. It runs on every v* tag too. The two-platform digest is reproduced by hand before a release is signed.

Run the pin check yourself:

python3 scripts/check_pins.py

The mkp224o-build stage installs its build tools unpinned on purpose. They are not in the final image, and the stage's only output is the hash-checked, statically linked generator binary.

Clone this wiki locally