Add reproducible build infrastructure

Pin Rust toolchain to 1.94.0 via rust-toolchain.toml for deterministic
compiler output across environments. Set SOURCE_DATE_EPOCH from git
commit timestamp in CI workflows and packaging scripts to normalize
embedded timestamps.

Make packaging archives reproducible: pass --mtime=@$SOURCE_DATE_EPOCH
to tar in .deb, .ipk, and systemd tarball builds. Normalize ownership
to root:root in systemd tarballs. Pin cargo-zigbuild to 0.19.8 for
cross-compilation stability.

Add SHA-256 hash output to CI build and OpenWrt packaging workflows
for binary verification.
This commit is contained in:
Origami74
2026-03-20 20:36:02 -07:00
committed by Johnathan Corgan
parent fed6cc6987
commit c164de8808
6 changed files with 43 additions and 4 deletions
+10
View File
@@ -18,6 +18,7 @@ permissions:
env: env:
CARGO_TERM_COLOR: always CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1 RUST_BACKTRACE: 1
SOURCE_DATE_EPOCH: 0 # overridden per-step after checkout
# ───────────────────────────────────────────────────────────────────────────── # ─────────────────────────────────────────────────────────────────────────────
# Job 1 Build matrix # Job 1 Build matrix
@@ -40,6 +41,9 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Set SOURCE_DATE_EPOCH from git
run: echo "SOURCE_DATE_EPOCH=$(git log -1 --format=%ct)" >> "$GITHUB_ENV"
- name: Install Rust toolchain - name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable uses: dtolnay/rust-toolchain@stable
@@ -57,6 +61,9 @@ jobs:
- name: Build - name: Build
run: cargo build --release run: cargo build --release
- name: SHA-256 hashes
run: sha256sum target/release/fips target/release/fipsctl target/release/fipstop
# Upload the Linux binary so integration jobs can use it without rebuilding # Upload the Linux binary so integration jobs can use it without rebuilding
- name: Upload Linux binary - name: Upload Linux binary
if: matrix.os == 'ubuntu-latest' if: matrix.os == 'ubuntu-latest'
@@ -82,6 +89,9 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Set SOURCE_DATE_EPOCH from git
run: echo "SOURCE_DATE_EPOCH=$(git log -1 --format=%ct)" >> "$GITHUB_ENV"
- name: Install Rust toolchain - name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable uses: dtolnay/rust-toolchain@stable
+12 -1
View File
@@ -11,6 +11,7 @@ on:
env: env:
CARGO_TERM_COLOR: always CARGO_TERM_COLOR: always
SOURCE_DATE_EPOCH: 0 # overridden per-step after checkout
jobs: jobs:
build: build:
@@ -46,6 +47,9 @@ jobs:
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Set SOURCE_DATE_EPOCH from git
run: echo "SOURCE_DATE_EPOCH=$(git log -1 --format=%ct)" >> "$GITHUB_ENV"
- name: Derive package version - name: Derive package version
id: version id: version
run: | run: |
@@ -84,7 +88,7 @@ jobs:
openwrt-${{ matrix.rust_target }}- openwrt-${{ matrix.rust_target }}-
- name: Install cargo-zigbuild - name: Install cargo-zigbuild
run: cargo install cargo-zigbuild --locked run: cargo install cargo-zigbuild --version 0.19.8 --locked
- name: Install zig (required by cargo-zigbuild) - name: Install zig (required by cargo-zigbuild)
uses: goto-bus-stop/setup-zig@v2 uses: goto-bus-stop/setup-zig@v2
@@ -98,6 +102,13 @@ jobs:
LLVM_STRIP: llvm-strip LLVM_STRIP: llvm-strip
run: ./packaging/openwrt-ipk/build-ipk.sh --arch ${{ matrix.build_arch }} run: ./packaging/openwrt-ipk/build-ipk.sh --arch ${{ matrix.build_arch }}
- name: SHA-256 hashes
run: |
echo "==> Binaries:"
sha256sum target/${{ matrix.rust_target }}/release/fips target/${{ matrix.rust_target }}/release/fipsctl target/${{ matrix.rust_target }}/release/fipstop
echo "==> Package:"
sha256sum dist/${{ steps.version.outputs.filename }}
- name: Upload artifact - name: Upload artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
+5
View File
@@ -19,6 +19,11 @@ if ! command -v cargo-deb &>/dev/null; then
exit 1 exit 1
fi fi
# Derive SOURCE_DATE_EPOCH from git if not already set (reproducible builds)
if [ -z "${SOURCE_DATE_EPOCH:-}" ]; then
export SOURCE_DATE_EPOCH=$(git log -1 --format=%ct)
fi
# Build the .deb package # Build the .deb package
echo "Building .deb package..." echo "Building .deb package..."
cargo deb cargo deb
+5 -1
View File
@@ -244,7 +244,11 @@ fi
ipk_tar() { ipk_tar() {
# ipk_tar <output.tar.gz> <source-dir> [paths...] # ipk_tar <output.tar.gz> <source-dir> [paths...]
local out="$1" src="$2"; shift 2 local out="$1" src="$2"; shift 2
COPYFILE_DISABLE=1 "$TAR_CMD" $TAR_EXTRA_FLAGS -czf "$out" -C "$src" "$@" local mtime_flags=""
if [ -n "${SOURCE_DATE_EPOCH:-}" ]; then
mtime_flags="--mtime=@$SOURCE_DATE_EPOCH"
fi
COPYFILE_DISABLE=1 "$TAR_CMD" $TAR_EXTRA_FLAGS $mtime_flags -czf "$out" -C "$src" "$@"
} }
ipk_tar "$IPK_WORK/control.tar.gz" "$CONTROL_DIR" . ipk_tar "$IPK_WORK/control.tar.gz" "$CONTROL_DIR" .
+9 -2
View File
@@ -45,9 +45,16 @@ cp "${SCRIPT_DIR}/README.install.md" "${STAGING_DIR}/"
chmod +x "${STAGING_DIR}/install.sh" "${STAGING_DIR}/uninstall.sh" chmod +x "${STAGING_DIR}/install.sh" "${STAGING_DIR}/uninstall.sh"
# Create tarball # Create tarball (reproducible: normalize timestamps and ownership)
cd "${DEPLOY_DIR}" cd "${DEPLOY_DIR}"
tar czf "${TARBALL_NAME}.tar.gz" "${TARBALL_NAME}/" TAR_REPRO_FLAGS=""
if [ -n "${SOURCE_DATE_EPOCH:-}" ]; then
TAR_REPRO_FLAGS="--mtime=@${SOURCE_DATE_EPOCH}"
fi
if tar --version 2>/dev/null | grep -q 'GNU tar'; then
TAR_REPRO_FLAGS="${TAR_REPRO_FLAGS} --numeric-owner --owner=0 --group=0"
fi
COPYFILE_DISABLE=1 tar ${TAR_REPRO_FLAGS} -czf "${TARBALL_NAME}.tar.gz" "${TARBALL_NAME}/"
rm -rf "${STAGING_DIR}" rm -rf "${STAGING_DIR}"
echo "" echo ""
+2
View File
@@ -0,0 +1,2 @@
[toolchain]
channel = "1.94.0"