Skip to content

Reproducing the Build

Sam Bent edited this page Dec 3, 2026 · 15 revisions

Reproducing the Build

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

Since 3.0 the build takes every package, the Tor tarball and the vendored Rust crate from the release's input archive, not from a package mirror. build-inputs.sha256 locks that archive. The only other things the build pulls are the three Docker Hardened Images base and builder images and the BuildKit image, each by digest.

Reproduce 3.0.2

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 qemu's binfmt_misc handler for aarch64 to build the arm64 half. The release was built with BuildKit v0.30.0, pinned below by digest. dhi.io, where the base and builder images come from, refuses anonymous pulls, so log in with any Docker account first.

docker login dhi.io
git clone --branch v3.0.2 https://sambent.dev/sam/HiddenForge.git /tmp/hf && cd /tmp/hf
python3 scripts/build_inputs.py fetch \
  https://sambent.dev/api/packages/sam/generic/hiddenforge-inputs/3.0.2/hiddenforge-inputs-3.0.2.tar /tmp/hf-inputs
docker buildx version   # record this; buildx behaviour here is version-sensitive
docker buildx create --name repro --driver docker-container \
  --driver-opt image=moby/buildkit@sha256:0168606be2315b7c807a03b3d8aa79beefdb31c98740cebdffdfeebf31190c9f
export SOURCE_DATE_EPOCH=$(git log -1 --format=%ct v3.0.2)
docker buildx build --builder repro --no-cache --platform linux/amd64,linux/arm64 \
  --build-context inputs=/tmp/hf-inputs \
  --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 3.0.2 index digest is:

sha256:075ec87627abb1ad938b145741e0e77953cebf27a9a228fc8ac9a442067871ec

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:3.0.2 | sha256sum   # bare hex: compare without the sha256: prefix

The input archive

The archive is published as the generic package hiddenforge-inputs, version 3.0.2, on sambent.dev (the URL in the fetch command above). scripts/build_inputs.py fetch downloads it over HTTPS into an empty directory, extracts it without trusting the paths inside, and then verifies it. You can repeat the check at any time:

python3 scripts/build_inputs.py verify /tmp/hf-inputs

verify refuses the archive unless every one of these holds:

  1. The directory holds exactly the files in build-inputs.sha256, with those hashes. An older or substituted archive fails here, even if everything in it is validly signed.
  2. Each package index carries a valid RSA signature from a key pinned in signatures/ (Docker's DHI apk key, Alpine's keys).
  3. Every .apk matches the checksum its signed index lists.
  4. The Tor tarball's SHA-256 file is signed by one of Tor's release keys, and the tarball matches it.
  5. The vendored libc crate matches Cargo.lock.

It needs openssl and gpg on the host. Only fetch uses the network.

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
--build-context inputs=... The verified input archive. The Dockerfile copies every package, the Tor tarball and the vendored crate from it.
--no-cache Every layer is built again, so a cached layer cannot hide a difference.
--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 Dockerfile sets every file in the added layer to it.

Both --provenance=false and rewrite-timestamp behave differently across buildx and BuildKit releases. The 3.0.2 reproduction used a docker-container builder running BuildKit v0.30.0, and the digest depends on that version, so reproduce with it. 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 v3.0.2, 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
Packages and sources fetched at build time change between builds They come from the locked input archive, installed with apk add --no-network and cargo build --offline, and every RUN step has --network=none, so nothing can be fetched.
/var/log/apk.log records wall-clock operation times Deleted after the apk add in the C build stage.
File modification times Every file in the added layer is set to SOURCE_DATE_EPOCH with touch, and rewrite-timestamp clamps the rest.
Build paths and build ids end up in binaries Tor and mkp224o are built with -ffile-prefix-map, -fno-ident and --build-id=none; the Rust binary with --remap-path-prefix and --build-id=none.
File modes depend on the cloner's umask Every COPY states its mode with --chmod, and the directories are created first so they do not inherit a file mode.

What is verified, and what is not

Three clean two-platform builds of the v3.0.2 tag from fresh clones gave the same index digest, which covers both platform manifests, and the three OCI archives were byte-for-byte identical. Two ran on one machine (umask 007 and 022, base images from dhi.io) and one on another (umask 022, base images from a mirror of the same digests). All three used BuildKit v0.30.0. Both machines are the maintainer's, so no one else has reproduced it yet. A build by someone else would remove that point.

The arm64 half was built under qemu emulation on an amd64 host. The arm64 image was run in a full-system arm64 VM, where it came up healthy and served over Tor. It has not run on real ARM hardware.

Old tags no longer rebuild

2.x pinned exact Alpine package versions (for example tor=0.4.9.11-r0 in v2.0.4), and apk add fetched the index at build time. Alpine prunes superseded packages from its index, so those pins stopped resolving once a security update landed, and the build failed at apk add. v2.0.4 and v2.1.6 cannot be rebuilt from source today. Their signatures still verify; what is gone is the ability to rebuild them.

3.0 removes the cause. It builds from an archive of its inputs, which build-inputs.sha256 locks and fetch verifies, so Alpine pruning cannot break it. The archive is kept for each 3.x release.

Two CI jobs guard this:

Guard What it does
inputs-integrity job Runs scripts/build_inputs.py verify over the archived inputs (lock, signatures, checksums) on a schedule or on dispatch, and warns when Tor has published a newer stable release than the one the build pins.
reproducibility job Clones the commit twice, under umask 007 and 022, builds each for linux/amd64 on a BuildKit builder of its own (pinned by digest, removed afterwards), 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.

scripts/check_pins.py and the pin-freshness job are gone, because there are no apk pins left to check.

Clone this wiki locally