The live user had NOPASSWD: ALL for the graphical broker. Replace it with an emitted, visudo-validated policy that grants unattended escalation only to /usr/local/bin/phoebus-installer, /usr/local/bin/sys and the systemctl power actions; no ALL, no sh -c and no wildcard. The recovery console is preserved: it logs in with the live-only password and authenticates sudo. build.sh installs the asset, validates it with visudo and refuses any unscoped policy. The GUI harness stages its preseed config with the password-authenticated sudo over a 0600 file instead of bare install, and the read-only greetd check no longer needs sudo.
132 lines
4.4 KiB
Bash
132 lines
4.4 KiB
Bash
#!/usr/bin/env python3
|
|
"""Headless driver for the Phoebus live desktop ISO.
|
|
|
|
Boots the live ISO in a QEMU VM that still has a **graphical device** (so the
|
|
compositor gets a real DRM seat) as well as the serial console, logs in on the
|
|
serial recovery console, runs checks and captures a framebuffer screenshot via
|
|
the QEMU monitor.
|
|
|
|
OVMF_CODE=... OVMF_VARS=... DISK=... ISO=... \
|
|
python3 installer/tests/vm/live-driver.py live
|
|
|
|
A serial console coexisting with graphical hardware is intentional: the checks
|
|
run over the serial line while the desktop renders on the virtual GPU.
|
|
"""
|
|
import os
|
|
import sys
|
|
|
|
import pexpect
|
|
|
|
QEMU = os.environ.get("QEMU_BIN", "qemu-system-x86_64")
|
|
OVMF_CODE = os.environ["OVMF_CODE"]
|
|
OVMF_VARS = os.environ["OVMF_VARS"]
|
|
ISO = os.environ["ISO"]
|
|
DISK = os.environ.get("DISK", "")
|
|
SERIAL_LOG = os.environ.get("SERIAL_LOG", "/tmp/phoebus-live-serial.log")
|
|
MONITOR = os.environ.get("MONITOR", "/tmp/phoebus-live-monitor.sock")
|
|
SHOT = os.environ.get("SHOT", "/tmp/phoebus-live-screen.ppm")
|
|
USER = os.environ.get("LIVE_USER", "phoebus")
|
|
PW = os.environ.get("LIVE_PASSWORD", "phoebus")
|
|
MEM = os.environ.get("VM_MEM", "8192")
|
|
SMP = os.environ.get("VM_SMP", "8")
|
|
BOOT_TIMEOUT = int(os.environ.get("BOOT_TIMEOUT", "600"))
|
|
CHECKS_TIMEOUT = int(os.environ.get("CHECKS_TIMEOUT", "300"))
|
|
|
|
|
|
def args():
|
|
a = [
|
|
"-machine", "q35,accel=kvm",
|
|
"-cpu", "host", "-smp", SMP, "-m", MEM,
|
|
"-drive", f"if=pflash,format=raw,readonly=on,file={OVMF_CODE}",
|
|
"-drive", f"if=pflash,format=raw,file={OVMF_VARS}",
|
|
]
|
|
if DISK:
|
|
a += ["-drive", f"file={DISK},if=virtio,format=qcow2"]
|
|
a += [
|
|
# A real GPU device so the compositor has a DRM node and a logind seat.
|
|
"-device", "virtio-gpu-pci",
|
|
"-netdev", "user,id=n0", "-device", "virtio-net-pci,netdev=n0,romfile=",
|
|
"-device", "virtio-rng-pci",
|
|
"-drive", f"file={ISO},media=cdrom,readonly=on",
|
|
"-boot", "order=d",
|
|
"-vga", "none", "-display", "none",
|
|
"-serial", "stdio",
|
|
"-monitor", f"unix:{MONITOR},server,nowait",
|
|
"-no-reboot",
|
|
]
|
|
return a
|
|
|
|
|
|
def screendump(child):
|
|
"""Ask the QEMU monitor for a framebuffer screenshot."""
|
|
if not os.path.exists(MONITOR):
|
|
return None
|
|
import socket
|
|
import time
|
|
|
|
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
s.settimeout(15)
|
|
try:
|
|
s.connect(MONITOR)
|
|
time.sleep(0.5)
|
|
try:
|
|
s.recv(65536)
|
|
except socket.timeout:
|
|
pass
|
|
s.sendall(b"screendump %s\n" % SHOT.encode())
|
|
time.sleep(2)
|
|
try:
|
|
s.recv(65536)
|
|
except socket.timeout:
|
|
pass
|
|
finally:
|
|
s.close()
|
|
return SHOT if os.path.exists(SHOT) else None
|
|
|
|
|
|
def main():
|
|
log = open(SERIAL_LOG, "w")
|
|
child = pexpect.spawn(QEMU, args(), timeout=BOOT_TIMEOUT, encoding="utf-8",
|
|
codec_errors="replace", maxread=65536)
|
|
child.delaybeforesend = 0.4
|
|
child.logfile = log
|
|
try:
|
|
# The live serial recovery console (hostname is arbitrary).
|
|
idx = child.expect([r"login:", r"[$#] $"], timeout=BOOT_TIMEOUT)
|
|
if idx == 0:
|
|
child.sendline(USER)
|
|
child.expect(r"[Pp]assword:", timeout=60)
|
|
child.sendline(PW)
|
|
child.expect(r"[$#] $", timeout=120)
|
|
|
|
checks = os.environ.get(
|
|
"LIVE_CHECKS",
|
|
"echo ===CHECKS-$(printf START)===; "
|
|
"cat /proc/1/comm; systemctl is-system-running; "
|
|
"systemctl --failed --no-pager; "
|
|
"loginctl list-sessions --no-legend; "
|
|
"pgrep -a mango || echo NO-MANGO; "
|
|
"pgrep -a dms || echo NO-DMS; "
|
|
"pgrep -a qs || pgrep -a quickshell || echo NO-QUICKSHELL; "
|
|
"pgrep -af 'waybar|mako|swayidle|swaylock' || echo NO-DWL-HELPERS; "
|
|
"ls -l /dev/dri 2>&1; "
|
|
"systemctl is-enabled greetd; "
|
|
"echo ===CHECKS-$(printf END)===",
|
|
)
|
|
child.sendline(checks)
|
|
child.expect("===CHECKS-END===", timeout=CHECKS_TIMEOUT)
|
|
shot = screendump(child)
|
|
print("checks complete", flush=True)
|
|
print("screenshot", shot, flush=True)
|
|
finally:
|
|
child.close(force=True)
|
|
log.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
mode = sys.argv[1] if len(sys.argv) > 1 else ""
|
|
if mode == "live":
|
|
main()
|
|
else:
|
|
print(__doc__)
|
|
sys.exit(2)
|