diff --git a/README.md b/README.md index 17768aa..7aa9aff 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ support is best effort), Caddy and Pebble on PATH: `nix develop .#ci`. A release is a signed manifest, not a binary: `SHA256SUMS` signed by `domi-release` (through Custos) over the release notes, screenshots of the UI and `ianitor-nix.json`, the NAR hashes of the Nix build at the tagged commit. -Anyone can rebuild the pinned commit and compare the hashes: [docs/verify.md](docs/verify.md). What is checked +Anyone can rebuild the tagged commit and compare the hashes: [docs/verify.md](docs/verify.md). What is checked so far is narrower than "reproducible": the output derivations are rebuilt once and compared, with dependencies from the binary cache, and that has not run yet; the first pin needs a machine with Nix. diff --git a/docs/launch/blog-post.md b/docs/launch/blog-post.md index 797582a..9425ffb 100644 --- a/docs/launch/blog-post.md +++ b/docs/launch/blog-post.md @@ -38,7 +38,7 @@ how it is run, not for a number. ## Verifiable, and signed Every release is a `SHA256SUMS` signed through Custos with my release key, over the notes, screenshots of the UI, -and the NAR hashes of the Nix build. Rebuild the pinned commit and compare (docs/verify.md tells you how). +and the NAR hashes of the Nix build. Rebuild the tagged commit and compare (docs/verify.md tells you how). [Before posting: say "reproducible" only once two independent builds have matched; until then, what is checked is one rebuild of the output derivations, with dependencies from the binary cache.] diff --git a/docs/release.md b/docs/release.md index ea03be8..ee89fd9 100644 --- a/docs/release.md +++ b/docs/release.md @@ -22,13 +22,13 @@ are on every step's PATH). | `check`, `test` | `svelte-check` and the vitest click smoke test of the web UI the shots show | | | `notes` | `fabrica notes` (the range since the previous `v*` tag; the first release covers the whole history) | `target/notes/release-notes.md`, `release-notes.json` | | `shots` | `node apps/web/scripts/shots.mjs` (below) | `target/aula/aula-.png`, `aula.json` | -| `pin` | `node scripts/release-pin.mjs `: the Nix pin committed before the tag (`.fabrica/nix/pin.json`, by `scripts/nix-pin.sh` on Linux); refuses a missing pin, a pin of another version, and one made from other code than the tag's; publishes the pinned commit | `target/nix/ianitor-nix.json` | +| `pin` | `node scripts/release-pin.mjs `: the Nix pin committed before the tag (`.fabrica/nix/pin.json`, by `scripts/nix-pin.sh` on Linux); refuses a missing pin, a pin of another version, one made from other code than the tag's, and one naming a present commit of other code; publishes the tagged commit as the build reference | `target/nix/ianitor-nix.json` | | `approve` | the run's Custos approval, before anything is published | | | `publish` | the Gitea release of the tag: the notes, the shots, `aula.json` and `ianitor-nix.json`; `sums: domi-release` adds `SHA256SUMS` and `SHA256SUMS.minisig`; `release-notes.md` becomes the release's text | | **The Nix build is pinned, not shipped.** The Windows runner has no Nix and Fabrica's `SHA256SUMS` covers only the files of one `publish` step, so the release cannot carry a build made by the NixOS runner. It carries the build's -NAR hashes instead (`ianitor-nix.json`, under the signed `SHA256SUMS`): anyone rebuilds the pinned commit and +NAR hashes instead (`ianitor-nix.json`, under the signed `SHA256SUMS`): anyone rebuilds the tagged commit and compares ([verify.md](verify.md)), and the `verify-nix` pipeline does that on every `v*` tag on the NixOS runner. The `pin` step refuses a pin made from other code than the tag's (its source tree must match), which is the gate: Fabrica pipelines cannot depend on one another, so `publish` cannot wait for `verify-nix`. What "reproducible" diff --git a/docs/verify.md b/docs/verify.md index f8f0bd9..40214cb 100644 --- a/docs/verify.md +++ b/docs/verify.md @@ -3,7 +3,7 @@ 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 commit the build was made from and the NAR hash of every Nix output (`.#ianitor`, the two binaries; `.#ianitor-web`, the built UI). -Ianitor ships no binary download: you build that commit yourself (or your server does, through the NixOS module) +Ianitor ships no binary download: you build the tagged commit yourself (or your server does, through the NixOS module) and check that you got exactly the bytes the release vouches for. What is checked, and what is not yet: `scripts/nix-pin.sh` builds each output, then rebuilds the output derivation itself once more (`nix build --rebuild`) and refuses to pin it if the two differ; the dependencies come from the binary cache and are not rebuilt. The `verify-nix` pipeline does the same on the NixOS @@ -32,8 +32,11 @@ sha256sum -c --ignore-missing SHA256SUMS # every downloaded file: OK ## 2. The build -`ianitor-nix.json` names the commit the hashes were built from (`commit`; the tag's own commit, `taggedCommit`, -differs from it at most by the pin file), the nixpkgs revision of its flake.lock, and the hashes: +`ianitor-nix.json` names the commit to build, `taggedCommit` (also in `flake`), the nixpkgs revision of its +flake.lock, and the hashes. `commit` is where `nix-pin.sh` ran, for the record: the release checks that the tagged +commit holds the same source (they differ at most by the pin file, which no package's source contains), and that +`commit` does too when it is present (`commitChecked`); a pin naming a commit that no longer exists is published +with `commitChecked: false`, and that is fine, because you build `taggedCommit`: ```json { "version": "1.0.0", "commit": "<40 hex>", "taggedCommit": "<40 hex>", "nixpkgs": "<40 hex>", "system": "x86_64-linux", @@ -43,7 +46,7 @@ differs from it at most by the pin file), the nixpkgs revision of its flake.lock 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) +c=$(jq -r .taggedCommit 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') @@ -57,13 +60,13 @@ hash is the content. `nix build --rebuild` builds once more locally and fails if 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/.*##')` +`rev` is the release's `taggedCommit`, `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 + tagged 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 diff --git a/scripts/release-pin.mjs b/scripts/release-pin.mjs index 9c6ec03..55c0148 100644 --- a/scripts/release-pin.mjs +++ b/scripts/release-pin.mjs @@ -9,8 +9,12 @@ // The pin is a claim about the code it was built from, so it is refused unless the tagged commit // holds exactly that code: its source tree (every tracked file except pin.json itself) must be // the one the pin recorded. That is `git diff --name-only ` being empty or only -// pin.json, checked without the pinned commit's history (a runner's clone is shallow). The -// published file names the commit the hashes were built from, not the tag's. +// pin.json, checked without the pinned commit's history (a runner's clone is shallow). +// +// The build reference verifiers use is the tagged commit: it has the pinned source by that check, +// and it surely exists. The commit the pin names is kept for the record only; when its objects +// are here it must hold the recorded source tree too (a forged commit is refused), and when they +// are not (a shallow clone, or a commit rebased away) it is published unchecked. // // node scripts/release-pin.mjs write target/nix/ianitor-nix.json // node scripts/release-pin.mjs --source-tree print that commit's source-tree hash @@ -86,15 +90,31 @@ if (here !== pin.sourceTree) { ); } +let commitChecked = false; +try { + git("cat-file", "-e", `${pin.commit}^{commit}`); + commitChecked = true; +} catch { + // Not here: informational only. +} +if (commitChecked && sourceTree(pin.commit) !== pin.sourceTree) { + fail( + `${PIN} names ${pin.commit}, which does not hold the source tree it records: ` + + `the pin was edited by hand; run scripts/nix-pin.sh again`, + ); +} + const out = { name: "Ianitor Domi", version, tag, - // The commit the hashes were built from; the tag's own commit differs at most by pin.json. - commit: pin.commit, + // Build this one (docs/verify.md): the tagged commit, whose source the pin is of. taggedCommit: commit, + flake: `git+https://gitea.marek-novak.cz/mnovak/Ianitor.git?rev=${commit}`, + // The commit nix-pin.sh ran at, for the record; checked against the source tree when present. + commit: pin.commit, + commitChecked, sourceTree: pin.sourceTree, - flake: `git+https://gitea.marek-novak.cz/mnovak/Ianitor.git?rev=${pin.commit}`, nixpkgs: pin.nixpkgs ?? null, system: pin.system, outputs: pin.outputs, @@ -102,4 +122,6 @@ const out = { }; 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}, built from ${pin.commit}, tagged at ${commit}`); +console.log( + `target/nix/ianitor-nix.json: ${version} at ${commit} (pinned at ${pin.commit}, ${commitChecked ? "checked" : "not here, unchecked"})`, +);