diff --git a/.fabrica/artifex/layers.yaml b/.fabrica/artifex/layers.yaml new file mode 100644 index 0000000..18564ff --- /dev/null +++ b/.fabrica/artifex/layers.yaml @@ -0,0 +1,39 @@ +# Ianitor Domi: the five test layers (ROADMAP §5) on a push to main, or by hand. Layer 1 (the differential +# suite against Caddy) runs inside the workspace tests; layer 2 is scripts/conformance.sh (h2spec, testssl.sh); +# layer 3 tests/fuzz/run.sh (cargo-fuzz, 2 minutes a target; any crash fails); layer 4 the NixOS VM tests; +# layer 5 scripts/bench.sh (load and a 5-minute soak against Caddy; results kept as artifacts). +# Runner: label `nixos`, on a host with /dev/kvm and Nix's `kvm` system feature (the VM tests; on Hyper-V, +# nested virtualisation on), outbound HTTPS (crates.io, cache.nixos.org) and about 20 GB free. Every tool comes +# from the flake's `ci` shell, so the runner needs only Nix with flakes. +name: layers +on: + push: [main] + manual: true +runner: nixos +env: + CARGO_TERM_COLOR: "never" + CARGO_BUILD_JOBS: "8" +steps: + - id: workspace-tests + run: nix --extra-experimental-features "nix-command flakes" develop .#ci -c cargo test --workspace --no-fail-fast + - id: conformance + needs: [workspace-tests] + run: nix --extra-experimental-features "nix-command flakes" develop .#ci -c scripts/conformance.sh + artifacts: ["bench/conformance/*"] + - id: fuzz + needs: [workspace-tests] + run: nix --extra-experimental-features "nix-command flakes" develop .#ci -c tests/fuzz/run.sh 120 + - id: vm-apply-reverts + nix: .#checks.x86_64-linux.vm-apply-reverts + - id: vm-engine-switch + nix: .#checks.x86_64-linux.vm-engine-switch + - id: vm-intermediate-renewal + nix: .#checks.x86_64-linux.vm-intermediate-renewal + - id: vm-control-loopback + nix: .#checks.x86_64-linux.vm-control-loopback + - id: vm-sockets + nix: .#checks.x86_64-linux.vm-sockets + - id: load + needs: [conformance, fuzz] + run: nix --extra-experimental-features "nix-command flakes" develop .#ci -c scripts/bench.sh fabrica-runner + artifacts: ["bench/results/**"] diff --git a/.fabrica/artifex/release.yaml b/.fabrica/artifex/release.yaml index e05263b..748ab88 100644 --- a/.fabrica/artifex/release.yaml +++ b/.fabrica/artifex/release.yaml @@ -6,6 +6,9 @@ # `notes` is Fabrica's release notes since the previous v* tag (Fabrica docs/12_release_kit.md); `shots` takes the # same files as `fabrica aula shots` (core docs/FORMATS.md, "Fabrica: the Aula page") from the built web UI against # the demo control plane with invented data, in headless Edge. No landing page while app.yaml has no `aula: true`. +# `pin` publishes the Nix build's NAR hashes (.fabrica/nix/pin.json, written by scripts/nix-pin.sh on Linux and +# committed before the tag) with the tag's commit as ianitor-nix.json, so SHA256SUMS also vouches for the build +# anyone can repeat (docs/verify.md); the `verify-nix` pipeline rebuilds the tag on the NixOS runner and compares. name: release on: tag: "v*" @@ -29,8 +32,12 @@ steps: needs: [check, test] run: node apps/web/scripts/shots.mjs artifacts: ["target/aula/aula-*.png", "target/aula/aula.json"] + - id: pin + needs: [version] + run: node scripts/release-pin.mjs ${{ version }} ${{ tag }} ${{ commit }} + artifacts: ["target/nix/ianitor-nix.json"] - id: approve - needs: [version, notes, shots] + needs: [version, notes, shots, pin] approve: "Publish Ianitor ${{ tag }}: its notes and screenshots?" - id: publish needs: [approve] @@ -41,4 +48,5 @@ steps: - "**/release-notes.json" - "**/aula-*.png" - "**/aula.json" + - "**/ianitor-nix.json" sums: domi-release diff --git a/.fabrica/artifex/verify-nix.yaml b/.fabrica/artifex/verify-nix.yaml new file mode 100644 index 0000000..1203a17 --- /dev/null +++ b/.fabrica/artifex/verify-nix.yaml @@ -0,0 +1,17 @@ +# Ianitor Domi: the verifiable build (docs/verify.md). On a v* tag the NixOS runner builds .#ianitor and +# .#ianitor-web from the tag (the run record keeps each output's store path and NAR hash), builds them again +# from scratch, and compares with the pin the release publishes (.fabrica/nix/pin.json at the tag); any +# difference fails the run. Runner: label `nixos`, Nix with flakes; no KVM needed. +name: verify-nix +on: + tag: "v*" + manual: true +runner: nixos +steps: + - id: ianitor + nix: .#ianitor + - id: web + nix: .#ianitor-web + - id: pin + needs: [ianitor, web] + run: nix --extra-experimental-features "nix-command flakes" develop .#ci -c scripts/nix-pin.sh --check diff --git a/deploy/nixos/package.nix b/deploy/nixos/package.nix index 65aae88..5874f2b 100644 --- a/deploy/nixos/package.nix +++ b/deploy/nixos/package.nix @@ -9,7 +9,8 @@ rustPlatform.buildRustPackage { pname = "ianitor"; - version = "0.1.0"; + # One version, the workspace's (scripts/check-version.mjs checks the rest). + version = (lib.importTOML ../../Cargo.toml).workspace.package.version; src = lib.fileset.toSource { root = ../..; @@ -19,6 +20,8 @@ rustPlatform.buildRustPackage { ../../crates ../../tests/diff ../../tests/support + # The fuzz crate is a workspace member; its cargo-fuzz project is not (own workspace). + (lib.fileset.difference ../../tests/fuzz ../../tests/fuzz/fuzz) ]; }; diff --git a/deploy/nixos/web.nix b/deploy/nixos/web.nix index f42e8a5..b82e185 100644 --- a/deploy/nixos/web.nix +++ b/deploy/nixos/web.nix @@ -8,7 +8,7 @@ stdenv.mkDerivation (finalAttrs: { pname = "ianitor-web"; - version = "0.1.0"; + version = (lib.importJSON ../../apps/web/package.json).version; src = lib.fileset.toSource { root = ../..; diff --git a/docs/domi-release.pub b/docs/domi-release.pub new file mode 100644 index 0000000..4bea412 --- /dev/null +++ b/docs/domi-release.pub @@ -0,0 +1,2 @@ +untrusted comment: minisign public key ABD87B469ADF4BE4 +RWTkS9+aRnvYq1si0VvyJFeEJf7oQ3Dsadl0/fI64nuVIaz286PGiyPe diff --git a/docs/verify.md b/docs/verify.md new file mode 100644 index 0000000..c43f5ae --- /dev/null +++ b/docs/verify.md @@ -0,0 +1,78 @@ +# Verifying a release + +Every Ianitor release on Gitea (`vX.Y.Z`) carries `SHA256SUMS` and `SHA256SUMS.minisig`, signed through Custos by +the `domi-release` key, and among the files that `SHA256SUMS` lists, `ianitor-nix.json`: the tag's commit and the +NAR hash of every Nix output (`.#ianitor`, the two binaries; `.#ianitor-web`, the built UI). Ianitor ships no +binary download: you build the tag yourself (or your server does, through the NixOS module) and check that you got +exactly the bytes the release vouches for. The build is reproducible: `scripts/nix-pin.sh` builds each output twice +from scratch and refuses to pin one whose bytes differ, and the `verify-nix` pipeline rebuilds every tag on the +NixOS runner and compares. + +## 1. The signature + +The `domi-release` public key, key id `ABD87B469ADF4BE4` (also in [domi-release.pub](domi-release.pub)): + +```text +untrusted comment: minisign public key ABD87B469ADF4BE4 +RWTkS9+aRnvYq1si0VvyJFeEJf7oQ3Dsadl0/fI64nuVIaz286PGiyPe +``` + +Take it from a source you trust more than the release page itself (Custos → *Signing keys* → *Copy minisign.pub*, +or a clone of this repository you already had). Then, in a folder with the release's files: + +```sh +minisign -Vm SHA256SUMS -p domi-release.pub # "Signature and comment signature verified" +sha256sum -c --ignore-missing SHA256SUMS # every downloaded file: OK +``` + +(`nix shell nixpkgs#minisign` if you have no minisign. Custos signs prehashed; minisign 0.10 and later verify it.) + +## 2. The build + +`ianitor-nix.json` names the commit and the hashes: + +```json +{ "version": "1.0.0", "commit": "<40 hex>", "system": "x86_64-linux", + "outputs": { "ianitor": { "storePath": "/nix/store/…-ianitor-1.0.0", "narHash": "sha256-…" }, … } } +``` + +Build that commit and compare (Linux with Nix and flakes; nothing from Ianitor's own caches is needed): + +```sh +c=$(jq -r .commit ianitor-nix.json) +for a in ianitor ianitor-web; do + p=$(nix build "git+https://gitea.marek-novak.cz/mnovak/Ianitor.git?rev=$c#$a" --no-link --print-out-paths) + got=$(nix path-info --json "$p" | jq -r 'if type == "array" then .[0].narHash else .[].narHash end') + want=$(jq -r ".outputs[\"$a\"].narHash" ianitor-nix.json) + [ "$got" = "$want" ] && echo "$a: $got matches" || echo "$a: MISMATCH (got $got, release says $want)" +done +``` + +The store path matches too (it depends only on the derivation, so it tells you the inputs were the same); the NAR +hash is the content. `nix build --rebuild` builds once more locally and fails if your own two builds differ. + +On a server that uses the NixOS module, the running build is `services.ianitor.package`, normally +`ianitor.packages.x86_64-linux.ianitor` from the flake input pinned in the server's `flake.lock`: if that input's +`rev` is the release's commit, `nix path-info --json $(readlink -f /run/current-system/sw/bin/ianitor-edge | sed 's#/bin/.*##')` +gives the same NAR hash. + +## What this does and does not prove + +- **Proves:** the release's notes, screenshots and pin are the ones Mark approved and Custos signed; the code at the + pinned commit builds to exactly the pinned bytes, on any machine with the same nixpkgs (the flake.lock is part of + the commit). +- **Does not prove:** that the code is good (that is the five test layers' job, ROADMAP §5), nor anything about the + Nix binary cache you build with: a substituted dependency is trusted as Nix trusts it. `nix build --rebuild` and + `--option substitute false` narrow that, at the cost of building everything. + +## For Mark: making the pin before a tag + +On a Linux machine with Nix (WSL2 Debian works), at the commit to be tagged: + +```sh +scripts/nix-pin.sh # builds twice, writes .fabrica/nix/pin.json +git add .fabrica/nix/pin.json && git commit -m "[repo] Release: the Nix pin of X.Y.Z" +``` + +The pin lies outside every package's source, so the commit does not change what it pins. The `release` pipeline's +`pin` step refuses a pin of another version, so a forgotten pin stops the release before anything is published. diff --git a/flake.nix b/flake.nix index c64e23a..2d55a42 100644 --- a/flake.nix +++ b/flake.nix @@ -28,6 +28,31 @@ inherit self; }; + # The tools of the five test layers (ROADMAP §5), for scripts/*.sh, tests/fuzz/run.sh and the + # `layers` pipeline: `nix develop .#ci -c `. + devShells = forAll (pkgs: { + ci = pkgs.mkShell { + packages = with pkgs; [ + cargo + rustc + clippy + rustfmt + cargo-fuzz + cmake + pkg-config + git + jq + caddy + pebble + h2spec + testssl + oha + nodejs_22 + pnpm_11 + ]; + }; + }); + formatter = forAll (pkgs: pkgs.nixfmt-rfc-style); }; } diff --git a/scripts/bench.sh b/scripts/bench.sh new file mode 100755 index 0000000..3a9068c --- /dev/null +++ b/scripts/bench.sh @@ -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/-