aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
GitHub aien-dev/aien-sovereign-core-mv#433 (code only)
Apply it
git checkout -b patch-215cfd86fb1a48b5 66a6ba65b042cf07a74680544fcf06d0c3d1eafd curl -fsSL https://interplane.io/drakestapleton/aien-sovereign-core-mv/patches/215cfd86fb1a48b5.patch | git am
Provenance
github-import 1
aien-dev/aien-sovereign-core-mv
433
f1ec7eb445696d2456533573ba3c39a87b2e18c9
{"kind":"github-import","owner":"aien-dev","repo":"aien-sovereign-core-mv","number":433,"url":"https://github.com/aien-dev/aien-sovereign-core-mv/pull/433","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:37:09Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/.crumb b/.crumb index 73b981fb..09445d50 100644 --- a/.crumb +++ b/.crumb @@ -64,8 +64,8 @@ "generated": { "children": [ { - "digest": "83fec06a58e8f390a0760fc7a1a56f92e8a367205ede8ef2b88b02069854694f", - "last_commit": "805be03", + "digest": "de59c21bf8b5819007225986edf7a75dbe93c1203686e619e72e17a6799fa127", + "last_commit": "b6f3b2b", "name": "scripts", "purpose": "" }, @@ -76,15 +76,15 @@ "purpose": "" } ], - "children_root": "sha256:487a2166057a996c7eb8d85014729071455e5ac4b1728a0b23f5a3cbfada4ab7", - "compiled_at": "2026-10-11T14:09:39Z", + "children_root": "sha256:9b69c98f2b943ef9c4a3768e892e02b1856c6bd53647de0688f375e86e964ee1", + "compiled_at": "2026-10-11T14:27:50Z", "compiler": "crumb-compile/1", - "digest": "sha256:d1ac4244fc97cc5ef0232fdcccb46d6b9eae4817aa431964ec4e486758695028", + "digest": "sha256:1ee1320f71b3b56f7fac480ea10b808ebef8b2e06137fe9d90eb3129bd5a3335", "evidence_files": 187, "evidence_root": "sha256:27ee0353cb4d4aae2b7dbce2bfe0d9f4ef2a94cd7a4555b84684d59372503280", - "files": 3535, - "generated_at_commit": "8203055722258309c8057098f6f278e6140d91f8", - "source_tree": "sha256:f9cd239fd5912fda3861cee50e3575e99f81e919548eac4658c14b926e379bdd" + "files": 3539, + "generated_at_commit": "9dd0992a4d82f92f469484c5718239831a8e9658", + "source_tree": "sha256:b8000dd062eb5d729a60d4d818e2640143dd36d5a7da0432141c4e0859af5109" } }, "history": [], diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6d30d014..986c8dc0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,6 +33,12 @@ jobs: - name: Offline-signing handoff (ceremony rehearsal, offline sign, publish gate; throwaway keys only) run: bash scripts/test-offline-signing.sh + - name: Public-key integration (ceremony public record to trust config; throwaway keys only) + run: bash scripts/test-public-key-integration.sh + + - name: Release trust config is consistent (placeholder or pinned with matching ceremony record) + run: bash scripts/check-release-trust-config.sh + - name: Release gate negative tests (pins, digests, model inputs, signatures) run: bash scripts/test-release-checks.sh diff --git a/docs/release/CEREMONY-RUNBOOK-DRAKE.md b/docs/release/CEREMONY-RUNBOOK-DRAKE.md new file mode 100644 index 00000000..8b86c207 --- /dev/null +++ b/docs/release/CEREMONY-RUNBOOK-DRAKE.md @@ -0,0 +1,154 @@ +# Key ceremony runbook for Drake (step by step) + +This is the hands-on version of `KEY_CEREMONY.md`. It covers one evening of work, done once. It uses only what +`scripts/key-ceremony.sh` already does; nothing here is a new tool. Related: sc#118 (your checklist), sc#385 (the design), +arch#190 comment 6109731585 (your approval of the offline signing design). + +**The idea in one paragraph.** You make a secret key on a computer that is not connected to anything. The key is like a +rubber stamp that only you own. Every public release gets stamped with it. The matching "public half" (which cannot stamp, +only check a stamp) is published so anyone can check a release is genuine. The secret half never goes near the internet, +GitHub, the Spark or any AI. + +## Two kinds of files. Learn this first. + +| Kind | Files | May leave the offline computer? | +|---|---|---| +| **SECRET** | `aien_release_ed25519` (the key file, no extension) in `~/aien-key/` and the same file on each backup stick | **Never.** It stays on the offline computer and the two backup sticks. | +| **Public** | `~/aien-key/public/allowed_signers` and `~/aien-key/public/ceremony-record.txt`, and the key's `.pub` file | **Yes.** These are safe to publish and are what gets committed to the repository. | + +The `public` folder is the only thing you carry out. If you ever see a file called `aien_release_ed25519` (without +`.pub`) in the folder you are about to carry out, stop. + +The ceremony record contains your name, the witness's name, the date, the fingerprint (the key's short ID), and the test +results. It does not contain the key. Because it will be committed to a public repository, check you are happy for both +names to be public. If not, tell the engineering side before step 5; the record format is fixed by the script, so this +would need a change. + +## What you need + +- One spare laptop (the **offline computer**) with `ssh-keygen`. Mac and Linux already have it. Check in step 2. +- Three USB sticks: "AIEN KEY BACKUP 1", "AIEN KEY BACKUP 2", and "PUBLIC CARRY" (a plain one for carrying the public files out). +- A **witness**: someone present who can watch the screen. They also write the fingerprint on paper. +- Pen, paper, an envelope or two. +- A passphrase you will remember: long (a sentence of 5 or more random words is good). Do not store it on any computer. + +## Part A: Before the evening (on the Spark, or any normal connected computer) + +**Step 1. Get the script onto the PUBLIC CARRY stick.** +- Where: the Spark (connected). Changes: only the stick (adds one file). +- Type (replace the path with where the stick is mounted): + `cp ~/workspace/aien-sovereign-core/scripts/key-ceremony.sh /media/$USER/PUBLICCARRY/` + then `sha256sum /media/$USER/PUBLICCARRY/key-ceremony.sh` +- Write the first 16 characters of the long number on paper. You will compare it in step 3, to know the script on the + offline computer is the one from the repository. +- You should see: one line with a 64-character number and the file name. + +**Step 2 (optional but recommended). Practise on the Spark.** This is safe: it makes a throwaway key labelled REHEARSAL. +- Where: the Spark. Changes: creates folders under `/tmp` only. +- Type: `cd ~/workspace/aien-sovereign-core && bash scripts/key-ceremony.sh ceremony --rehearsal --out /tmp/practice --backup /tmp/practice-b1 --backup /tmp/practice-b2` +- You should see six "Step N of 6" headings with the word REHEARSAL, lines saying `good signature verifies: yes` and + `altered file is refused: yes`, then a record starting "REHEARSAL: throwaway key". Clean up: `rm -rf /tmp/practice*` +- Note: a rehearsal key can never become the release key; the checks refuse it by name. + +## Part B: The ceremony (on the OFFLINE computer, with the witness) + +**Step 3. Go offline and bring the script.** +- Where: offline computer. Changes: nothing is deleted. +- Do: unplug the network cable, turn Wi-Fi and Bluetooth off. Plug in the PUBLIC CARRY stick, copy `key-ceremony.sh` + to your home folder, and run `sha256sum ~/key-ceremony.sh`. The first 16 characters must match your paper. + Then unplug the PUBLIC CARRY stick. +- Check ssh-keygen exists: `ssh-keygen -V 2>&1 | head -1` or `ssh -V`. You should see a version line (OpenSSH_...). + +**Step 4. Plug in the two backup sticks and start the script.** Nothing is created before you confirm. +- Where: offline computer, in a terminal in the folder with the script. Changes: creates `~/aien-key` and writes to + the two sticks only after you confirm each. +- Type (on a Mac, replace `/media/` with `/Volumes/`; use the real stick names): + `bash key-ceremony.sh ceremony --out ~/aien-key --backup /media/BACKUP1/aien-key --backup /media/BACKUP2/aien-key` +- The script refuses (and says why) if: the computer still has a network route, it sees CI variables, a folder is inside + a git checkout, or `~/aien-key` is not empty. Fix what it names and run it again. Nothing was made yet. + +**Step 5. Confirm and give names.** The script asks "Is this machine offline ... and is the witness watching?" Type `yes`. +Then it asks for your full name and the witness's full name; type them. + +**Step 6. Make the key.** The script shows "Step 2 of 6: make the key" and `ssh-keygen` asks for a passphrase twice. +- The witness looks away from the keyboard. Type the passphrase twice. +- You should see a "Your identification has been saved" style message and the key files appear in `~/aien-key`. + +**Step 7. Fingerprint check by the witness.** The screen shows `Fingerprint: SHA256:...`. +- The witness copies the whole fingerprint onto paper by hand. The script asks the witness to type the LAST 8 + characters from the paper. If they do not match the screen the script stops (nothing to clean up; start again). +- Keep the paper. It is your independent copy of the fingerprint. + +**Step 8. The public-key test (automatic).** Type the passphrase when asked. +- You should see exactly: `good signature verifies: yes` and `altered file is refused: yes`. +- This proves the key can stamp, the public half can check the stamp, and a changed file is rejected. + +**Step 9. Backups, one stick at a time.** For each stick the script says "Backup N goes to ... Is that medium plugged +in?" Type `yes`. It copies the key, compares the copy to the original byte for byte, then makes the copy stamp a +test file (passphrase again) and verifies it. +- You should see for each: `backup N is an exact copy: yes`, then the two test lines again. +- If any line says STOPPED, do not use that stick. Re-run the ceremony from step 4 with a different stick. + +**Step 10. The public record.** The script prints the record and saves it in `~/aien-key/public/`. +- You should see lines starting `date-utc:`, `mode: ceremony`, `operator:`, `witness:`, `fingerprint:`, + `allowed_signers: aien-release ssh-ed25519 ...`, two `backup-N: exact copy yes; signs and verifies yes; ...` lines, and + the last line `private key: stays on the offline machine and the backups; it is not in this record`. +- The line `mode: ceremony` (not `rehearsal`) matters: the checks reject anything else. +- On paper, below the fingerprint, write the date and both names. The witness signs it. (The script does not capture + signatures; the paper is the witness's signature. Photograph it if you like; the photo is optional and is not required + by any test.) + +**Step 11. Custody (who holds what).** +- Put each backup stick in its own sealed envelope, write the date and "AIEN release key backup N", and store them in two + different physical places (for example a home safe and a bank box). They must not be kept together. +- The offline computer keeps the working copy in `~/aien-key`. Keep this computer powered off and offline when not signing. +- The passphrase lives in your head (and, if you choose, on paper in a third place). Never in a file, email or chat. +- The paper with the fingerprint goes with your records. + +**Step 12. Prove a backup works later (any time, offline computer, backup plugged in).** Safe, changes nothing: +- Type: `bash key-ceremony.sh verify-backup /media/BACKUP1/aien-key/aien_release_ed25519 ~/aien-key/public/allowed_signers` +- You should see the two test lines then `backup OK`. Do this for stick 2 too. Do it once now, then about once a year. + +**Step 13. Carry the PUBLIC half out.** +- Plug in the PUBLIC CARRY stick. Type: `cp -r ~/aien-key/public /media/PUBLICCARRY/ceremony-public` + then `ls /media/PUBLICCARRY/ceremony-public` +- You should see exactly two files: `allowed_signers` and `ceremony-record.txt`. Nothing else. Eject the stick. +- Do NOT copy `aien_release_ed25519`. Do NOT copy the backup sticks. + +## Part C: Handing the public record to the Spark (connected computer) + +**Step 14. Give the two public files to the engineering side.** +- Where: the Spark. Plug in PUBLIC CARRY and copy the folder `ceremony-public` somewhere, for example + `cp -r /media/$USER/PUBLICCARRY/ceremony-public ~/ceremony-public`. +- Compare the fingerprint in the record to your paper: `grep '^fingerprint:' ~/ceremony-public/ceremony-record.txt`. + Read it aloud against the paper with the witness. They must be identical. +- Tell the orchestrator chat: "ceremony done, public folder is at ~/ceremony-public". That is the whole handoff. No + one needs the secret key, the passphrase or the backup sticks. + +Everything the engineering side does next is in the next section. + +## Post-ceremony integration (what the engineering side does after step 14) + +One pull request, title "release: pin the public release key from the key ceremony (sc#118, sc#385)". It is made with +`scripts/apply-ceremony-public-record.sh ~/ceremony-public`, which refuses a rehearsal record, extra files, private key +material, or an inconsistent record, and ends by running `scripts/check-release-trust-config.sh`. + +| File | Change | +|---|---| +| `docs/release/allowed_signers` | the placeholder text is replaced by a short header plus **one key line** (`aien-release ssh-ed25519 ...`) | +| `install.sh` | **one line**: `AIEN_RELEASE_SIGNER='<the same key line>'` (was empty) | +| `docs/release/ceremony-record.txt` | **new**, the public record copied unchanged | + +Nothing else. You review the diff: the fingerprint in the record is checked against your paper, and CI runs +`scripts/check-release-trust-config.sh` (the key line, the installer value and the record must all agree; a fingerprint +that is not the key's, a rehearsal marker, a second key, the old internal test key, or private key material all fail). + +What proves this will work, before and after: `scripts/test-public-key-integration.sh` (runs in CI with throwaway keys) +performs this exact change from a rehearsal public folder and shows: the diff is only those three files; a release +signed by the matching key installs as `signature_check: release` and the receipt's signer fingerprint equals the +record's; a different key, a tampered archive and a tampered checksum list are refused; and nine kinds of wrong record +are refused. After the real pull request merges, the only things the real key does are sign `SHA256SUMS.txt` at each +release, offline (`KEY_CEREMONY.md`, "Signing a release"). + +**Still required before any public release** (this runbook does not change them): the physical rollback gate and the +signing and model gates. Pinning the key alone does not make a public release; no tag is created by this work. diff --git a/docs/release/KEY_CEREMONY.md b/docs/release/KEY_CEREMONY.md index 796a2cb4..3b157a73 100644 --- a/docs/release/KEY_CEREMONY.md +++ b/docs/release/KEY_CEREMONY.md @@ -57,6 +57,8 @@ It makes a throwaway key labelled REHEARSAL everywhere. It is never a release ke ## After the ceremony +Step-by-step version for the operator: `CEREMONY-RUNBOOK-DRAKE.md`. + - Hand `public/allowed_signers` and `public/ceremony-record.txt` to the orchestrator. It opens one pull request that puts that key line into `docs/release/allowed_signers` and `install.sh` (`AIEN_RELEASE_SIGNER`), and the tests prove a release sealed with it installs as `signature_check: release`. You check the fingerprint in that pull request diff --git a/docs/release/RELEASE_SIGNING.md b/docs/release/RELEASE_SIGNING.md index 83cc92fe..5acb949c 100644 --- a/docs/release/RELEASE_SIGNING.md +++ b/docs/release/RELEASE_SIGNING.md @@ -77,4 +77,6 @@ listed in `SHA256SUMS.txt` and therefore covered by the signature. - `scripts/test-install-release.sh`: signature classes, receipts, negative install rows. - `scripts/test-offline-signing.sh`: ceremony rehearsal, offline sign, publish gate refusals. - `scripts/test-release-signing-workflow.sh`: no release key in CI; release.yml only drafts; publish only after the gate. +- `scripts/test-public-key-integration.sh`: from only the ceremony's public folder: the trust-config change is a reviewable 3-file diff, the record fingerprint matches the pinned key, matching key installs as `release`, other key / tampered archive / tampered checksums refused. +- `scripts/check-release-trust-config.sh`: run in CI; passes in the PLACEHOLDER state and, after the ceremony, only if `allowed_signers`, `install.sh` and `ceremony-record.txt` agree. - `scripts/test-release-checks.sh`: signature and checksum verification, placeholder refusal. diff --git a/scripts/.crumb b/scripts/.crumb index 6b299905..e5364a06 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -4,14 +4,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-11T06:38:07Z", + "compiled_at": "2026-10-11T14:00:48Z", "compiler": "crumb-compile/1", - "digest": "sha256:83fec06a58e8f390a0760fc7a1a56f92e8a367205ede8ef2b88b02069854694f", + "digest": "sha256:de59c21bf8b5819007225986edf7a75dbe93c1203686e619e72e17a6799fa127", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 33, - "generated_at_commit": "ae1d24c157e113d7bd088deafc3d1c7a9665aab2", - "source_tree": "sha256:8f381c78e075ecfa3aef94cbf86068d40702dd43fd00ae2b4352ddd31c73d97b" + "files": 36, + "generated_at_commit": "5e44b0b8770528265d1d8d2ce07f7137b05a6fcf", + "source_tree": "sha256:91af5a64bb27722da49137d357d85749a9e0b23387d00644d793ff77f61e3cd1" } }, "parent": { diff --git a/scripts/apply-ceremony-public-record.sh b/scripts/apply-ceremony-public-record.sh new file mode 100755 index 00000000..77a7f355 --- /dev/null +++ b/scripts/apply-ceremony-public-record.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# Post-ceremony step (D3, sc#385, sc#118): turn the PUBLIC folder the operator carried out of the ceremony into the +# release trust configuration. Touches exactly three files and reads only the two public ones: +# docs/release/allowed_signers the one key line (with a short header) +# docs/release/ceremony-record.txt the public record, copied unchanged +# install.sh AIEN_RELEASE_SIGNER='<same key line>' +# scripts/apply-ceremony-public-record.sh <public-dir> [--root DIR] [--allow-rehearsal] +# <public-dir> is the ceremony's public/ folder (allowed_signers + ceremony-record.txt). Any other file, any private key +# material, a REHEARSAL record (without --allow-rehearsal) or an inconsistent record stops it. Ends by running +# scripts/check-release-trust-config.sh. It never needs, reads or asks for a private key. +set -euo pipefail +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"; REH=0; PUB="" +while [[ $# -gt 0 ]]; do + case "$1" in + --root) ROOT="$(cd "${2:?--root needs a directory}" && pwd)"; shift ;; + --allow-rehearsal) REH=1 ;; + *) [[ -z "$PUB" ]] || { echo "one public folder only" >&2; exit 2; }; PUB="$1" ;; + esac + shift +done +die() { echo "apply: REFUSED: $*" >&2; exit 1; } +[[ -d "$PUB" ]] || die "give the ceremony's public folder" +[[ "$(ls -A "$PUB" | sort | tr '\n' ' ')" == "allowed_signers ceremony-record.txt " ]] \ + || die "$PUB must hold exactly allowed_signers and ceremony-record.txt" +! grep -rq 'PRIVATE KEY' "$PUB" || die "private key material in $PUB" +line="$(grep -vE '^[[:space:]]*(#|$)' "$PUB/allowed_signers" || true)" +[[ "$(printf '%s' "$line" | grep -c .)" -eq 1 ]] || die "the public allowed_signers must hold exactly one key line" +[[ "$line" =~ ^aien-release\ ssh-ed25519\ [A-Za-z0-9+/]+=*$ ]] || die "unexpected key line format" +if [[ "$REH" == 0 ]]; then + ! grep -qi REHEARSAL "$PUB/allowed_signers" "$PUB/ceremony-record.txt" || die "this is a REHEARSAL record, not a ceremony" +fi +{ + echo "# AIEN public-release key (ssh-keygen allowed_signers format, principal aien-release)." + echo "# Pinned from the witnessed key ceremony; the public record is docs/release/ceremony-record.txt." + echo "# Only this one public key may ever be listed here. The private half is offline and is not in this repository." + [[ "$REH" == 0 ]] || echo "# REHEARSAL KEY (test only)" + echo "$line" +} > "$ROOT/docs/release/allowed_signers" +cp "$PUB/ceremony-record.txt" "$ROOT/docs/release/ceremony-record.txt" +sed -i "s|^AIEN_RELEASE_SIGNER=.*|AIEN_RELEASE_SIGNER='$line'|" "$ROOT/install.sh" +args=(--root "$ROOT"); [[ "$REH" == 0 ]] || args+=(--allow-rehearsal) +bash "$ROOT/scripts/check-release-trust-config.sh" "${args[@]}" diff --git a/scripts/check-release-trust-config.sh b/scripts/check-release-trust-config.sh new file mode 100755 index 00000000..8b7f2e86 --- /dev/null +++ b/scripts/check-release-trust-config.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash +# Consistency check for the release trust configuration (D3, sc#385 and sc#118). Reads PUBLIC files only. +# scripts/check-release-trust-config.sh [--root DIR] [--allow-rehearsal] +# Two states are valid: +# PLACEHOLDER (before the key ceremony): docs/release/allowed_signers holds no key line, install.sh has +# AIEN_RELEASE_SIGNER='' and there is no docs/release/ceremony-record.txt. +# PINNED (after the ceremony): allowed_signers holds exactly one 'aien-release ssh-ed25519 <key>' line; install.sh +# AIEN_RELEASE_SIGNER is that same line; the line is not the internal test key; docs/release/ceremony-record.txt +# exists, says mode: ceremony, its allowed_signers line equals the pinned line, and its fingerprint equals the +# fingerprint ssh-keygen computes from the pinned line; no private key material is in any of the three files. +# Anything else exits 1 and says why. --allow-rehearsal accepts a REHEARSAL record (used only by the tests). +set -euo pipefail +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"; REH=0 +while [[ $# -gt 0 ]]; do + case "$1" in + --root) ROOT="$(cd "${2:?--root needs a directory}" && pwd)"; shift ;; + --allow-rehearsal) REH=1 ;; + *) echo "usage: $0 [--root DIR] [--allow-rehearsal]" >&2; exit 2 ;; + esac + shift +done +die() { echo "trust config: REFUSED: $*" >&2; exit 1; } +AS="$ROOT/docs/release/allowed_signers"; REC="$ROOT/docs/release/ceremony-record.txt"; INST="$ROOT/install.sh" +INT="$ROOT/docs/release/internal_test_signers" +[[ -f "$AS" && -f "$INST" ]] || die "allowed_signers or install.sh is missing" +keylines() { grep -vE '^[[:space:]]*(#|$)' "$1" || true; } +pinned="$(sed -n "s/^AIEN_RELEASE_SIGNER='\(.*\)'\$/\1/p" "$INST")" +grep -qE '^AIEN_RELEASE_SIGNER=' "$INST" || die "install.sh has no AIEN_RELEASE_SIGNER line" +line="$(keylines "$AS")"; n="$(printf '%s' "$line" | grep -c . || true)" +for f in "$AS" "$INST" "$REC"; do + [[ ! -f "$f" ]] || ! grep -q 'PRIVATE KEY' "$f" || die "private key material found in $f" +done +if [[ "$n" -eq 0 ]]; then + [[ -z "$pinned" ]] || die "install.sh pins a release key but allowed_signers holds none" + [[ ! -e "$REC" ]] || die "a ceremony record exists but allowed_signers is still the placeholder" + grep -q PLACEHOLDER "$AS" || die "allowed_signers holds no key and is not labelled PLACEHOLDER" + echo "trust config: OK (PLACEHOLDER: no public-release key pinned, nothing can verify as a release)"; exit 0 +fi +[[ "$n" -eq 1 ]] || die "allowed_signers must pin exactly one key (found $n)" +[[ "$line" =~ ^aien-release\ ssh-ed25519\ [A-Za-z0-9+/]+=*$ ]] || die "the pinned line is not 'aien-release ssh-ed25519 <key>' with nothing else on it" +[[ "$pinned" == "$line" ]] || die "install.sh AIEN_RELEASE_SIGNER differs from the key line in allowed_signers" +if [[ -f "$INT" ]]; then + ik="$(keylines "$INT" | awk '{ print $3 }')" + [[ -z "$ik" || "$line" != *"$ik"* ]] || die "the pinned key is the internal test key" +fi +fp="$(printf '%s\n' "$line" | awk '{ print $2" "$3 }' | ssh-keygen -lf - 2>/dev/null | awk '{ print $2 }')" +[[ "$fp" == SHA256:* ]] || die "ssh-keygen cannot read the pinned key" +[[ -f "$REC" ]] || die "a key is pinned but docs/release/ceremony-record.txt is missing" +rv() { sed -n "s/^$1: //p" "$REC" | head -1; } +mode="$(rv mode)" +if [[ "$REH" == 1 && "$mode" == rehearsal ]]; then :; else + [[ "$mode" == ceremony ]] || die "ceremony record says mode '$mode', not 'ceremony' (a rehearsal key is never a release key)" + ! grep -qi REHEARSAL "$REC" "$AS" || die "REHEARSAL marker found; a rehearsal key is never a release key" +fi +[[ "$(rv allowed_signers)" == "$line" ]] || die "the ceremony record's allowed_signers line differs from the pinned line" +[[ "$(rv fingerprint)" == "$fp" ]] || die "the ceremony record fingerprint ($(rv fingerprint)) is not the fingerprint of the pinned key ($fp)" +for k in date-utc operator witness; do [[ -n "$(rv $k)" ]] || die "ceremony record has no $k"; done +[[ "$(grep -c 'signs and verifies yes; altered file refused yes' "$REC")" -ge 2 ]] || die "ceremony record does not show two verified backups" +grep -q 'altered file refused yes' "$REC" || die "ceremony record has no public-key verification test" +echo "trust config: OK (PINNED $fp; record: $(rv operator) with witness $(rv witness), $(rv date-utc))" diff --git a/scripts/test-public-key-integration.sh b/scripts/test-public-key-integration.sh new file mode 100755 index 00000000..97d1cadf --- /dev/null +++ b/scripts/test-public-key-integration.sh @@ -0,0 +1,126 @@ +#!/usr/bin/env bash +# Public-key integration test (D3, sc#385 and sc#118). Proves, from ONLY the public folder a ceremony produces +# (allowed_signers line + ceremony-record.txt), that the post-ceremony trust-config pull request is correct: +# (a) a release signed by the matching key installs with the real install.sh as signature_check: release, and the +# publish gate passes it +# (b) a release signed by a different key is refused by install.sh ("signature is NOT valid") and by the publish gate +# (c) a tampered archive (checksum) and a tampered checksum list (signature) are refused and install nothing +# (d) the trust-config change is a reviewable diff: one allowed_signers key line, one AIEN_RELEASE_SIGNER line, +# one new public record file, no private material +# (e) the record's fingerprint matches the pinned line, and each kind of mismatch is refused (mutants) +# The "ceremony" is the --rehearsal mode of scripts/key-ceremony.sh: a throwaway key made and deleted inside this test. +# No production key is made, read or needed. +set -euo pipefail +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +W="$(mktemp -d "${TMPDIR:-/tmp}/aien-test-pubkey.XXXXXX")" +trap 'rm -rf "$W"' EXIT +fail() { echo "FAIL: $*" >&2; exit 1; } +pass() { echo "ok: $*"; } +case "$(uname -s)" in Linux) OS=linux ;; Darwin) OS=macos ;; *) fail "unsupported OS" ;; esac +case "$(uname -m)" in x86_64|amd64) ARCH=x86_64 ;; aarch64|arm64) ARCH=aarch64 ;; *) fail "unsupported arch" ;; esac +[[ "$OS-$ARCH" != macos-aarch64 ]] || ARCH=arm64 +ASSET="sovereign-$OS-$ARCH.tar.gz" +KC=(env AIEN_CEREMONY_ASSUME_YES=1 bash "$ROOT/scripts/key-ceremony.sh") + +# The rehearsal ceremony. From here on only $PUB (public) is used to configure trust; the private key only signs. +"${KC[@]}" ceremony --rehearsal --out "$W/offline" --backup "$W/u1" --backup "$W/u2" > "$W/cer.log" 2>&1 || { tail -20 "$W/cer.log" >&2; fail "rehearsal ceremony failed"; } +PUB="$W/offline/public"; KEY="$W/offline/REHEARSAL-aien_release_ed25519" +ssh-keygen -q -t ed25519 -N '' -C other -f "$W/other" + +# A scratch copy of the repository files that matter, under git, so the change is a real diff. +T="$W/tree"; mkdir -p "$T/docs/release" "$T/scripts" +cp "$ROOT/install.sh" "$T/"; cp "$ROOT/docs/release/allowed_signers" "$ROOT/docs/release/internal_test_signers" "$T/docs/release/" +cp "$ROOT"/scripts/*.sh "$T/scripts/" +git -C "$T" init -q; git -C "$T" add -A; git -C "$T" -c user.name=t -c user.email=t@t commit -qm base +bash "$T/scripts/check-release-trust-config.sh" > "$W/o.log" || fail "baseline (placeholder) rejected" +grep -q PLACEHOLDER "$W/o.log" || fail "baseline not reported as placeholder" +pass "baseline: placeholder state is consistent" + +# Negative control: the rehearsal record must not be accepted as a real ceremony. +if bash "$T/scripts/apply-ceremony-public-record.sh" "$PUB" --root "$T" > "$W/o.log" 2>&1; then fail "rehearsal record applied without --allow-rehearsal"; fi +grep -q 'REHEARSAL' "$W/o.log" || fail "rehearsal refusal not named" +git -C "$T" diff --quiet && [[ -z "$(git -C "$T" status --porcelain)" ]] || fail "refused apply still changed the tree" +pass "a REHEARSAL record is refused as a release key (negative control), tree untouched" +mkdir "$W/stray"; cp "$PUB"/* "$W/stray/"; touch "$W/stray/aien_release_ed25519" +if bash "$T/scripts/apply-ceremony-public-record.sh" "$W/stray" --root "$T" --allow-rehearsal > "$W/o.log" 2>&1; then fail "apply accepted a public folder holding an extra file"; fi +pass "a public folder with any extra file (for example a key file) is refused" + +# (d) the post-ceremony change +bash "$T/scripts/apply-ceremony-public-record.sh" "$PUB" --root "$T" --allow-rehearsal > "$W/o.log" 2>&1 || { cat "$W/o.log" >&2; fail "apply failed"; } +git -C "$T" add -A +[[ "$(git -C "$T" diff --cached --name-only | sort | tr '\n' ' ')" == "docs/release/allowed_signers docs/release/ceremony-record.txt install.sh " ]] || fail "change touches files other than the three expected" +[[ "$(git -C "$T" diff --cached -U0 install.sh | grep -c '^[-+][^-+]')" -eq 2 ]] || fail "install.sh change is not exactly one line replaced" +git -C "$T" diff --cached -U0 install.sh | grep -q "^+AIEN_RELEASE_SIGNER='aien-release ssh-ed25519 " || fail "install.sh change is not the AIEN_RELEASE_SIGNER line" +[[ "$(git -C "$T" diff --cached -U0 docs/release/allowed_signers | grep '^+[^+]' | grep -vc '^+#')" -eq 1 ]] || fail "allowed_signers change is not exactly one key line" +[[ "$(git -C "$T" diff --cached -U0 docs/release/allowed_signers | grep '^-[^-]' | grep -vc '^-#')" -eq 0 ]] || fail "allowed_signers change removes a key line" +! git -C "$T" diff --cached | grep -q 'PRIVATE KEY' || fail "private key material in the diff" +cmp -s "$PUB/ceremony-record.txt" "$T/docs/release/ceremony-record.txt" || fail "record in the tree is not the ceremony's public record" +pass "(d) trust-config change = one allowed_signers key line + one AIEN_RELEASE_SIGNER value + the public record, no private material" + +# (e) fingerprint match and mutants +CHK=(bash "$T/scripts/check-release-trust-config.sh" --root "$T" --allow-rehearsal) +"${CHK[@]}" > "$W/o.log" 2>&1 || { cat "$W/o.log" >&2; fail "consistent tree rejected"; } +FP="$(sed -n 's/^fingerprint: //p' "$PUB/ceremony-record.txt")" +[[ "$FP" == "$(awk '{ print $2" "$3 }' "$T/docs/release/allowed_signers" | grep -v '^#' | ssh-keygen -lf - | awk '{ print $2 }' | head -1)" ]] || fail "record fingerprint is not the pinned key's fingerprint" +if bash "$T/scripts/check-release-trust-config.sh" --root "$T" > "$W/o.log" 2>&1; then fail "rehearsal tree passed the strict check"; fi +pass "(e) record fingerprint $FP equals the pinned line; strict mode refuses the rehearsal tree" +mutant() { # name, then commands run in a fresh copy of the pinned tree; the checker must refuse + local name="$1" M="$W/m-$1"; shift + rm -rf "$M"; cp -r "$T" "$M"; ( cd "$M"; "$@" ) || fail "mutant $name could not be built" + if bash "$M/scripts/check-release-trust-config.sh" --root "$M" --allow-rehearsal > "$W/o.log" 2>&1; then fail "mutant refused? no: $name passed the checker"; fi + pass "mutant refused: $name ($(sed -n 's/.*REFUSED: //p' "$W/o.log" | cut -c1-70))" +} +OTHERLINE="aien-release $(cut -d' ' -f1,2 "$W/other.pub")" +mutant wrong-fingerprint-in-record sed -i 's/^fingerprint: SHA256:./fingerprint: SHA256:X/' docs/release/ceremony-record.txt +mutant other-key-in-allowed_signers sed -i "s|^aien-release ssh-ed25519 .*|$OTHERLINE|" docs/release/allowed_signers +mutant installer-pin-differs sed -i "s|^AIEN_RELEASE_SIGNER=.*|AIEN_RELEASE_SIGNER='$OTHERLINE'|" install.sh +mutant installer-pin-empty sed -i "s|^AIEN_RELEASE_SIGNER=.*|AIEN_RELEASE_SIGNER=''|" install.sh +mutant record-missing rm docs/release/ceremony-record.txt +mutant two-keys-pinned sh -c "echo '$OTHERLINE' >> docs/release/allowed_signers" +mutant internal-test-key-pinned sh -c "l=\$(grep -v '^#' docs/release/internal_test_signers); sed -i \"s|^aien-release ssh-ed25519 .*|\$l|\" docs/release/allowed_signers; sed -i \"s|^AIEN_RELEASE_SIGNER=.*|AIEN_RELEASE_SIGNER='\$l'|\" install.sh" +mutant private-material-in-record sh -c "echo '-----BEGIN OPENSSH PRIVATE KEY-----' >> docs/release/ceremony-record.txt" +mutant record-says-one-backup sed -i '0,/signs and verifies yes; altered file refused yes/s//signs and verifies no/' docs/release/ceremony-record.txt + +# (a)(b)(c) the real installer and publish gate, configured only from the public record +make_release() { # dir signing-key + local d="$1" k="$2" p="$W/pkg" f aien + rm -rf "$p"; mkdir -p "$d" "$p/bin" + printf '#!/bin/sh\necho aien\nexit 0\n' > "$p/bin/aien"; chmod 755 "$p/bin/aien" + aien="$(sha256sum "$p/bin/aien" | cut -d' ' -f1)" + { printf 'schema = "AienReleaseV1"\ncandidate = "CAND-1"\naien-cli-sha256 = "%s"\n\n[files]\n' "$aien" + printf '"bin/aien" = "%s"\n' "$aien"; } > "$p/release.toml" + tar -czf "$d/$ASSET" -C "$p" . + (cd "$d" && sha256sum "$ASSET" > SHA256SUMS.txt) + ssh-keygen -q -Y sign -f "$k" -n aien-release "$d/SHA256SUMS.txt" +} +inst() { # release-dir tag-suffix + env HOME="$W/home" AIEN_RELEASE_TAG=v0.0.0-test AIEN_RELEASE_BASE_URL="file://$1" AIEN_BIN_DIR="$W/bin-$2" \ + AIEN_CONFIG_DIR="$W/cfg-$2" AIEN_INSTALL_NO_PROFILE=1 bash "$T/install.sh" > "$W/log" 2>&1 +} +mkdir -p "$W/home" +GATE=(bash "$T/scripts/release-publish-gate.sh") +make_release "$W/good" "$KEY" +inst "$W/good" good || { cat "$W/log" >&2; fail "release signed by the matching key did not install"; } +grep -q '"signature_check": "release"' "$W/cfg-good/install-receipt.json" || fail "receipt does not say signature_check release" +grep -q "\"signer_fingerprint\": \"$FP\"" "$W/cfg-good/install-receipt.json" || fail "receipt signer_fingerprint is not the ceremony record's fingerprint" +"${GATE[@]}" "$W/good" "$T/docs/release/allowed_signers" > "$W/g.log" 2>&1 || { cat "$W/g.log" >&2; fail "publish gate refused the matching-key release"; } +pass "(a) signed by the matching key: installs as signature_check release, receipt fingerprint = record fingerprint, publish gate passes" +make_release "$W/wrongkey" "$W/other" +if inst "$W/wrongkey" wk; then fail "release signed by a different key was installed"; fi +grep -q "signature is NOT valid" "$W/log" || fail "different key not refused by name" +[[ ! -e "$W/cfg-wk/install-receipt.json" && ! -e "$W/bin-wk/aien" ]] || fail "refusal left a receipt or binary" +if "${GATE[@]}" "$W/wrongkey" "$T/docs/release/allowed_signers" > "$W/g.log" 2>&1; then fail "publish gate passed a different key"; fi +grep -q "NOT valid" "$W/g.log" || fail "publish gate did not name the signature" +pass "(b) signed by a different key: installer refuses ('signature is NOT valid'), nothing installed; publish gate refuses" +cp -r "$W/good" "$W/flip"; A="$W/flip/$ASSET"; SZ=$(wc -c < "$A"); OFF=$((SZ / 2)) +B="$(dd if="$A" bs=1 skip="$OFF" count=1 2>/dev/null | od -An -tu1 | tr -d ' ')" +printf "$(printf '\\%03o' $(( (B + 1) % 256 )))" | dd of="$A" bs=1 seek="$OFF" count=1 conv=notrunc 2>/dev/null +if inst "$W/flip" flip; then fail "tampered archive installed"; fi +grep -qi checksum "$W/log" || fail "tampered archive not refused as a checksum failure" +[[ ! -e "$W/cfg-flip/install-receipt.json" ]] || fail "tampered archive left a receipt" +if "${GATE[@]}" "$W/flip" "$T/docs/release/allowed_signers" > "$W/g.log" 2>&1; then fail "publish gate passed a tampered archive"; fi +cp -r "$W/good" "$W/flipsum"; C1="$(head -c1 "$W/flipsum/SHA256SUMS.txt")"; [[ "$C1" == 0 ]] && R=1 || R=0; sed -i "1s/^./$R/" "$W/flipsum/SHA256SUMS.txt" +if inst "$W/flipsum" fs; then fail "tampered checksum list installed"; fi +grep -q "signature is NOT valid" "$W/log" || fail "tampered checksum list not refused as a signature failure" +pass "(c) tampered archive refused (checksum), tampered checksum list refused (signature), nothing installed" +echo "PASS: public-key integration: from only the public ceremony record, the trust-config change is a 3-file reviewable diff, the record fingerprint equals the pinned key (9 mismatch mutants refused), a release signed by the matching key installs as release, a different key, a tampered archive and a tampered checksum list are refused"