Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/scripts/trust1_gate7_preflight.sh # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / scripts / trust1_gate7_preflight.sh` 211 lines ยท 9956 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # SPDX-License-Identifier: Apache-2.0 3 # Copyright 2026 Drake Stapleton (AIEN / aien-dev) 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # trust1_gate7_preflight.sh: TRUST-1 Gate 7 pre-flight check (read-only). 18 # 19 # Checks, before the attended Gate 7 steps, everything that can be checked 20 # without the operator's reboot measurements: the tools the stick and the 21 # snapshot/compare steps need, the offline spare and the encrypted storage 22 # folder, the TPM, Secure Boot, and (if the stick is plugged in and open, or 23 # an image path is given) the tools inside the recovery image. 24 # 25 # Safety rules (after the 2026-09-30 /dev deletion incident): 26 # - changes nothing on the machine: no sudo, no mount, no chroot, no efivar 27 # or boot-entry writes, no TPM writes; 28 # - never creates, removes or binds anything under /dev (it only looks at 29 # /dev entries with `test`, and reads PCRs through the TPM like 30 # tpm_measurement_campaign.sh does); 31 # - writes only inside one private temp folder, which it removes with 32 # `rm --one-file-system` and only if nothing is mounted under it. 33 # 34 # Usage: bash scripts/trust1_gate7_preflight.sh [INITRD_IMAGE] 35 # INITRD_IMAGE optional: a recovery initrd to inspect. Without it, the 36 # image on a mounted AIENOSRECOV stick is used; if the stick 37 # is not open, a private copy is built in a temp folder. 38 # Exit: 0 = no FAIL, 1 = at least one FAIL. 39 40 set -uo pipefail 41 42 REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" 43 SPARE_DIR="${AIENOS_SPARE_DIR:-${HOME}/.config/atlas/offline-spares}" 44 SPARE="${SPARE_DIR}/atlas-private-storage.passfile.age" 45 CIPHER_DIR="${AIENOS_CIPHER_DIR:-/home/atlas/atlas-runtime-setup-`20260905`/private-cipher}" 46 EVENTLOG="${AIENOS_EVENTLOG:-/sys/kernel/security/tpm0/binary_bios_measurements}" 47 EFIVARS="${AIENOS_EFIVARS_DIR:-/sys/firmware/efi/efivars}" 48 SB_VAR="${EFIVARS}/SecureBoot-`8be4df61`-93ca-11d2-aa0d-`00e098032b8c`" 49 50 TMP="$(mktemp -d /tmp/trust1-gate7-preflight.XXXXXX)" || { echo "FAIL could not create a temp folder"; exit 1; } 51 cleanup() { 52 # Refuse to delete if anything is mounted inside the temp folder. 53 if findmnt -rn -o TARGET 2>/dev/null | grep -q "^${TMP}\(/\|$\)"; then 54 echo "WARNING: something is mounted under ${TMP}; leaving it in place" >&2 55 return 56 fi 57 rm -rf --one-file-system -- "${TMP}" 58 } 59 trap cleanup EXIT 60 61 PASSES=0; FAILS=0; SKIPS=0 62 pass() { echo "PASS $1"; PASSES=$((PASSES + 1)); } 63 fail() { echo "FAIL $1"; FAILS=$((FAILS + 1)); } 64 skip() { echo "SKIP $1"; SKIPS=$((SKIPS + 1)); } 65 check() { if [[ "$2" == 1 ]]; then pass "$1"; else fail "$1"; fi; } 66 yes_if() { if "$@" >/dev/null 2>&1; then echo 1; else echo 0; fi; } 67 68 echo "TRUST-1 Gate 7 pre-flight (read-only; changes nothing)" 69 echo "" 70 71 echo "-- 1. The Spark's device list looks healthy (after the 2026-09-30 incident) --" 72 check "/dev/null is a real device (not a plain file)" "$(yes_if test -c /dev/null)" 73 check "the TPM device /dev/tpmrm0 exists" "$(yes_if test -c /dev/tpmrm0)" 74 75 echo "" 76 echo "-- 2. The TPM can be read --" 77 check "you are in the tss group (allowed to read the TPM)" \ 78 "$(id -nG | tr ' ' '\n' | grep -qx tss && echo 1 || echo 0)" 79 check "the TPM device is readable by you" "$(yes_if test -r /dev/tpmrm0)" 80 # FLAG(sovereignty): tpm2_pcrread (outside dep) on Linux host; replace with in-house C PCR reader. 81 if command -v tpm2_pcrread >/dev/null 2>&1; then 82 check "the TPM answers a read of startup measurement 7 (Secure Boot state)" \ 83 "$(yes_if tpm2_pcrread sha256:7)" 84 else 85 fail "tpm2_pcrread is installed (needed to read the TPM)" 86 fi 87 check "the firmware's startup measurement log is readable" "$(yes_if test -r "${EVENTLOG}")" 88 89 echo "" 90 echo "-- 3. Secure Boot state can be read --" 91 if command -v mokutil >/dev/null 2>&1; then 92 sb="$(mokutil --sb-state 2>/dev/null || true)" 93 check "Secure Boot reports ON (mokutil says: ${sb:-nothing})" \ 94 "$([[ "${sb}" == *"SecureBoot enabled"* ]] && echo 1 || echo 0)" 95 else 96 fail "mokutil is installed (reads the Secure Boot state)" 97 fi 98 if [[ -r "${SB_VAR}" ]]; then 99 # efivarfs: 4 attribute bytes, then the 1-byte value. 100 sb_byte="$(od -An -tu1 -j4 -N1 "${SB_VAR}" 2>/dev/null | tr -d ' ')" 101 check "the firmware's own Secure Boot setting reads 1 (ON), got '${sb_byte}'" \ 102 "$([[ "${sb_byte}" == 1 ]] && echo 1 || echo 0)" 103 else 104 fail "the firmware's Secure Boot setting is readable" 105 fi 106 107 echo "" 108 echo "-- 4. Tools the stick build copies from Ubuntu are all present --" 109 mapfile -t stick_bins < <(sed -n '/^BINARIES=(/,/^)/p' "${REPO_ROOT}/scripts/build_standalone_recovery_initrd.sh" \ 110 | sed -n 's/^[[:space:]]*\(\/[^[:space:]]*\).*/\1/p') 111 if [[ ${#stick_bins[@]} -eq 0 ]]; then 112 fail "read the list of stick tools from build_standalone_recovery_initrd.sh" 113 else 114 missing=() 115 for b in "${stick_bins[@]}"; do [[ -e "${b}" ]] || missing+=("${b}"); done 116 check "all ${#stick_bins[@]} programs the stick build copies exist on Ubuntu${missing[*]:+ (missing: ${missing[*]})}" \ 117 "$([[ ${#missing[@]} -eq 0 ]] && echo 1 || echo 0)" 118 fi 119 gocryptfs_bin="${AIENOS_GOCRYPTFS:-$(command -v gocryptfs 2>/dev/null || echo /home/atlas/atlas-forgejo-setup-`20260904`/runtime/usr/bin/gocryptfs)}" 120 check "gocryptfs (opens the private storage) is where the stick build looks: ${gocryptfs_bin}" \ 121 "$(yes_if test -f "${gocryptfs_bin}")" 122 123 echo "" 124 echo "-- 5. Snapshot, compare and stick scripts are present --" 125 for s in tpm_measurement_campaign.sh build_recovery_media.sh build_standalone_recovery_initrd.sh \ 126 verify_recovery_tools.sh collect_recovery_boot_evidence.sh; do 127 check "scripts/${s} is present" "$(yes_if test -f "${REPO_ROOT}/scripts/${s}")" 128 done 129 # FLAG(sovereignty): tpm2_pcrread/tpm2_eventlog required on Linux host; replace with in-house C tool. 130 for t in tpm2_pcrread tpm2_eventlog mokutil efibootmgr sha256sum aien-proof; do 131 check "${t} is installed on Ubuntu" "$(yes_if command -v "${t}")" 132 done 133 134 echo "" 135 echo "-- 6. Key ciphertext is where the docs say, and no secret key sits beside it --" 136 if [[ -s "${SPARE}" ]]; then 137 hdr="$(head -n 1 "${SPARE}" 2>/dev/null)" 138 check "the offline spare is present and locked (age format): ${SPARE}" \ 139 "$([[ "${hdr}" == "age-encryption.org/v1" ]] && echo 1 || echo 0)" 140 else 141 fail "the offline spare is present and not empty: ${SPARE}" 142 fi 143 if [[ -d "${SPARE_DIR}" ]]; then 144 if grep -rlq 'AGE-SECRET-KEY-' "${SPARE_DIR}" 2>/dev/null; then 145 fail "no unlocking identity (secret key) is stored next to the spares on the Spark" 146 else 147 pass "no unlocking identity (secret key) is stored next to the spares on the Spark" 148 fi 149 fi 150 if [[ -d "${CIPHER_DIR}" ]]; then 151 if [[ -r "${CIPHER_DIR}/gocryptfs.conf" ]]; then 152 pass "the encrypted private storage folder and its gocryptfs.conf are present: ${CIPHER_DIR}" 153 elif [[ -e "${CIPHER_DIR}/gocryptfs.conf" ]]; then 154 skip "the encrypted storage's gocryptfs.conf exists but you may not read it (not a fault)" 155 else 156 fail "the encrypted private storage has its gocryptfs.conf: ${CIPHER_DIR}" 157 fi 158 elif [[ -e "${CIPHER_DIR}" ]]; then 159 skip "the encrypted private storage folder exists but you may not look inside (not a fault)" 160 else 161 fail "the encrypted private storage folder exists: ${CIPHER_DIR}" 162 fi 163 164 echo "" 165 echo "-- 7. Tools inside the recovery image --" 166 image=""; image_note="" 167 if [[ $# -ge 1 ]]; then 168 image="$1"; image_note="the image you named" 169 else 170 stick_mnt="$(findmnt -rn -o TARGET -S LABEL=AIENOSRECOV 2>/dev/null | head -n 1)" 171 if [[ -n "${stick_mnt}" ]]; then 172 image="${stick_mnt}/aienos-recovery/initrd.img"; image_note="the image on the plugged-in stick" 173 fi 174 fi 175 log="${TMP}/verify_recovery_tools.log" 176 if [[ -n "${image}" ]]; then 177 if [[ -f "${image}" ]]; then 178 TMPDIR="${TMP}" bash "${REPO_ROOT}/scripts/verify_recovery_tools.sh" "${image}" >"${log}" 2>&1 179 rc=$? 180 else 181 echo "image not found: ${image}" >"${log}"; rc=1 182 fi 183 else 184 image_note="a fresh private copy built now (stick not open; this is what Step 4 would write)" 185 TMPDIR="${TMP}" bash "${REPO_ROOT}/scripts/verify_recovery_tools.sh" >"${log}" 2>&1 186 rc=$? 187 fi 188 grep -E '^(FAIL|SKIP)|^image not found' "${log}" | sed 's/^/ /' 189 if [[ ${rc} -eq 3 ]]; then 190 # verify_recovery_tools.sh exits 3 when a check class was skipped (NOT_RUN). 191 fail "every recovery tool is inside ${image_note}: NOT CHECKED in full (verify_recovery_tools.sh skipped a check class and reported NOT_RUN)" 192 else 193 check "every recovery tool is inside ${image_note}" "$([[ ${rc} -eq 0 ]] && echo 1 || echo 0)" 194 fi 195 196 echo "" 197 echo "-- Not checked here (need Drake's reboots or later gates) --" 198 echo "NOT CHECKED startup measurements match across normal boots (Gate 2 reboot snapshots)" 199 echo "NOT CHECKED owner key fingerprints and backups (Gate 3 key ceremony not run yet)" 200 echo "NOT CHECKED owner-signed loader and its fingerprint (Gate 4)" 201 echo "NOT CHECKED Secure Boot variables archived, Gates 0-6 PASS, operator approval" 202 echo "NOT CHECKED the stick actually boots and unlocks with Secure Boot ON (Gate 1, Step 6)" 203 echo "NOT CHECKED every Gate 7 checkpoint A-E (attended hardware boot)" 204 205 echo "" 206 echo "Summary: ${PASSES} passed, ${FAILS} failed, ${SKIPS} skipped" 207 if [[ ${FAILS} -ne 0 ]]; then 208 echo "GATE7_PREFLIGHT: FAIL" 209 exit 1 210 fi 211 echo "GATE7_PREFLIGHT: PASS (only covers what can be checked before the reboots)"