phoebus_os/installer/tests/vm/agentic-hardening-guest.sh
2026-10-12 04:27:15 -07:00

50 lines
2.2 KiB
Bash
Executable file

#!/bin/bash
# Run only in a disposable QEMU overlay, after the serial driver authenticates.
set -euo pipefail
case "$(systemd-detect-virt)" in
qemu|kvm) ;;
*) echo 'disposable QEMU/KVM required'; exit 2 ;;
esac
[[ $(id -u) == 0 ]] || { echo 'root fixture required'; exit 2; }
SYS=/tmp/phoebus-hardening-sys
report() { printf 'CASE %s PASS\n' "$1"; }
# On failure, retain useful native diagnostics without pretending a missing
# case passed. These files contain only deterministic package/snapshot output.
on_exit() {
local rc="$?"
if [[ "$rc" -ne 0 ]]; then
printf 'CASE native-command FAIL exit=%s\n' "$rc"
for output in /tmp/phoebus-hardening-{install,flatpak,nix,snapshot}.out; do
[[ -f "$output" ]] || continue
printf 'Fixture diagnostic: %s\n' "$output"
tail -n 12 "$output"
done
fi
}
trap on_exit EXIT
"$SYS" history --legacy >/tmp/phoebus-hardening-history.out
report deterministic-history
/tmp/phoebus-hardening-isolation --ignored model_system_unit
report root-model-isolation
"$SYS" snapshot --legacy -y >/tmp/phoebus-hardening-snapshot.out
report descriptor-snapshot
if compgen -G '/var/db/pkg/app-misc/hello-*' >/dev/null; then
"$SYS" remove hello --legacy --portage -y >/tmp/phoebus-hardening-remove-before.out 2>&1
fi
"$SYS" install hello --legacy --portage -y >/tmp/phoebus-hardening-install.out 2>&1
# Dedicated workflow must have verified the exact candidate, not mere presence.
grep -q 'verified: app-misc/hello ' /tmp/phoebus-hardening-install.out >/dev/null
report portage-exact
"$SYS" remove hello --legacy --portage -y >/tmp/phoebus-hardening-remove.out 2>&1
report portage-remove
[[ -f /run/phoebus/sys.lock ]] && [[ $(stat -c %a /run/phoebus/sys.lock) == 600 ]]
report persistent-kernel-lock
"$SYS" install org.gnome.Calculator --legacy --flatpak -y >/tmp/phoebus-hardening-flatpak.out 2>&1
grep -q 'verified: Flatpak app org.gnome.Calculator' /tmp/phoebus-hardening-flatpak.out
report flatpak-pin
"$SYS" remove org.gnome.Calculator --legacy --flatpak -y >/tmp/phoebus-hardening-flatpak-remove.out 2>&1
report flatpak-remove
"$SYS" install hello --legacy --nix -y >/tmp/phoebus-hardening-nix.out 2>&1
grep -q 'verified:' /tmp/phoebus-hardening-nix.out
report nix-pin