From b9ee171ff1cc183b393b2e165f2cae31566d82fb Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Wed, 30 Sep 2026 21:30:37 -0500 Subject: [PATCH] TRUST-1: fix recovery guide, add Gate 7 pre-flight check The recovery media guide told the operator to wrap the evidence collector in `aien-proof hold` at the recovery prompt, but aien-proof is not on the stick. Run the collector directly there; aien-proof stays on Ubuntu. List the exact tools the stick ships, and cross-link the guide with TRUST-1-OPERATOR-STEPS.md. Add scripts/trust1_gate7_preflight.sh: read-only checks of everything that can be verified before the operator's reboots (device list health, TPM and Secure Boot readable, stick build inputs, snapshot/compare tools, offline spare and cipher folder, recovery image tools). No sudo, no mounts, never touches /dev entries; writes only to its own temp folder. Co-Authored-By: Drake Stapleton Co-Authored-By: Claude Opus 5.5 --- docs/RECOVERY_MEDIA_MACHINE1.md | 54 +++++++-- docs/TRUST-1-OPERATOR-STEPS.md | 29 ++++- scripts/trust1_gate7_preflight.sh | 189 ++++++++++++++++++++++++++++++ 3 files changed, 261 insertions(+), 11 deletions(-) create mode 100755 scripts/trust1_gate7_preflight.sh diff --git a/docs/RECOVERY_MEDIA_MACHINE1.md b/docs/RECOVERY_MEDIA_MACHINE1.md index f357a528..d4412750 100644 --- a/docs/RECOVERY_MEDIA_MACHINE1.md +++ b/docs/RECOVERY_MEDIA_MACHINE1.md @@ -1,5 +1,16 @@ # Bootable recovery media for Machine 1 +> **Operator doing TRUST-1:** follow +> [TRUST-1-OPERATOR-STEPS.md](TRUST-1-OPERATOR-STEPS.md) (Step 4 rebuilds the +> stick, Step 6 boots it and proves the unlock). This page is the technical +> record of what the stick contains and how it was first proven. +> +> **Two places, two sets of tools.** Commands in "Build and verify" run in a +> normal Ubuntu terminal on the Spark. Commands after "Boot the USB once" run +> at the recovery prompt on the stick, which only has the tools listed under +> "What ships". `aien-proof` (the shared test-board tool) is **not** on the +> stick: use it only from Ubuntu. + This procedure builds and exercises the bootable recovery USB for [issue #17](https://github.com/aien-dev/aienos/issues/17) and TRUST-1 Gate 1. The physical run on 2026-09-25 booted the USB once, mounted the internal root @@ -19,9 +30,21 @@ exercise. recovery USB (signed shim + GRUB fallback, signed production kernel, and a standalone RAM initrd). It refuses the internal NVMe and mounted targets. - `scripts/build_standalone_recovery_initrd.sh` builds the RAM rescue - environment with BusyBox, filesystem check/repair tools, `chroot`, - `efibootmgr`, `findmnt`, and the Machine 1 xHCI/HID/USB-storage/NVMe/dm-crypt - modules. Internal storage remains unmounted until the operator mounts it. + environment. It contains exactly these programs (the `BINARIES` list in that + script, plus gocryptfs): + - shell and basics: BusyBox (with its built-in commands), `sh`, `bash`, + `mount`, `umount`, `mkdir`, `cat`, `grep`, `sed`, `sha256sum`; + - disks: `lsblk`, `blkid`, `findmnt`, `cryptsetup`; + - repair and boot entries: `fsck.vfat`, `mkfs.vfat`, `fsck.ext4`, `chroot`, + `efibootmgr`; + - TRUST-1 Gate 1: `tpm2_pcrread` (startup measurements), `sbverify` (loader + signatures), `age` (opens the offline spare), `gocryptfs` and + `fusermount3` (open and close the private storage read-only). + + It also packages the Machine 1 xHCI/HID/USB-storage/NVMe/dm-crypt modules. + It does **not** contain `aien-proof`, `tpm2_eventlog`, `mokutil`, a + repository checkout, or any key. Internal storage remains unmounted until + the operator mounts it. - The build copies the attended collector into the image at `/usr/local/sbin/collect_recovery_boot_evidence`; it does not depend on a repository checkout being present in the rescue shell. @@ -36,8 +59,9 @@ it on exit, including failed builds. ## Build and verify -On Machine 1 in Linux, identify the dedicated USB target. Do not target the -internal NVMe or EFI System Partition; the builder rejects them. +On Machine 1 in Linux (an Ubuntu terminal, where `aien-proof` is installed), +identify the dedicated USB target. Do not target the internal NVMe or EFI +System Partition; the builder rejects them. ```bash cd ~/workspace/aienos-recovery-gate @@ -100,11 +124,12 @@ exercise only reads entries and does not change efivars or BootOrder. ## Capture the recovery evidence Run the collector packaged on the USB, not a copy assumed to exist in the -repository checkout. Use the exact mount locations above: +repository checkout. Use the exact mount locations above. Type it as shown, +with no `aien-proof hold` in front: that tool is not on the stick, and an +earlier version of this page wrongly said to use it here. ```sh -aien-proof hold --resource machine-1 --job recovery-boot-evidence -- \ - env AIENOS_ESP_MNT=/mnt/esp \ +env AIENOS_ESP_MNT=/mnt/esp \ /usr/local/sbin/collect_recovery_boot_evidence /mnt/root ``` @@ -112,13 +137,24 @@ The collector is read-only. A PASS checks removable-media boot, Secure Boot byte readability, internal root mount, ESP mount and fallback loader, efivarfs presence, and readable boot entries. Preserve its complete output. +For the TRUST-1 Gate 1 round trip (opening the private storage read-only with +the offline spare), use the longer form with the `AIENOS_UNLOCK_*` settings in +[TRUST-1-OPERATOR-STEPS.md, Step 6](TRUST-1-OPERATOR-STEPS.md#step-6-boot-the-recovery-stick-with-secure-boot-on-and-prove-the-unlock-gate-1-attended). + +The machine-1 test-board record for this boot comes from Ubuntu, not from the +stick: the `aien-proof hold` around the stick build is the last ledger event +before the reboot. The 2026-09-25 run had no separate ledger event for the +attended boot itself (see the evidence record); the collector's printed +output is the record of the boot. + ## Return to Linux and complete the record Exit any chroot, unmount `/mnt/esp` and `/mnt/root`, then reboot or power off. Confirm Linux returns and record its root/ESP mounts. Record the recovery `BootCurrent` and `BootOrder`, the return-to-Linux proof, tool results, Secure Boot observations before and after the boot, and the aien-proof events -in the evidence file. If an abbreviated collector or receipt omitted the +taken from Ubuntu (the build hold, and anything recorded after return) in the +evidence file. If an abbreviated collector or receipt omitted the Secure Boot byte or post-return state, say so explicitly; do not infer it. For the 2026-09-25 run, the recovery entry was `Boot0004* UEFI: USB USB Hard diff --git a/docs/TRUST-1-OPERATOR-STEPS.md b/docs/TRUST-1-OPERATOR-STEPS.md index 1203b979..91619a80 100644 --- a/docs/TRUST-1-OPERATOR-STEPS.md +++ b/docs/TRUST-1-OPERATOR-STEPS.md @@ -102,7 +102,9 @@ Why: the stick in use today was built before the Gate 1 fixes. It lacks the tools that open the encrypted storage, read the startup measurements through the TPM, and check loader signatures. Rebuilding replaces the recovery files on the stick (it is not reformatted); it does not -touch the Spark's internal drive. +touch the Spark's internal drive. (What the stick contains, and how it was +first proven, is recorded in +[RECOVERY_MEDIA_MACHINE1.md](RECOVERY_MEDIA_MACHINE1.md).) 1. Plug in the recovery stick (label `AIENOSRECOV`). Run `lsblk -f` and find the line with that label. Note its name, for example `sdb1`. If Ubuntu @@ -165,6 +167,12 @@ second copy somewhere physically separate from the Spark.)* ## Step 6. Boot the recovery stick with Secure Boot ON and prove the unlock (Gate 1, attended) +The recovery prompt is a small, separate system on the stick. It has only +the tools listed in +[RECOVERY_MEDIA_MACHINE1.md, "What ships"](RECOVERY_MEDIA_MACHINE1.md#what-ships). +`aien-proof` is not one of them, so type the commands below exactly as shown, +with nothing in front. + 1. Both sticks plugged in (Option A). In the terminal: ```bash @@ -295,6 +303,23 @@ live): the current one. Gets its own written steps and approval. - **Gate 7** (you): the single attended hardware boot with Secure Boot on. Gets its own written checklist and approval; nothing above prepares it - silently. + silently. Before that checklist, an agent or you can run the pre-flight + check in a normal terminal: + + ```bash + bash scripts/trust1_gate7_preflight.sh + ``` + + *What it does:* checks the things that can be checked before any restart: + the TPM and Secure Boot state can be read, every tool the stick and the + snapshot steps need is present, the locked spare and the encrypted storage + folder are where this page says, no secret key sits next to the spare, and + the recovery image (on the stick if it is plugged in and open, otherwise a + private test copy) has every tool. *Changes:* nothing; it needs no + password and cleans up its own temporary folder. Takes about 5 seconds. + *You should see:* a list of `PASS` lines, a `NOT CHECKED` list (things only + your restarts or later gates can prove), and last + `GATE7_PREFLIGHT: PASS`. Any `FAIL` line: stop and hand the output to the + orchestrator. - **Gates 8-9**: observation period, then retiring the old rules only with your approval. diff --git a/scripts/trust1_gate7_preflight.sh b/scripts/trust1_gate7_preflight.sh new file mode 100755 index 00000000..fef8dfb3 --- /dev/null +++ b/scripts/trust1_gate7_preflight.sh @@ -0,0 +1,189 @@ +#!/usr/bin/env bash +# trust1_gate7_preflight.sh: TRUST-1 Gate 7 pre-flight check (read-only). +# +# Checks, before the attended Gate 7 steps, everything that can be checked +# without the operator's reboot measurements: the tools the stick and the +# snapshot/compare steps need, the offline spare and the encrypted storage +# folder, the TPM, Secure Boot, and (if the stick is plugged in and open, or +# an image path is given) the tools inside the recovery image. +# +# Safety rules (after the 2026-09-30 /dev deletion incident): +# - changes nothing on the machine: no sudo, no mount, no chroot, no efivar +# or boot-entry writes, no TPM writes; +# - never creates, removes or binds anything under /dev (it only looks at +# /dev entries with `test`, and reads PCRs through the TPM like +# tpm_measurement_campaign.sh does); +# - writes only inside one private temp folder, which it removes with +# `rm --one-file-system` and only if nothing is mounted under it. +# +# Usage: bash scripts/trust1_gate7_preflight.sh [INITRD_IMAGE] +# INITRD_IMAGE optional: a recovery initrd to inspect. Without it, the +# image on a mounted AIENOSRECOV stick is used; if the stick +# is not open, a private copy is built in a temp folder. +# Exit: 0 = no FAIL, 1 = at least one FAIL. + +set -uo pipefail + +REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +SPARE_DIR="${AIENOS_SPARE_DIR:-${HOME}/.config/atlas/offline-spares}" +SPARE="${SPARE_DIR}/atlas-private-storage.passfile.age" +CIPHER_DIR="${AIENOS_CIPHER_DIR:-/home/atlas/atlas-runtime-setup-20260905/private-cipher}" +EVENTLOG="${AIENOS_EVENTLOG:-/sys/kernel/security/tpm0/binary_bios_measurements}" +EFIVARS="${AIENOS_EFIVARS_DIR:-/sys/firmware/efi/efivars}" +SB_VAR="${EFIVARS}/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c" + +TMP="$(mktemp -d /tmp/trust1-gate7-preflight.XXXXXX)" || { echo "FAIL could not create a temp folder"; exit 1; } +cleanup() { + # Refuse to delete if anything is mounted inside the temp folder. + if findmnt -rn -o TARGET 2>/dev/null | grep -q "^${TMP}\(/\|$\)"; then + echo "WARNING: something is mounted under ${TMP}; leaving it in place" >&2 + return + fi + rm -rf --one-file-system -- "${TMP}" +} +trap cleanup EXIT + +PASSES=0; FAILS=0; SKIPS=0 +pass() { echo "PASS $1"; PASSES=$((PASSES + 1)); } +fail() { echo "FAIL $1"; FAILS=$((FAILS + 1)); } +skip() { echo "SKIP $1"; SKIPS=$((SKIPS + 1)); } +check() { if [[ "$2" == 1 ]]; then pass "$1"; else fail "$1"; fi; } +yes_if() { if "$@" >/dev/null 2>&1; then echo 1; else echo 0; fi; } + +echo "TRUST-1 Gate 7 pre-flight (read-only; changes nothing)" +echo "" + +echo "-- 1. The Spark's device list looks healthy (after the 2026-09-30 incident) --" +check "/dev/null is a real device (not a plain file)" "$(yes_if test -c /dev/null)" +check "the TPM device /dev/tpmrm0 exists" "$(yes_if test -c /dev/tpmrm0)" + +echo "" +echo "-- 2. The TPM can be read --" +check "you are in the tss group (allowed to read the TPM)" \ + "$(id -nG | tr ' ' '\n' | grep -qx tss && echo 1 || echo 0)" +check "the TPM device is readable by you" "$(yes_if test -r /dev/tpmrm0)" +if command -v tpm2_pcrread >/dev/null 2>&1; then + check "the TPM answers a read of startup measurement 7 (Secure Boot state)" \ + "$(yes_if tpm2_pcrread sha256:7)" +else + fail "tpm2_pcrread is installed (needed to read the TPM)" +fi +check "the firmware's startup measurement log is readable" "$(yes_if test -r "${EVENTLOG}")" + +echo "" +echo "-- 3. Secure Boot state can be read --" +if command -v mokutil >/dev/null 2>&1; then + sb="$(mokutil --sb-state 2>/dev/null || true)" + check "Secure Boot reports ON (mokutil says: ${sb:-nothing})" \ + "$([[ "${sb}" == *"SecureBoot enabled"* ]] && echo 1 || echo 0)" +else + fail "mokutil is installed (reads the Secure Boot state)" +fi +if [[ -r "${SB_VAR}" ]]; then + # efivarfs: 4 attribute bytes, then the 1-byte value. + sb_byte="$(od -An -tu1 -j4 -N1 "${SB_VAR}" 2>/dev/null | tr -d ' ')" + check "the firmware's own Secure Boot setting reads 1 (ON), got '${sb_byte}'" \ + "$([[ "${sb_byte}" == 1 ]] && echo 1 || echo 0)" +else + fail "the firmware's Secure Boot setting is readable" +fi + +echo "" +echo "-- 4. Tools the stick build copies from Ubuntu are all present --" +mapfile -t stick_bins < <(sed -n '/^BINARIES=(/,/^)/p' "${REPO_ROOT}/scripts/build_standalone_recovery_initrd.sh" \ + | sed -n 's/^[[:space:]]*\(\/[^[:space:]]*\).*/\1/p') +if [[ ${#stick_bins[@]} -eq 0 ]]; then + fail "read the list of stick tools from build_standalone_recovery_initrd.sh" +else + missing=() + for b in "${stick_bins[@]}"; do [[ -e "${b}" ]] || missing+=("${b}"); done + check "all ${#stick_bins[@]} programs the stick build copies exist on Ubuntu${missing[*]:+ (missing: ${missing[*]})}" \ + "$([[ ${#missing[@]} -eq 0 ]] && echo 1 || echo 0)" +fi +gocryptfs_bin="${AIENOS_GOCRYPTFS:-$(command -v gocryptfs 2>/dev/null || echo /home/atlas/atlas-forgejo-setup-20260904/runtime/usr/bin/gocryptfs)}" +check "gocryptfs (opens the private storage) is where the stick build looks: ${gocryptfs_bin}" \ + "$(yes_if test -f "${gocryptfs_bin}")" + +echo "" +echo "-- 5. Snapshot, compare and stick scripts are present --" +for s in tpm_measurement_campaign.sh build_recovery_media.sh build_standalone_recovery_initrd.sh \ + verify_recovery_tools.sh collect_recovery_boot_evidence.sh; do + check "scripts/${s} is present" "$(yes_if test -f "${REPO_ROOT}/scripts/${s}")" +done +for t in tpm2_pcrread tpm2_eventlog mokutil efibootmgr sha256sum aien-proof; do + check "${t} is installed on Ubuntu" "$(yes_if command -v "${t}")" +done + +echo "" +echo "-- 6. Key ciphertext is where the docs say, and no secret key sits beside it --" +if [[ -s "${SPARE}" ]]; then + hdr="$(head -n 1 "${SPARE}" 2>/dev/null)" + check "the offline spare is present and locked (age format): ${SPARE}" \ + "$([[ "${hdr}" == "age-encryption.org/v1" ]] && echo 1 || echo 0)" +else + fail "the offline spare is present and not empty: ${SPARE}" +fi +if [[ -d "${SPARE_DIR}" ]]; then + if grep -rlq 'AGE-SECRET-KEY-' "${SPARE_DIR}" 2>/dev/null; then + fail "no unlocking identity (secret key) is stored next to the spares on the Spark" + else + pass "no unlocking identity (secret key) is stored next to the spares on the Spark" + fi +fi +if [[ -d "${CIPHER_DIR}" ]]; then + if [[ -r "${CIPHER_DIR}/gocryptfs.conf" ]]; then + pass "the encrypted private storage folder and its gocryptfs.conf are present: ${CIPHER_DIR}" + elif [[ -e "${CIPHER_DIR}/gocryptfs.conf" ]]; then + skip "the encrypted storage's gocryptfs.conf exists but you may not read it (not a fault)" + else + fail "the encrypted private storage has its gocryptfs.conf: ${CIPHER_DIR}" + fi +elif [[ -e "${CIPHER_DIR}" ]]; then + skip "the encrypted private storage folder exists but you may not look inside (not a fault)" +else + fail "the encrypted private storage folder exists: ${CIPHER_DIR}" +fi + +echo "" +echo "-- 7. Tools inside the recovery image --" +image=""; image_note="" +if [[ $# -ge 1 ]]; then + image="$1"; image_note="the image you named" +else + stick_mnt="$(findmnt -rn -o TARGET -S LABEL=AIENOSRECOV 2>/dev/null | head -n 1)" + if [[ -n "${stick_mnt}" ]]; then + image="${stick_mnt}/aienos-recovery/initrd.img"; image_note="the image on the plugged-in stick" + fi +fi +log="${TMP}/verify_recovery_tools.log" +if [[ -n "${image}" ]]; then + if [[ -f "${image}" ]]; then + TMPDIR="${TMP}" bash "${REPO_ROOT}/scripts/verify_recovery_tools.sh" "${image}" >"${log}" 2>&1 + rc=$? + else + echo "image not found: ${image}" >"${log}"; rc=1 + fi +else + image_note="a fresh private copy built now (stick not open; this is what Step 4 would write)" + TMPDIR="${TMP}" bash "${REPO_ROOT}/scripts/verify_recovery_tools.sh" >"${log}" 2>&1 + rc=$? +fi +grep -E '^(FAIL|SKIP)|^image not found' "${log}" | sed 's/^/ /' +check "every recovery tool is inside ${image_note}" "$([[ ${rc} -eq 0 ]] && echo 1 || echo 0)" + +echo "" +echo "-- Not checked here (need Drake's reboots or later gates) --" +echo "NOT CHECKED startup measurements match across normal boots (Gate 2 reboot snapshots)" +echo "NOT CHECKED owner key fingerprints and backups (Gate 3 key ceremony not run yet)" +echo "NOT CHECKED owner-signed loader and its fingerprint (Gate 4)" +echo "NOT CHECKED Secure Boot variables archived, Gates 0-6 PASS, operator approval" +echo "NOT CHECKED the stick actually boots and unlocks with Secure Boot ON (Gate 1, Step 6)" +echo "NOT CHECKED every Gate 7 checkpoint A-E (attended hardware boot)" + +echo "" +echo "Summary: ${PASSES} passed, ${FAILS} failed, ${SKIPS} skipped" +if [[ ${FAILS} -ne 0 ]]; then + echo "GATE7_PREFLIGHT: FAIL" + exit 1 +fi +echo "GATE7_PREFLIGHT: PASS (only covers what can be checked before the reboots)"