From 60e9daaab917ad8173ae0b2674c11e5a8c7b9def Mon Sep 17 00:00:00 2001 From: fastrevmd-lab Date: Fri, 23 Oct 2026 18:29:58 -0400 Subject: [PATCH 1/2] packaging: supported skip-build path with honest BUILD-INFO (mecmcp#355) scripts/build-release.sh gains PANOSMCP_PACKAGE_SKIP_BUILD=1 for packaging a CI-built binary (workstation glibc is newer than the LXCs'). It requires PANOSMCP_BINARY_SOURCE_COMMIT (40-hex, present in the clone) and records it as git_commit, with packaging_commit always recorded. BUILD-INFO now carries binary_sha256 and a single rustc= line: the real rustc -vV when built here, "unknown (... not compiled by this script)" when prebuilt. conformance.toml makes R3 fatal; CI stages the conformance package from build-release.sh output and runs packaging/tests/skip-build-provenance.sh. OPERATIONS.md documents the path and the new fields. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 14 +++--- docs/OPERATIONS.md | 22 +++++++++ packaging/conformance.toml | 10 +++-- packaging/tests/skip-build-provenance.sh | 57 ++++++++++++++++++++++++ scripts/build-release.sh | 42 ++++++++++++++--- 5 files changed, 129 insertions(+), 16 deletions(-) create mode 100755 packaging/tests/skip-build-provenance.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8090bc..a844032 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -128,17 +128,17 @@ jobs: - name: Install stable Rust uses: dtolnay/rust-toolchain@stable - - name: Build the release binary - run: cargo build --release --locked --bin rust-panosmcp - - - name: Stage the package + - name: Build and stage the package run: | set -euo pipefail - mkdir -p staging/bin - cp target/release/rust-panosmcp staging/bin/ - cp -r packaging staging/packaging + PANOSMCP_OUTPUT_DIR="$RUNNER_TEMP/pkg" scripts/build-release.sh + mkdir staging + tar -xzf "$RUNNER_TEMP"/pkg/rust-panosmcp-v*.tar.gz -C staging --strip-components=1 cp packaging/conformance.toml staging/ + - name: Skip-build provenance stays honest + run: packaging/tests/skip-build-provenance.sh + - name: Set up Buildx uses: docker/setup-buildx-action@v4 diff --git a/docs/OPERATIONS.md b/docs/OPERATIONS.md index c3f76df..ed483a5 100644 --- a/docs/OPERATIONS.md +++ b/docs/OPERATIONS.md @@ -16,6 +16,28 @@ tar -xzf rust-panosmcp-v0.16.2-x86_64-unknown-linux-gnu.tar.gz cat rust-panosmcp-v0.16.2/BUILD-INFO ``` +`BUILD-INFO` is `key=value` lines: `version`, `git_commit` (the commit that +built the binary), `packaging_commit` (the checkout that produced the +archive; equal unless the binary was supplied prebuilt), `source_date_epoch`, +`target`, `binary_sha256` (of `bin/rust-panosmcp`) and a single `rustc=` line. + +### Packaging a CI-built binary + +A binary rebuilt on a workstation links a newer glibc than the LXCs have and +will not start there. Package the binary CI built instead: extract it from the +release image to `target/release/rust-panosmcp`, then + +```bash +PANOSMCP_PACKAGE_SKIP_BUILD=1 \ +PANOSMCP_BINARY_SOURCE_COMMIT=<40-hex commit that built the image> \ + scripts/build-release.sh +``` + +The commit must exist in the clone (`git fetch origin `). `rustc=` is then +recorded as `unknown (... not compiled by this script)`, never a toolchain +version, and `target` defaults to `x86_64-unknown-linux-gnu` +(`PANOSMCP_TARGET_TRIPLE` overrides). Never hand-write `BUILD-INFO`. + The build uses `Cargo.lock`, a fixed Rust MSRV, path remapping, a fixed source date, deterministic tar ordering/ownership/timestamps, and no incremental compilation. `scripts/verify-reproducible-build.sh` compiles twice in isolated diff --git a/packaging/conformance.toml b/packaging/conformance.toml index 25c223f..8d125bc 100644 --- a/packaging/conformance.toml +++ b/packaging/conformance.toml @@ -4,10 +4,12 @@ service = "rust-panosmcp" config_dir = "/etc/rust-panosmcp" tokens = "/var/lib/rust-panosmcp/tokens.json" -# No supported skip-build path yet, so no honest BUILD-INFO is possible. -# R3 warns until both change together. See mecmcp's spec, "Provenance ordering". -build_info = false -skip_build_env = false +# rust-panosmcp has a supported skip-build path (PANOSMCP_PACKAGE_SKIP_BUILD) +# and scripts/build-release.sh emits an honest BUILD-INFO either way -- a real +# rustc -vV when it compiled the binary, "unknown (...)" when it did not. R3 is +# therefore fatal rather than a warning. See mecmcp#355. +build_info = true +skip_build_env = "PANOSMCP_PACKAGE_SKIP_BUILD" units = ["packaging/systemd/rust-panosmcp.service"] diff --git a/packaging/tests/skip-build-provenance.sh b/packaging/tests/skip-build-provenance.sh new file mode 100755 index 0000000..52601f7 --- /dev/null +++ b/packaging/tests/skip-build-provenance.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +# Regression guard for mecmcp#355: BUILD-INFO from the skip-build path must not +# name a toolchain that never compiled the binary. Needs target/release/rust-panosmcp. +set -euo pipefail + +repo_root=$(git rev-parse --show-toplevel) +cd "$repo_root" +[[ -x target/release/rust-panosmcp ]] || { + echo 'target/release/rust-panosmcp must already be built before this test runs' >&2 + exit 1 +} + +expected_sha=$(sha256sum target/release/rust-panosmcp | cut -d' ' -f1) +commit=$(git rev-parse HEAD) +work=$(mktemp -d) +trap 'rm -rf -- "$work"' EXIT + +# Negative: a missing or malformed source commit must be refused. +for bad in '' 'abc123' "${commit^^}"; do + if PANOSMCP_ALLOW_DIRTY=1 PANOSMCP_PACKAGE_SKIP_BUILD=1 \ + PANOSMCP_BINARY_SOURCE_COMMIT="$bad" PANOSMCP_OUTPUT_DIR="$work/neg" \ + scripts/build-release.sh >/dev/null 2>&1; then + echo "skip-build accepted a bad PANOSMCP_BINARY_SOURCE_COMMIT: '$bad'" >&2 + exit 1 + fi +done + +PANOSMCP_ALLOW_DIRTY=1 PANOSMCP_PACKAGE_SKIP_BUILD=1 \ +PANOSMCP_BINARY_SOURCE_COMMIT="$commit" PANOSMCP_OUTPUT_DIR="$work/out" \ + scripts/build-release.sh >/dev/null + +mapfile -t archives < <(find "$work/out" -maxdepth 1 -name 'rust-panosmcp-v*.tar.gz') +[[ ${#archives[@]} -eq 1 ]] || { echo "expected one archive, found ${#archives[@]}" >&2; exit 1; } +mkdir "$work/x" +tar -xzf "${archives[0]}" -C "$work/x" +build_info=$(find "$work/x" -maxdepth 2 -name BUILD-INFO) + +recorded_rustc=$(sed -n 's/^rustc=//p' "$build_info") +case "$recorded_rustc" in + unknown\ \(*) ;; + *) echo "skip-build rustc= must start with 'unknown ('; got: $recorded_rustc" >&2; exit 1 ;; +esac +if grep -Eq 'rustc [0-9]+\.[0-9]+\.[0-9]+' <<<"$recorded_rustc"; then + echo "skip-build BUILD-INFO names a compiler version: $recorded_rustc" >&2 + exit 1 +fi +recorded_sha=$(sed -n 's/^binary_sha256=//p' "$build_info") +[[ "$recorded_sha" == "$expected_sha" ]] || { + echo "binary_sha256 ($recorded_sha) != packaged binary ($expected_sha)" >&2 + exit 1 +} +recorded_commit=$(sed -n 's/^git_commit=//p' "$build_info") +[[ "$recorded_commit" == "$commit" ]] || { + echo "git_commit ($recorded_commit) != supplied commit ($commit)" >&2 + exit 1 +} +echo 'skip-build provenance is honest' diff --git a/scripts/build-release.sh b/scripts/build-release.sh index 94071a1..6c9ef62 100755 --- a/scripts/build-release.sh +++ b/scripts/build-release.sh @@ -16,11 +16,39 @@ if [[ -z "$VERSION" ]]; then echo "workspace version not found" >&2 exit 1 fi -COMMIT="$(git rev-parse --verify HEAD)" -SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-$(git show -s --format=%ct HEAD)}" -TARGET_TRIPLE="${PANOSMCP_TARGET_TRIPLE:-$(rustc -vV | sed -n 's/^host: //p')}" +PACKAGING_COMMIT="$(git rev-parse --verify HEAD)" +SKIP_BUILD="${PANOSMCP_PACKAGE_SKIP_BUILD:-0}" TARGET_DIR="${PANOSMCP_TARGET_DIR:-$ROOT/target}" OUTPUT_DIR="${PANOSMCP_OUTPUT_DIR:-$ROOT/dist}" +if [[ "$SKIP_BUILD" == "1" ]]; then + # Packaging a CI-built binary: the binary is not ours to compile, so the + # local rustc host says nothing about it, and the release image is x86_64. + TARGET_TRIPLE="${PANOSMCP_TARGET_TRIPLE:-x86_64-unknown-linux-gnu}" + # Workstation glibc is newer than the LXCs', so a rebuilt binary will not + # start there; package the release image's binary instead. + if [[ ! -x "$TARGET_DIR/release/rust-panosmcp" ]]; then + echo "PANOSMCP_PACKAGE_SKIP_BUILD=1 but $TARGET_DIR/release/rust-panosmcp is missing or not executable." >&2 + echo "Extract it from the release image, e.g.:" >&2 + echo " docker create --name pm ghcr.io/mechubsec/rust-panosmcp:" >&2 + echo " docker cp pm:/usr/local/bin/rust-panosmcp $TARGET_DIR/release/rust-panosmcp; docker rm pm" >&2 + exit 1 + fi + if [[ ! "${PANOSMCP_BINARY_SOURCE_COMMIT:-}" =~ ^[0-9a-f]{40}$ ]]; then + echo "PANOSMCP_PACKAGE_SKIP_BUILD=1 requires PANOSMCP_BINARY_SOURCE_COMMIT: the full lowercase 40-hex commit that built the binary" >&2 + exit 1 + fi + if ! COMMIT="$(git rev-parse "${PANOSMCP_BINARY_SOURCE_COMMIT}^{commit}" 2>/dev/null)"; then + echo "commit $PANOSMCP_BINARY_SOURCE_COMMIT is not in this clone; run: git fetch origin $PANOSMCP_BINARY_SOURCE_COMMIT" >&2 + exit 1 + fi + TOOLCHAIN_CHANNEL="$(sed -n 's/^channel *= *"\([^"]*\)".*/\1/p' rust-toolchain.toml 2>/dev/null | head -n 1)" + RUSTC_LINE="unknown (binary supplied prebuilt via PANOSMCP_PACKAGE_SKIP_BUILD; pinned toolchain ${TOOLCHAIN_CHANNEL:-unspecified} at ${COMMIT:0:12}; not compiled by this script)" +else + COMMIT="$PACKAGING_COMMIT" + TARGET_TRIPLE="${PANOSMCP_TARGET_TRIPLE:-$(rustc -vV | sed -n 's/^host: //p')}" + RUSTC_LINE="$(rustc -vV | tr '\n' ' ' | sed 's/ *$//')" +fi +SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-$(git show -s --format=%ct "$COMMIT")}" ARCHIVE="rust-panosmcp-v${VERSION}-${TARGET_TRIPLE}.tar.gz" BUILD_ARGS=(--release --locked --bin rust-panosmcp) if [[ "${PANOSMCP_OFFLINE:-0}" == "1" ]]; then @@ -29,7 +57,9 @@ fi export SOURCE_DATE_EPOCH CARGO_INCREMENTAL=0 CARGO_TARGET_DIR="$TARGET_DIR" export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--remap-path-prefix=$ROOT=/usr/src/rust-panosmcp" -cargo build "${BUILD_ARGS[@]}" +if [[ "$SKIP_BUILD" != "1" ]]; then + cargo build "${BUILD_ARGS[@]}" +fi STAGING="$(mktemp -d)" trap 'rm -rf "$STAGING"' EXIT @@ -50,9 +80,11 @@ install -m 0644 config/devices.example.json \ { printf 'version=%s\n' "$VERSION" printf 'git_commit=%s\n' "$COMMIT" + printf 'packaging_commit=%s\n' "$PACKAGING_COMMIT" printf 'source_date_epoch=%s\n' "$SOURCE_DATE_EPOCH" printf 'target=%s\n' "$TARGET_TRIPLE" - rustc -vV + printf 'binary_sha256=%s\n' "$(sha256sum "$PKG/bin/rust-panosmcp" | cut -d' ' -f1)" + printf 'rustc=%s\n' "$RUSTC_LINE" } >"$PKG/BUILD-INFO" mkdir -p "$OUTPUT_DIR" From a4206c9ddcce962e1abdf11f689a54c462431935 Mon Sep 17 00:00:00 2001 From: fastrevmd-lab Date: Fri, 23 Oct 2026 18:35:54 -0400 Subject: [PATCH 2/2] packaging: read version and toolchain pin at the binary's source commit Codex review of the skip-build path: the archive took VERSION from the packaging checkout and the toolchain pin from its rust-toolchain.toml, so an older CI binary could ship under a newer version's name with a pin it was never built with. Both now come from PANOSMCP_BINARY_SOURCE_COMMIT, and the binary's own --version must match or packaging refuses. The provenance test gains a stub-binary negative case for the version check. Co-Authored-By: Claude Opus 5.5 --- packaging/tests/skip-build-provenance.sh | 12 ++++++++++++ scripts/build-release.sh | 21 +++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/packaging/tests/skip-build-provenance.sh b/packaging/tests/skip-build-provenance.sh index 52601f7..3ef82b0 100755 --- a/packaging/tests/skip-build-provenance.sh +++ b/packaging/tests/skip-build-provenance.sh @@ -25,6 +25,18 @@ for bad in '' 'abc123' "${commit^^}"; do fi done +# Negative: a binary whose --version disagrees with the source commit's Cargo.toml +# must be refused, or an old binary ships under a new version's name. +mkdir -p "$work/stub/release" +printf '#!/bin/sh\necho "rust-panosmcp 0.0.0-stub"\n' >"$work/stub/release/rust-panosmcp" +chmod +x "$work/stub/release/rust-panosmcp" +if PANOSMCP_ALLOW_DIRTY=1 PANOSMCP_PACKAGE_SKIP_BUILD=1 PANOSMCP_TARGET_DIR="$work/stub" \ + PANOSMCP_BINARY_SOURCE_COMMIT="$commit" PANOSMCP_OUTPUT_DIR="$work/neg" \ + scripts/build-release.sh >/dev/null 2>&1; then + echo 'skip-build accepted a binary whose --version disagrees with the source commit' >&2 + exit 1 +fi + PANOSMCP_ALLOW_DIRTY=1 PANOSMCP_PACKAGE_SKIP_BUILD=1 \ PANOSMCP_BINARY_SOURCE_COMMIT="$commit" PANOSMCP_OUTPUT_DIR="$work/out" \ scripts/build-release.sh >/dev/null diff --git a/scripts/build-release.sh b/scripts/build-release.sh index 6c9ef62..568880e 100755 --- a/scripts/build-release.sh +++ b/scripts/build-release.sh @@ -41,8 +41,25 @@ if [[ "$SKIP_BUILD" == "1" ]]; then echo "commit $PANOSMCP_BINARY_SOURCE_COMMIT is not in this clone; run: git fetch origin $PANOSMCP_BINARY_SOURCE_COMMIT" >&2 exit 1 fi - TOOLCHAIN_CHANNEL="$(sed -n 's/^channel *= *"\([^"]*\)".*/\1/p' rust-toolchain.toml 2>/dev/null | head -n 1)" - RUSTC_LINE="unknown (binary supplied prebuilt via PANOSMCP_PACKAGE_SKIP_BUILD; pinned toolchain ${TOOLCHAIN_CHANNEL:-unspecified} at ${COMMIT:0:12}; not compiled by this script)" + # Version and toolchain pin describe the binary, so read them at its source + # commit, not from this checkout, and refuse a binary that disagrees. + VERSION="$(git show "$COMMIT:Cargo.toml" | sed -n 's/^version = "\([^"]*\)"/\1/p' | head -n 1)" + # shortcut: executes the binary, so packaging must run on a host that can run it + # (the fleet and packaging hosts are x86_64 Linux); fails closed otherwise. + BINARY_VERSION="$("$TARGET_DIR/release/rust-panosmcp" --version | awk '{print $2}')" || { + echo "cannot run $TARGET_DIR/release/rust-panosmcp to verify its version; package on a host that can execute it" >&2 + exit 1 + } + if [[ -z "$VERSION" || "$BINARY_VERSION" != "$VERSION" ]]; then + echo "binary reports version '$BINARY_VERSION' but ${COMMIT:0:12} declares '$VERSION'; wrong binary or wrong PANOSMCP_BINARY_SOURCE_COMMIT" >&2 + exit 1 + fi + TOOLCHAIN_CHANNEL="$(git show "$COMMIT:rust-toolchain.toml" 2>/dev/null | sed -n 's/^channel *= *"\([^"]*\)".*/\1/p' | head -n 1)" + if [[ -z "$TOOLCHAIN_CHANNEL" ]]; then + echo "no toolchain channel in rust-toolchain.toml at ${COMMIT:0:12}" >&2 + exit 1 + fi + RUSTC_LINE="unknown (binary supplied prebuilt via PANOSMCP_PACKAGE_SKIP_BUILD; pinned toolchain $TOOLCHAIN_CHANNEL at ${COMMIT:0:12}; not compiled by this script)" else COMMIT="$PACKAGING_COMMIT" TARGET_TRIPLE="${PANOSMCP_TARGET_TRIPLE:-$(rustc -vV | sed -n 's/^host: //p')}"