release: reproducible builds, and sign every asset
"The source is public" is not a check anyone can run, and against a Tor + Monero tool the surviving objection is that the released binary might not be that source. This makes the build checkable instead of trusted. - scripts/reproducible-build.sh is the single definition of a release build: digest-pinned builder image, fixed in-container paths, SOURCE_DATE_EPOCH from the released commit, --locked, its own apt build deps, and RUSTFLAGS replaced rather than extended. The fixed paths are load-bearing: rustc's --remap-path-prefix cannot reach absolute paths compiled in by a C toolchain, and this graph always has one (rusqlite compiles OpenSSL from vendored sources; the default cuprate-daemon adds RandomX and cmake). It also records toolchain versions in build-info, because the apt build deps are not digest-pinned the way the image is. - release.yml pins the image by digest, resolves SOURCE_DATE_EPOCH from the tag's commit, runs that recipe, and uploads build-info-<target>.txt beside the binary. The cargo target volume is created per run and removed, so the published artifact cannot come out of a cache that a verifier does not have. - scripts/verify-reproducible.sh rebuilds a tag in the same pinned image and compares bytes against the release asset. Two fresh builds of the same tree in that image produce identical sha256. - scripts/sign-release.sh signs with minisign and verifies its own signature against the committed public key. The publish job signs BEFORE publishing and fails closed without MINISIGN_SECRET_KEY, so nothing unsigned reaches the release page: an unsigned release is indistinguishable from a signed one to anyone who is not checking. Checked: signature accepted by an independent minisign -V, a tampered file rejected, a missing key refused, a missing public key refused. - build-release-local.sh runs the same container and the same recipe. A host cargo build would publish a hash nobody could reproduce, which is worse than having no fallback at all. - docs/VERIFY.md is the verifier-facing walkthrough: the dependency graph and where its HTTP actually comes from, the wallet's real seed-read exposure, the rebuild check, the signature check, and an explicit list of what none of it proves. - Cargo.toml repository: point at the Forgejo instance that hosts this and builds its releases. Needs a MINISIGN_SECRET_KEY secret before the next release; without it the publish job stops by design. docs/RELEASING.md has the keygen procedure.
This commit is contained in:
parent
1031092192
commit
601f640f78
11 changed files with 962 additions and 76 deletions
144
scripts/reproducible-build.sh
Executable file
144
scripts/reproducible-build.sh
Executable file
|
|
@ -0,0 +1,144 @@
|
|||
#!/usr/bin/env bash
|
||||
# Canonical OnionWire release build. RUNS INSIDE THE PINNED BUILDER IMAGE
|
||||
# (BUILDER_IMAGE in .forgejo/workflows/release.yml — pinned by digest, not by a
|
||||
# floating tag, and recorded in the build-info asset).
|
||||
#
|
||||
# This is the only supported way to produce a release binary. The bytes it
|
||||
# emits are exactly what `scripts/verify-reproducible.sh` rebuilds and compares,
|
||||
# so anything that can move those bytes is pinned here rather than left to the
|
||||
# environment:
|
||||
#
|
||||
# * the builder image, by digest — `rust:1.98-bookworm` floats, and rustc
|
||||
# patches change codegen;
|
||||
# * every absolute build path (source, cargo target dir, cargo registry).
|
||||
# rustc's `--remap-path-prefix` covers paths that reach rustc's own
|
||||
# strings and debug info, but NOT absolute paths compiled in by a C
|
||||
# toolchain — and this crate always has one: rusqlite's
|
||||
# `bundled-sqlcipher-vendored-openssl` feature compiles OpenSSL from
|
||||
# source, and OpenSSL bakes its build and config paths into the artifact.
|
||||
# The build therefore happens at fixed paths inside the container;
|
||||
# * SOURCE_DATE_EPOCH, from the released commit's committer date, so no
|
||||
# build clock reaches the output (OpenSSL and any date-dependent crate
|
||||
# read it);
|
||||
# * the dependency graph, via `--locked`;
|
||||
# * the strip step and its exact flag (binutils versions differ between
|
||||
# hosts; inside the pinned image they do not).
|
||||
#
|
||||
# RUSTFLAGS is *replaced*, never extended. An ambient RUSTFLAGS from a shell
|
||||
# profile or a CI default would silently change the output bytes, which is
|
||||
# precisely the thing this script exists to prevent.
|
||||
#
|
||||
# Inputs (env):
|
||||
# SOURCE_DATE_EPOCH required. `git log -1 --format=%ct <released-commit>`
|
||||
# SRC source checkout (default /src)
|
||||
# CARGO_TARGET_DIR build directory (default /target)
|
||||
# OUT where dist assets are written (default /out)
|
||||
# TARGET_TRIPLE asset name triple, defaults to the image's rustc host
|
||||
# BUILDER_IMAGE recorded in build-info.txt only (no effect on bytes)
|
||||
# CARGO_BUILD_JOBS build parallelism (no effect on bytes; default 2)
|
||||
#
|
||||
# Outputs in $OUT:
|
||||
# onionwire-<triple> the stripped binary
|
||||
# onionwire-<triple>.sha256 sha256sum-format checksum of it
|
||||
# build-info-<triple>.txt the recipe record: toolchain, epoch, commit,
|
||||
# image, and the hash this run produced
|
||||
set -euo pipefail
|
||||
|
||||
SRC="${SRC:-/src}"
|
||||
OUT="${OUT:-/out}"
|
||||
export CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-/target}"
|
||||
|
||||
: "${SOURCE_DATE_EPOCH:?set SOURCE_DATE_EPOCH to the committer time of the released commit: git log -1 --format=%ct <sha>}"
|
||||
export SOURCE_DATE_EPOCH
|
||||
|
||||
# No colour, no progress bars: not a determinism input, but it keeps CI logs
|
||||
# diffable between two builds of the same commit.
|
||||
export CARGO_TERM_COLOR=never
|
||||
export CARGO_BUILD_JOBS="${CARGO_BUILD_JOBS:-2}"
|
||||
|
||||
# Fixed paths. The remaps make the output independent of where $SRC actually
|
||||
# lives on the verifying host; the container keeps the paths themselves fixed
|
||||
# for the C toolchains that ignore remapping entirely.
|
||||
#
|
||||
# CARGO_HOME is remapped as a whole, not just `registry`: the default feature
|
||||
# set pulls `cuprated` from a pinned git revision, and its checkout lands under
|
||||
# `$CARGO_HOME/git/...` — a path that would otherwise reach the artifact through
|
||||
# cuprate's own `file!()`/panic locations.
|
||||
CARGO_HOME_DIR="${CARGO_HOME:-/usr/local/cargo}"
|
||||
export RUSTFLAGS="--remap-path-prefix=${SRC}=/onionwire --remap-path-prefix=${CARGO_TARGET_DIR}=/onionwire/target --remap-path-prefix=${CARGO_HOME_DIR}=/cargo"
|
||||
|
||||
cd "$SRC"
|
||||
|
||||
# Build dependencies are installed HERE rather than by the caller, so CI and a
|
||||
# verifier get the same toolchain. `cmake` and a C toolchain are required because
|
||||
# the default feature set includes `cuprate-daemon` (RandomX + fjall), which the
|
||||
# release binary ships.
|
||||
#
|
||||
# Honest limit: these apt packages are not digest-pinned the way the image is, so
|
||||
# a Debian security update to gcc or cmake can move the output bytes. build-info
|
||||
# records their versions, so that mismatch is diagnosable instead of mysterious.
|
||||
apt-get -o Acquire::Retries=5 -o Acquire::ForceIPv4=true update
|
||||
apt-get -o Acquire::Retries=5 -o Acquire::ForceIPv4=true install -y --no-install-recommends \
|
||||
pkg-config libssl-dev cmake build-essential
|
||||
|
||||
TARGET_TRIPLE="${TARGET_TRIPLE:-$(rustc -vV | sed -n 's/^host: //p')}"
|
||||
[ -n "$TARGET_TRIPLE" ] || { echo "could not determine the target triple from rustc -vV" >&2; exit 1; }
|
||||
|
||||
# Derived once into variables: the values are wanted twice (the log line and
|
||||
# build-info.txt), and nesting a command substitution with its own quotes
|
||||
# inside a double-quoted string is where this file previously broke.
|
||||
EPOCH_UTC="$(date -u -d "@${SOURCE_DATE_EPOCH}" +%Y-%m-%dT%H:%M:%SZ)"
|
||||
RUSTC_VV="$(rustc -Vv | tr '\n' ' ' | sed 's/ */ /g')"
|
||||
CARGO_V="$(cargo -V)"
|
||||
STRIP_V="$(strip --version | head -1)"
|
||||
CC_V="$(cc --version | head -1)"
|
||||
CMAKE_V="$(cmake --version | head -1)"
|
||||
|
||||
echo "==> builder image: ${BUILDER_IMAGE:-unknown}"
|
||||
echo "==> rustc: ${RUSTC_VV}"
|
||||
echo "==> cargo: ${CARGO_V}"
|
||||
echo "==> SOURCE_DATE_EPOCH: ${SOURCE_DATE_EPOCH} (${EPOCH_UTC})"
|
||||
echo "==> RUSTFLAGS: ${RUSTFLAGS}"
|
||||
|
||||
cargo build --release --locked --bin onionwire
|
||||
|
||||
BIN="${CARGO_TARGET_DIR}/release/onionwire"
|
||||
[ -f "$BIN" ] || { echo "no binary at $BIN" >&2; exit 1; }
|
||||
|
||||
# CI passes the released sha in (the builder image has no git checkout to read);
|
||||
# a verifier running this from a clone lets it derive the sha itself.
|
||||
GIT_SHA="${GIT_SHA:-$(git -C "$SRC" rev-parse HEAD 2>/dev/null || echo unknown)}"
|
||||
|
||||
strip --strip-all "$BIN"
|
||||
|
||||
mkdir -p "$OUT"
|
||||
install -m 755 "$BIN" "${OUT}/onionwire-${TARGET_TRIPLE}"
|
||||
(
|
||||
cd "$OUT"
|
||||
sha256sum "onionwire-${TARGET_TRIPLE}" > "onionwire-${TARGET_TRIPLE}.sha256"
|
||||
sha256sum -c "onionwire-${TARGET_TRIPLE}.sha256"
|
||||
)
|
||||
|
||||
# The recipe record. Published next to the binary so a verifier can see which
|
||||
# toolchain, epoch and commit produced the hash they are comparing against
|
||||
# without having to reverse it out of a CI log.
|
||||
BINARY_SHA="$(cut -d' ' -f1 < "${OUT}/onionwire-${TARGET_TRIPLE}.sha256")"
|
||||
|
||||
{
|
||||
echo "onionwire ${TARGET_TRIPLE}"
|
||||
echo "commit: ${GIT_SHA}"
|
||||
echo "source_date_epoch: ${SOURCE_DATE_EPOCH}"
|
||||
echo "commit_time_utc: ${EPOCH_UTC}"
|
||||
echo "builder_image: ${BUILDER_IMAGE:-unknown}"
|
||||
echo "rustc: ${RUSTC_VV}"
|
||||
echo "cargo: ${CARGO_V}"
|
||||
echo "strip: ${STRIP_V}"
|
||||
echo "cc: ${CC_V}"
|
||||
echo "cmake: ${CMAKE_V}"
|
||||
echo "rustflags: ${RUSTFLAGS}"
|
||||
echo "build_command: cargo build --release --locked --bin onionwire"
|
||||
echo "sha256: ${BINARY_SHA}"
|
||||
} > "${OUT}/build-info-${TARGET_TRIPLE}.txt"
|
||||
|
||||
echo "==> build-info-${TARGET_TRIPLE}.txt"
|
||||
cat "${OUT}/build-info-${TARGET_TRIPLE}.txt"
|
||||
Loading…
Reference in a new issue