[fabrica] Layers and the verifiable build: the layers pipeline runs all five test layers on a NixOS runner with KVM, verify-nix rebuilds a tag and compares with its pin, the release publishes the Nix pin (ianitor-nix.json) under the signed SHA256SUMS; scripts for conformance, load and the pin; docs/verify.md

This commit is contained in:
2026-11-10 21:23:16 +01:00
parent 4692044099
commit 9ae721b79f
12 changed files with 485 additions and 3 deletions
+115
View File
@@ -0,0 +1,115 @@
#!/usr/bin/env bash
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# ROADMAP §5 layer 5: load and soak against Caddy, reproducible. Ianitor and two Caddys (as Go
# starts it, and GOMAXPROCS=2 to match edge's two Pingora worker threads) serve the same route
# (tests/diff/src/bin/pair.rs) to the same upstream; oha drives each in turn. Results are
# committed as data: bench/results/<date>-<label>.csv and the raw oha JSON beside it.
#
# scripts/bench.sh [label] # needs caddy, oha, jq on PATH
# nix shell nixpkgs#caddy nixpkgs#oha nixpkgs#jq -c scripts/bench.sh wsl2-ryzen
#
# Environment: DURATION (each load run, default 20s), SOAK (the soak run, default 300s; 0 skips
# it), CONNS (default "1 16 64 256"), BUILD (release or debug, default release).
# Everything listens on 127.0.0.1; the load generator shares the machine, so absolute numbers
# say more about the machine than the proxies: compare the rows, not the numbers across machines.
set -euo pipefail
root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
label=${1:-$(hostname -s 2>/dev/null || echo local)}
duration=${DURATION:-20s}
soak=${SOAK:-300}
conns=${CONNS:-"1 16 64 256"}
profile=${BUILD:-release}
for tool in caddy oha jq; do
command -v "$tool" >/dev/null || { echo "missing: $tool" >&2; exit 2; }
done
flag=--release
[ "$profile" = debug ] && flag=
cargo build $flag -q -p ianitor-diff --bin ianitor-pair
bin="${CARGO_TARGET_DIR:-$root/target}/$profile/ianitor-pair"
stamp=$(date -u +%Y-%m-%d)
dir="$root/bench/results"
raw="$dir/$stamp-$label"
mkdir -p "$raw"
csv="$dir/$stamp-$label.csv"
info=$(mktemp)
"$bin" --caddy "$(command -v caddy)" >"$info" &
pair=$!
trap 'kill $pair 2>/dev/null; wait $pair 2>/dev/null; rm -f "$info"' EXIT
for _ in $(seq 1 100); do
[ -s "$info" ] && break
sleep 0.2
done
[ -s "$info" ] || { echo "ianitor-pair did not start" >&2; exit 1; }
# The machine, for the record.
{
echo "label: $label"
echo "date: $(date -u +%Y-%m-%dT%H:%M:%SZ)"
echo "kernel: $(uname -sr)"
grep -m1 'model name' /proc/cpuinfo 2>/dev/null | sed 's/^.*: /cpu: /' || true
echo "cpus: $(nproc)"
grep -m1 MemTotal /proc/meminfo 2>/dev/null | sed 's/^MemTotal: */memory: /' || true
grep -qi microsoft /proc/version 2>/dev/null && echo "virtualisation: WSL2" || true
echo "build: $(jq -r .build "$info"); edge worker threads: $(jq -r .edge_threads "$info")"
echo "caddy: $(jq -r .caddy_version "$info")"
echo "oha: $(oha --version 2>/dev/null | head -1)"
echo "duration: $duration per run; soak: ${soak}s"
} >"$raw/machine.txt"
# The process to sample for memory: edge runs inside ianitor-pair; each Caddy is a child of it.
pid_of() {
local port=$1
ss -Hltnp "sport = :$port" 2>/dev/null | grep -Eo 'pid=[0-9]+' | head -1 | cut -d= -f2
}
rss_kb() { awk '/VmRSS/ {print $2}' "/proc/$1/status" 2>/dev/null || echo 0; }
echo "engine,scenario,connections,duration_s,requests,rps,p50_ms,p90_ms,p99_ms,max_ms,success_rate,non_2xx,rss_kb_after" >"$csv"
run() { # engine scenario conns duration url [oha args...]
local engine=$1 scenario=$2 c=$3 d=$4 url=$5
shift 5
local file="$raw/$engine-$scenario-c$c.json"
oha --no-tui --insecure -j -c "$c" -z "$d" "$@" "$url" >"$file" 2>/dev/null || true
local pid
pid=$(pid_of "$(echo "$url" | sed -E 's#.*:([0-9]+)/.*#\1#')")
jq -r --arg e "$engine" --arg s "$scenario" --arg c "$c" --arg rss "$(rss_kb "${pid:-0}")" '
def ms: if . == null then "" else (. * 1000 * 100 | round / 100 | tostring) end;
[$e, $s, $c,
(.summary.total | . * 100 | round / 100 | tostring),
((.statusCodeDistribution // {}) | to_entries | map(.value) | add // 0 | tostring),
(.summary.requestsPerSec | round | tostring),
(.latencyPercentiles.p50 | ms), (.latencyPercentiles.p90 | ms), (.latencyPercentiles.p99 | ms),
(.summary.slowest | ms),
(.summary.successRate | tostring),
((.statusCodeDistribution // {}) | to_entries | map(select(.key | startswith("2") | not) | .value) | add // 0 | tostring),
$rss] | join(",")' "$file" >>"$csv"
tail -1 "$csv"
}
for engine in ianitor caddy caddy_gomaxprocs2; do
https=$(jq -r ".$engine.https" "$info")
http=$(jq -r ".$engine.http" "$info")
url="https://localhost:${https##*:}/"
for c in $conns; do
run "$engine" https-h1-keepalive "$c" "$duration" "$url"
run "$engine" https-h2 "$c" "$duration" "$url" --http2
done
# A new TLS connection per request: the handshake dominates.
run "$engine" https-h1-new-conn 16 "$duration" "$url" --disable-keepalive
# The plain-HTTP listener's redirect (no upstream).
run "$engine" http-redirect 64 "$duration" "http://localhost:${http##*:}/" --redirect 0
done
if [ "$soak" -gt 0 ]; then
for engine in ianitor caddy; do
https=$(jq -r ".$engine.https" "$info")
run "$engine" soak-https-h1 32 "${soak}s" "https://localhost:${https##*:}/"
done
fi
echo "results: $csv"
+79
View File
@@ -0,0 +1,79 @@
#!/usr/bin/env bash
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# ROADMAP §5 layer 2: protocol conformance, Ianitor and Caddy side by side on the same routes
# (tests/diff/src/bin/pair.rs): h2spec (HTTP/2, RFC 9113 and HPACK) and testssl.sh (TLS) against
# each. Raw outputs go to bench/conformance/<engine>-*.{txt,json}; the summary table to stdout.
#
# scripts/conformance.sh # needs caddy, h2spec, testssl.sh, jq on PATH
# nix shell nixpkgs#caddy nixpkgs#h2spec nixpkgs#testssl nixpkgs#jq -c scripts/conformance.sh
#
# Exit status: 1 if Ianitor fails an h2spec case Caddy passes, or testssl.sh rates Ianitor's
# TLS below Caddy's (a regression against the fallback); the rest is reported, not enforced.
# Everything listens on 127.0.0.1.
set -euo pipefail
root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
out="$root/bench/conformance"
mkdir -p "$out"
for tool in caddy h2spec jq; do
command -v "$tool" >/dev/null || { echo "missing: $tool" >&2; exit 2; }
done
testssl=$(command -v testssl.sh || command -v testssl || true)
[ -n "$testssl" ] || { echo "missing: testssl.sh" >&2; exit 2; }
profile=${BUILD:-release}
flag=--release
[ "$profile" = debug ] && flag=
cargo build $flag -q -p ianitor-diff --bin ianitor-pair
bin="${CARGO_TARGET_DIR:-$root/target}/$profile/ianitor-pair"
info=$(mktemp)
"$bin" --caddy "$(command -v caddy)" >"$info" &
pair=$!
trap 'kill $pair 2>/dev/null; wait $pair 2>/dev/null; rm -f "$info"' EXIT
for _ in $(seq 1 100); do
[ -s "$info" ] && break
sleep 0.2
done
[ -s "$info" ] || { echo "ianitor-pair did not start" >&2; exit 1; }
port() { jq -r ".$1.https" "$info" | sed 's/.*://'; }
status=0
printf '%-10s %-8s %s\n' engine tool result
for engine in ianitor caddy; do
p=$(port "$engine")
# h2spec names the host for SNI; `localhost` is the pair's only host.
h2spec -h localhost -p "$p" -t -k -o 5 >"$out/$engine-h2spec.txt" 2>&1 || true
summary=$(grep -Eo '[0-9]+ tests, [0-9]+ passed, [0-9]+ skipped, [0-9]+ failed' "$out/$engine-h2spec.txt" | tail -1)
printf '%-10s %-8s %s\n' "$engine" h2spec "${summary:-no summary (see $out/$engine-h2spec.txt)}"
# The failed cases, by id, for the comparison below.
grep -E '^\s+×' -B0 "$out/$engine-h2spec.txt" | sed -E 's/^\s+× //' | sort >"$out/$engine-h2spec-failed.txt" || true
"$testssl" --quiet --color 0 --warnings off --ip 127.0.0.1 --add-ca "$(jq -r .ca "$info")" \
--jsonfile "$out/$engine-testssl.json" --overwrite "https://localhost:$p" \
>"$out/$engine-testssl.txt" 2>&1 || true
grade=$(jq -r '[.[] | select(.id=="overall_grade")][0].finding // "n/a"' "$out/$engine-testssl.json" 2>/dev/null || echo n/a)
bad=$(jq -r '[.[] | select(.severity=="HIGH" or .severity=="CRITICAL")] | length' "$out/$engine-testssl.json" 2>/dev/null || echo "?")
printf '%-10s %-8s %s\n' "$engine" testssl "grade $grade, $bad findings HIGH or CRITICAL"
done
# A case Caddy passes and Ianitor fails is a regression against the fallback.
regressions=$(comm -23 "$out/ianitor-h2spec-failed.txt" "$out/caddy-h2spec-failed.txt" || true)
if [ -n "$regressions" ]; then
echo "h2spec cases Ianitor fails and Caddy passes:" >&2
echo "$regressions" >&2
status=1
fi
rank() { case "$1" in A+) echo 7;; A) echo 6;; A-) echo 5;; B) echo 4;; C) echo 3;; D) echo 2;; E) echo 1;; *) echo 0;; esac; }
gi=$(jq -r '[.[] | select(.id=="overall_grade")][0].finding // ""' "$out/ianitor-testssl.json" 2>/dev/null || true)
gc=$(jq -r '[.[] | select(.id=="overall_grade")][0].finding // ""' "$out/caddy-testssl.json" 2>/dev/null || true)
if [ "$(rank "$gi")" -lt "$(rank "$gc")" ]; then
echo "testssl.sh grades Ianitor ($gi) below Caddy ($gc)" >&2
status=1
fi
jq -c '{build, caddy_version, edge_threads}' "$info" >"$out/run.json"
exit $status
+59
View File
@@ -0,0 +1,59 @@
#!/usr/bin/env bash
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# The verifiable Nix build (ROADMAP §6 phase 4, docs/verify.md): build .#ianitor and
# .#ianitor-web, build them a second time from scratch (`--rebuild`: Nix fails if the bytes
# differ), and record each output's store path and NAR hash in .fabrica/nix/pin.json. The release
# pipeline publishes that pin, with the tag's commit, as ianitor-nix.json under SHA256SUMS signed
# by domi-release; anyone who builds the tag gets the same NAR hashes.
#
# scripts/nix-pin.sh # write .fabrica/nix/pin.json (commit it before tagging)
# scripts/nix-pin.sh --check # rebuild and compare with the committed pin; 1 if different
#
# Linux with Nix (flakes). The pin lies outside every package's source, so committing it does not
# change what it pins.
set -euo pipefail
root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
cd "$root"
mode=${1:-write}
pin=.fabrica/nix/pin.json
nf=(--extra-experimental-features "nix-command flakes")
system=$(nix "${nf[@]}" eval --raw --impure --expr builtins.currentSystem)
version=$(sed -n '/^\[workspace.package\]/,/^\[/s/^version = "\(.*\)"/\1/p' Cargo.toml)
entries=()
for attr in ianitor ianitor-web; do
path=$(nix "${nf[@]}" build ".#$attr" --no-link --print-out-paths)
# A second, independent build of the same derivation; Nix compares the outputs bit for bit.
if ! nix "${nf[@]}" build ".#$attr" --rebuild --no-link >/dev/null 2>"$root/target-nix-rebuild.log"; then
echo "$attr is not reproducible: a rebuild gave other bytes" >&2
cat "$root/target-nix-rebuild.log" >&2
rm -f "$root/target-nix-rebuild.log"
exit 1
fi
rm -f "$root/target-nix-rebuild.log"
nar=$(nix "${nf[@]}" path-info --json "$path" | jq -r 'if type == "array" then .[0].narHash else .[].narHash end')
size=$(nix "${nf[@]}" path-info --json "$path" | jq -r 'if type == "array" then .[0].narSize else .[].narSize end')
entries+=("$(jq -cn --arg a "$attr" --arg p "$path" --arg h "$nar" --argjson s "$size" \
'{($a): {storePath: $p, narHash: $h, narSize: $s}}')")
echo "$attr: $path $nar (rebuilt: identical)"
done
new=$(printf '%s\n' "${entries[@]}" | jq -s --arg v "$version" --arg sys "$system" \
'{version: $v, system: $sys, outputs: add}')
if [ "$mode" = --check ]; then
[ -f "$pin" ] || { echo "no $pin to check" >&2; exit 1; }
if [ "$(jq -S . "$pin")" != "$(jq -S . <<<"$new")" ]; then
echo "the build differs from $pin:" >&2
diff <(jq -S . "$pin") <(jq -S . <<<"$new") >&2 || true
exit 1
fi
echo "matches $pin"
else
mkdir -p "$(dirname "$pin")"
jq -S . <<<"$new" >"$pin"
echo "wrote $pin"
fi
+57
View File
@@ -0,0 +1,57 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// The release's Nix pin (docs/verify.md): .fabrica/nix/pin.json, written by scripts/nix-pin.sh on
// Linux and committed before tagging, becomes target/nix/ianitor-nix.json with the tag and the
// commit, published under SHA256SUMS signed by domi-release. Refuses a pin of another version.
// node scripts/release-pin.mjs <X.Y.Z> <tag> <commit>
// Exit codes: 0 written, 1 no pin or a pin of another version, 2 usage.
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const repo = resolve(dirname(fileURLToPath(import.meta.url)), "..");
const [version, tag, commit] = process.argv.slice(2);
if (
process.argv.length !== 5 ||
!/^\d+\.\d+\.\d+$/.test(version) ||
!/^[0-9a-f]{40}$/.test(commit ?? "")
) {
console.error("usage: node scripts/release-pin.mjs <X.Y.Z> <tag> <commit sha>");
process.exit(2);
}
let pin;
try {
pin = JSON.parse(readFileSync(join(repo, ".fabrica/nix/pin.json"), "utf8"));
} catch (e) {
console.error(`no usable .fabrica/nix/pin.json (run scripts/nix-pin.sh on Linux and commit it): ${e.message}`);
process.exit(1);
}
if (pin.version !== version) {
console.error(`.fabrica/nix/pin.json is for ${pin.version}, the tag is ${version}: run scripts/nix-pin.sh again`);
process.exit(1);
}
for (const attr of ["ianitor", "ianitor-web"]) {
const o = pin.outputs?.[attr];
if (!o || !/^\/nix\/store\/[0-9a-z]{32}-/.test(o.storePath) || !/^sha256[-:][A-Za-z0-9+/=]{43,52}$/.test(o.narHash)) {
console.error(`.fabrica/nix/pin.json: ${attr} has no store path and NAR hash`);
process.exit(1);
}
}
const out = {
name: "Ianitor Domi",
version,
tag,
commit,
flake: `git+https://gitea.marek-novak.cz/mnovak/Ianitor.git?rev=${commit}`,
system: pin.system,
outputs: pin.outputs,
verify: "docs/verify.md",
};
mkdirSync(join(repo, "target/nix"), { recursive: true });
writeFileSync(join(repo, "target/nix/ianitor-nix.json"), JSON.stringify(out, null, 2) + "\n");
console.log(`target/nix/ianitor-nix.json: ${version} at ${commit}`);