phoebus_os/installer/tests/vm/rollback-verify.sh
Phoebus 744059b6a2 fix(vm): provision Gentoo release key; truthful rollback gate
Live image ships gnupg plus the Gentoo release key, fingerprint-checked
at build time against the published release-key fingerprints, so the
fail-closed DIGESTS verification cannot be silently skipped.

Rollback harness: authenticate sudo (unique end markers, verified
timestamp, abort instead of hanging), run both guest phases as root,
use explicit --legacy for snapshot/break/undo, fix the verify SYS path,
emit the real systemd state, and preserve the phase-1 transcript.
2026-09-25 19:49:50 -07:00

70 lines
2.2 KiB
Bash
Executable file

#!/bin/bash
# Guest-side post-rollback verification for the disposable VM.
#
# Fetched and run by `serial-driver.py rollback` after the detached reboot. It
# records the restored root/var generation, the package-database fingerprint,
# kernel modules, the /home marker, the recovery BLS entry and `sys rollback
# status`. The host compares these against the pre-rollback markers; a marker
# alone would not prove package-state consistency.
set -uo pipefail
# Verification reads the system state (subvolumes, ESP entries) and must run
# as root; the driver authenticates sudo before invoking this script.
if [ "$(id -u)" != "0" ]; then
echo "===AFTER-NEEDS-ROOT id=$(id -u)==="
echo "===AFTER-DONE==="
exit 1
fi
# `sys` is installed into the target by the installer; fall back to the host
# copy only if it is somehow absent.
if [[ -n "${SYS_BIN:-}" ]]; then
SYS="$SYS_BIN"
elif [[ -x /usr/local/bin/sys ]]; then
SYS=/usr/local/bin/sys
else
SYS=/tmp/sys
fi
USER_NAME="${USERNAME:-phoebus}"
pkg_fingerprint() {
find /var/db/pkg -mindepth 2 -maxdepth 2 -type d 2>/dev/null \
| sort | sha256sum | awk '{print $1}'
}
HOME_MARKER="$(cat "/home/$USER_NAME/rollback-marker.txt" 2>/dev/null || echo missing)"
echo "===AFTER-KNOWN-GOOD pkgs=$(pkg_fingerprint) kernel=$(uname -r) home=$HOME_MARKER==="
echo "===AFTER-SYSTEMD $(systemctl is-system-running 2>&1)==="
if [ -e /etc/phoebus/rollback-broken.txt ]; then
echo "===AFTER-BROKEN-MARKER present==="
else
echo "===AFTER-BROKEN-MARKER absent==="
fi
echo "===AFTER-ROOT==="
btrfs subvolume show / 2>&1 | sed -n '1,10p'
echo "===AFTER-VAR==="
btrfs subvolume show /var 2>&1 | sed -n '1,10p'
if [ -d "/lib/modules/$(uname -r)" ]; then
echo "===AFTER-MODULES ok==="
else
echo "===AFTER-MODULES missing==="
fi
echo "===AFTER-ENTRIES==="
for d in /efi/loader/entries /boot/efi/loader/entries; do
if [ -d "$d" ]; then
ls "$d"
break
fi
done
echo "===AFTER-RECOVERY==="
cat /efi/loader/entries/phoebus-recovery.conf \
/boot/efi/loader/entries/phoebus-recovery.conf 2>/dev/null || true
echo "===AFTER-STATUS==="
"$SYS" rollback status --legacy 2>&1 || true
echo "===AFTER-DONE==="