From de42668ab0ae0ec412289e8b2674e83fa7d10b2b Mon Sep 17 00:00:00 2001 From: mrbobbytables Date: Fri, 11 Sep 2026 19:09:52 +0000 Subject: [PATCH] test(installer): validate encrypted offline installations Extend the Utah installer pipeline with Dakota-style encrypted installation coverage: - Add cryptsetup to packages/utah.toml for LUKS volume creation and management. - Add luks-unlock.py to automate Plymouth passphrase prompt detection and unlock via QEMU monitor sendkey. - Implement offline-e2e.sh supporting network-isolated Fisherman installation to LUKS-encrypted disk from embedded containers-storage payload, unlocking the deployment, and verifying graphical target and Flatpak availability. - Add CI workflow (.github/workflows/iso.yml) building production UEFI ISO, executing offline LUKS installation and boot gates, and publishing release artifacts or retaining diagnostics on failure. - Add unit tests for luks-unlock.py in tests/unit/test_luks_unlock.py. - Update Justfile with iso-e2e recipe and static checks. - Document local testing and CI workflows. Assisted-by: Gemini 3.8 Flash via GitHub Copilot Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: mrbobbytables --- .github/workflows/iso.yml | 275 +++++++++++++++++ AGENTS.md | 1 + Justfile | 19 ++ docs/skills/ci-workflows.md | 3 + docs/skills/local-testing.md | 18 ++ iso/live/Containerfile | 10 +- iso/live/src/configure-live.sh | 8 +- iso/scripts/build-iso.sh | 24 +- iso/scripts/luks-unlock.py | 352 ++++++++++++++++++++++ iso/scripts/offline-e2e.sh | 519 +++++++++++++++++++++++++++++++++ packages/utah.toml | 6 + tests/unit/test_luks_unlock.py | 87 ++++++ 12 files changed, 1311 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/iso.yml create mode 100755 iso/scripts/luks-unlock.py create mode 100755 iso/scripts/offline-e2e.sh create mode 100644 tests/unit/test_luks_unlock.py diff --git a/.github/workflows/iso.yml b/.github/workflows/iso.yml new file mode 100644 index 00000000..19fad8ef --- /dev/null +++ b/.github/workflows/iso.yml @@ -0,0 +1,275 @@ +name: Build, test, and publish Utah ISO + +run-name: >- + Utah ISO validation for ${{ github.event.workflow_run.head_sha || inputs.image || 'manual' }} + +on: + workflow_run: + workflows: ["Post-Testing E2E"] + types: [completed] + branches: [testing] + workflow_dispatch: + inputs: + image: + description: "Exact x86_64 image reference to test (must use @sha256:...)" + required: false + type: string + source_run_id: + description: "Successful Build Utah run containing image digest artifacts" + required: false + type: string + encryption: + description: "Installation encryption mode (luks or none)" + required: false + default: "luks" + type: choice + options: + - luks + - none + +permissions: {} + +concurrency: + group: utah-iso-${{ github.event.workflow_run.head_sha || github.run_id }} + cancel-in-progress: false + +jobs: + resolve-image: + name: Resolve exact candidate image + if: github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' + runs-on: ubuntu-24.04 + permissions: + actions: read + contents: read + packages: read + outputs: + image: ${{ steps.resolve.outputs.image }} + payload_ref: ${{ steps.resolve.outputs.payload_ref }} + source_digest: ${{ steps.resolve.outputs.source_digest }} + steps: + - name: Resolve exact x86_64 image digest + id: resolve + env: + GH_TOKEN: ${{ github.token }} + DISPATCH_IMAGE: ${{ inputs.image }} + DISPATCH_RUN_ID: ${{ inputs.source_run_id }} + EVENT_SHA: ${{ github.event.workflow_run.head_sha }} + REPOSITORY: ${{ github.repository }} + OWNER: ${{ github.repository_owner }} + run: | + set -euo pipefail + build_run_id=manual + image="${DISPATCH_IMAGE:-}" + source_digest="" + + if [[ -n "$image" ]]; then + if [[ ! "$image" =~ ^ghcr\.io/[^/]+/utah@sha256:[0-9a-f]{64}$ ]]; then + echo "image must be an exact ghcr.io//utah@sha256: reference" >&2 + exit 1 + fi + source_digest="${image##*@}" + else + build_run_id="${DISPATCH_RUN_ID:-}" + if [[ -z "$build_run_id" && -n "${EVENT_SHA:-}" ]]; then + build_run_id="$(gh run list \ + --repo "$REPOSITORY" \ + --workflow build.yml \ + --commit "$EVENT_SHA" \ + --event push \ + --status success \ + --limit 1 \ + --json databaseId \ + --jq '.[0].databaseId')" + fi + [[ -n "$build_run_id" ]] || { + echo "No successful Build Utah run was supplied or found for ${EVENT_SHA:-the manual run}" >&2 + exit 1 + } + + digest_dir="${RUNNER_TEMP}/utah-build-digests" + mkdir -p "$digest_dir" + gh run download "$build_run_id" \ + --repo "$REPOSITORY" \ + --pattern 'image-digest-testing-*' \ + --dir "$digest_dir" + + mapfile -t digests < <( + grep -RhsE '^utah=sha256:[0-9a-f]{64}$' "$digest_dir" \ + | cut -d= -f2- \ + | sort -u + ) + [[ "${#digests[@]}" -eq 1 ]] || { + printf 'Expected exactly one main utah digest, found %s\n' "${#digests[@]}" >&2 + printf '%s\n' "${digests[@]}" >&2 + exit 1 + } + source_digest="${digests[0]}" + image="ghcr.io/${OWNER,,}/utah@${source_digest}" + fi + + payload_ref="ghcr.io/${OWNER,,}/utah:ci-$GITHUB_RUN_ID" + { + echo "image=$image" + echo "payload_ref=$payload_ref" + echo "source_digest=$source_digest" + } >> "$GITHUB_OUTPUT" + echo "Candidate: ${image}" + echo "Payload reference inside ISO: ${payload_ref}" + echo "Build run: ${build_run_id}" + + iso-e2e: + name: Build, install, and boot x86_64 UEFI ISO + needs: resolve-image + if: needs.resolve-image.result == 'success' + runs-on: ubuntu-24.04 + timeout-minutes: 360 + permissions: + contents: read + packages: read + env: + IMAGE: ${{ needs.resolve-image.outputs.image }} + PAYLOAD_REF: ${{ needs.resolve-image.outputs.payload_ref }} + SOURCE_DIGEST: ${{ needs.resolve-image.outputs.source_digest }} + ENCRYPTION_MODE: ${{ inputs.encryption || 'luks' }} + ISO_OUTPUT: ${{ github.workspace }}/.ci/utah-iso-output + ISO_PATH: ${{ github.workspace }}/.ci/utah-iso-output/utah-live.iso + E2E_WORK: ${{ github.workspace }}/.ci/utah-iso-output/e2e + steps: + - name: Checkout + uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5 + + - name: Install ISO and VM tooling + run: | + set -euo pipefail + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + podman skopeo squashfs-tools xorriso dosfstools mtools \ + qemu-system-x86 qemu-utils ovmf ffmpeg sshpass cryptsetup-bin + sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc + mkdir -p "$ISO_OUTPUT" + df -h / + + - name: Pull exact candidate image + env: + GH_TOKEN: ${{ github.token }} + run: | + set -euo pipefail + echo "$GH_TOKEN" | podman login ghcr.io \ + --username "$GITHUB_ACTOR" --password-stdin + podman pull "$IMAGE" + architecture="$(podman image inspect --format '{{.Architecture}}' "$IMAGE")" + case "$architecture" in + amd64|x86_64) ;; + *) echo "Expected an x86_64 image, got ${architecture}" >&2; exit 1 ;; + esac + echo "Pulled ${IMAGE} (${architecture})" + + - name: Build UEFI ISO without publishing it + run: | + set -euo pipefail + mkdir -p "${RUNNER_TEMP}/utah-iso-stage" + UTAH_ISO_WORKDIR="${RUNNER_TEMP}/utah-iso-stage" \ + bash iso/scripts/build-iso.sh \ + "$IMAGE" "$ISO_PATH" "Utah Live" 1 "$PAYLOAD_REF" "$IMAGE" + test -s "$ISO_PATH" + xorriso -indev "$ISO_PATH" -report_el_torito plain \ + | tee "${ISO_OUTPUT}/el-torito.txt" + grep -qi 'EFI' "${ISO_OUTPUT}/el-torito.txt" + sha256sum "$ISO_PATH" > "${ISO_OUTPUT}/utah-live.iso.sha256" + cat > "${ISO_OUTPUT}/candidate.txt" <&2 + exit 1 + fi + done + + - name: Write final ISO manifest + if: success() + env: + MANIFEST: ${{ github.workspace }}/.ci/utah-iso-output/manifest.json + run: | + set -euo pipefail + python3 - "$MANIFEST" "$ISO_PATH" "$IMAGE" "$SOURCE_DIGEST" "$PAYLOAD_REF" "$ENCRYPTION_MODE" <<'PY' + import hashlib + import json + import pathlib + import sys + + manifest, iso, image, digest, payload, encryption = sys.argv[1:] + path = pathlib.Path(iso) + sha256 = hashlib.sha256() + with path.open("rb") as source: + for chunk in iter(lambda: source.read(1024 * 1024), b""): + sha256.update(chunk) + pathlib.Path(manifest).write_text(json.dumps({ + "artifact": path.name, + "sha256": sha256.hexdigest(), + "architecture": "x86_64", + "firmware": "UEFI", + "source_image": image, + "source_digest": digest, + "embedded_payload": payload, + "encryption": encryption, + "live_marker": "UTAH_LIVE_READY", + "installed_marker": "UTAH_INSTALLED_GRAPHICAL_OK", + "flatpaks_verified": True, + "network": { + "live_control": "qemu-user-restrict-on", + "installed": "none", + }, + }, indent=2) + "\n") + PY + + - name: Publish production ISO and checksum + if: success() + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: utah-iso-x86_64-${{ github.run_id }} + path: | + ${{ github.workspace }}/.ci/utah-iso-output/utah-live.iso + ${{ github.workspace }}/.ci/utah-iso-output/utah-live.iso.sha256 + ${{ github.workspace }}/.ci/utah-iso-output/candidate.txt + ${{ github.workspace }}/.ci/utah-iso-output/el-torito.txt + ${{ github.workspace }}/.ci/utah-iso-output/manifest.json + ${{ github.workspace }}/.ci/utah-iso-output/e2e/live-serial.log + ${{ github.workspace }}/.ci/utah-iso-output/e2e/installed-serial.log + ${{ github.workspace }}/.ci/utah-iso-output/e2e/e2e-summary.txt + ${{ github.workspace }}/.ci/utah-iso-output/e2e/screenshots/ + if-no-files-found: error + retention-days: 30 + + - name: Retain failed ISO diagnostics + if: failure() + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: utah-iso-failure-${{ github.run_id }} + path: ${{ github.workspace }}/.ci/utah-iso-output/ + if-no-files-found: warn + retention-days: 14 diff --git a/AGENTS.md b/AGENTS.md index 92965df2..0b67a98e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -26,6 +26,7 @@ just check-desktop-contract # in-image verifiers against a built image just generate-bootable-image testing # bootc install to-disk -> output/bootable.raw just boot-vm # QEMU/noVNC; confirm GDM + GNOME Shell render just iso testing && just boot-iso # live ISO build + boot (see docs/skills/local-testing.md) +just iso-e2e # network-isolated live ISO install and graphical boot (LUKS/none) ``` `just check` is the gate CI runs first; a change that fails it fails the whole diff --git a/Justfile b/Justfile index 6706129f..b4330bbb 100644 --- a/Justfile +++ b/Justfile @@ -46,6 +46,13 @@ check: bash -n iso/live/src/configure-live.sh bash -n iso/live/src/install-flatpaks.sh bash -n iso/scripts/build-iso.sh + test -f iso/scripts/offline-e2e.sh + bash -n iso/scripts/offline-e2e.sh + test -f iso/scripts/luks-unlock.py + python3 -m py_compile iso/scripts/luks-unlock.py + test -f tests/unit/test_luks_unlock.py + python3 -m unittest tests/unit/test_luks_unlock.py + grep -q 'cryptsetup' packages/utah.toml python3 -m json.tool iso/live/src/etc/bootc-installer/images.json >/dev/null python3 -m json.tool iso/live/src/etc/bootc-installer/recipe.json >/dev/null grep -q 'org.bootcinstaller.Installer' iso/live/src/install-flatpaks.sh @@ -369,6 +376,18 @@ boot-iso: --volume "$iso:/boot.iso:ro" \ ghcr.io/qemus/qemu:latest +# Run network-isolated live ISO install and graphical boot E2E test in QEMU. +# Supports encryption="luks" (default) or encryption="none". +iso-e2e iso="" payload_ref="ghcr.io/projectbluefin/utah:testing" encryption="luks": + #!/usr/bin/env bash + set -euo pipefail + iso_path="{{ iso }}" + if [[ -z "$iso_path" ]]; then + iso_path="$(realpath "{{ base_dir }}/utah-live.iso")" + fi + test -f "$iso_path" || { echo "Missing ISO: $iso_path; run just iso" >&2; exit 1; } + UTAH_E2E_ENCRYPTION="{{ encryption }}" bash iso/scripts/offline-e2e.sh "$iso_path" "{{ payload_ref }}" + # Boot the installed Utah disk through QEMU-for-Docker. Open the printed URL # and confirm GDM appears and the GNOME Shell desktop renders. The disk is # mounted at /boot.img and -snapshot keeps the test disposable. diff --git a/docs/skills/ci-workflows.md b/docs/skills/ci-workflows.md index 24c8c643..2072667b 100644 --- a/docs/skills/ci-workflows.md +++ b/docs/skills/ci-workflows.md @@ -30,6 +30,9 @@ each pinned to a SHA tagged `v1`: - `.github/workflows/promote-testing-to-main.yml` -- pushes to `testing`, a nightly cron, and manual dispatch. - `.github/workflows/sync-main-to-testing.yml` -- every push to `main`. +- `.github/workflows/iso.yml` -- builds, tests, and publishes the production + x86_64 UEFI ISO after testing promotion, running offline LUKS-encrypted + installation and graphical boot gates in QEMU. CI delegates builds, vulnerability reporting, SBOMs, keyless signatures, provenance, caching, and rechunking to `projectbluefin/actions@v1` (originated diff --git a/docs/skills/local-testing.md b/docs/skills/local-testing.md index 67755c90..20a1d1af 100644 --- a/docs/skills/local-testing.md +++ b/docs/skills/local-testing.md @@ -119,6 +119,24 @@ just boot-iso # QEMU/noVNC live-session validation just iso testing 1 # optional live-session SSH diagnostics (debug=1) ``` +## Offline ISO and encrypted installation validation + +The offline installer test validates the production ISO end to end in QEMU: +boots the live ISO, verifies the live graphical desktop, executes a network-isolated +installation from the embedded OCI payload onto a LUKS2 encrypted volume, +unlocks the encrypted disk via Plymouth (`luks-unlock.py`), and validates that +the installed deployment reaches the graphical target with default Flatpaks intact: + +```bash +just iso testing 1 +just iso-e2e output/utah-live.iso ghcr.io/projectbluefin/utah:testing luks +``` + +Key features: +- Supports `encryption="luks"` (default) or `encryption="none"`. +- `iso/scripts/luks-unlock.py` monitors QEMU serial and framebuffer screendumps to detect Plymouth's passphrase prompt and inject the unlock key. +- Captures serial logs (`live-serial.log`, `installed-serial.log`), framebuffer screenshots (`live-desktop.png`, `installed-desktop.png`), and retains failed disk images on error. + The result is `output/utah-live.iso`, assembled with systemd-boot, a `UTAH_LIVE` dmsquash-live root, and a serial `UTAH_LIVE_READY` marker. It is intended to prove live desktop boot first; bootc-installer/offline payload diff --git a/iso/live/Containerfile b/iso/live/Containerfile index 0c271b1b..46bad443 100644 --- a/iso/live/Containerfile +++ b/iso/live/Containerfile @@ -4,12 +4,14 @@ ARG SOURCE_IMAGE=localhost/utah:testing FROM ${SOURCE_IMAGE} -# TARGET_IMAGE is the published image name recorded in the installer recipe -# and embedded offline store. SOURCE_IMAGE may be localhost for development; -# it must never leak into the released recipe. +# TARGET_IMAGE is the tag imported into the embedded offline store. The +# separately supplied TRACKING_IMAGE is the exact remote ref recorded for +# updates. SOURCE_IMAGE may be localhost for development; it must never leak +# into the released recipe. ARG TARGET_IMAGE=ghcr.io/projectbluefin/utah:testing +ARG TRACKING_IMAGE=ghcr.io/projectbluefin/utah:testing ARG DEBUG=0 -ENV TARGET_IMAGE=${TARGET_IMAGE} DEBUG=${DEBUG} +ENV TARGET_IMAGE=${TARGET_IMAGE} TRACKING_IMAGE=${TRACKING_IMAGE} DEBUG=${DEBUG} # Utah already carries dracut-live; systemd-boot is added only to the live # environment because the installed image uses the Hummingbird bootloader. diff --git a/iso/live/src/configure-live.sh b/iso/live/src/configure-live.sh index bcba740d..78ab4d1a 100644 --- a/iso/live/src/configure-live.sh +++ b/iso/live/src/configure-live.sh @@ -5,7 +5,10 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" INSTALLER_APP_ID=org.bootcinstaller.Installer +# TARGET_IMAGE names the OCI object embedded in the live image. The tracking +# reference can remain the exact digest that was validated before composition. TARGET_IMAGE="${TARGET_IMAGE:-ghcr.io/projectbluefin/utah:testing}" +TRACKING_IMAGE="${TRACKING_IMAGE:-${TARGET_IMAGE}}" # Live media must not apply update or unified-storage policy intended for an # installed image. The payload embedded in the squashfs is the install source. @@ -97,7 +100,8 @@ cp "${SCRIPT_DIR}/etc/bootc-installer/images.json" /etc/bootc-installer/images.j python3 - </dev/null || rm -rf "${WORK}" 2>/dev/null || true +} +trap cleanup_work EXIT cd "${ROOT}" echo "Building live environment from ${IMAGE}" podman build --layers \ + --cap-add sys_admin --security-opt label=disable \ --build-arg SOURCE_IMAGE="${IMAGE}" \ --build-arg TARGET_IMAGE="${PUBLISHED_IMAGE}" \ + --build-arg TRACKING_IMAGE="${TRACKING_IMAGE}" \ --build-arg DEBUG="${DEBUG}" \ --tag "${LIVE_IMAGE}" \ --file iso/live/Containerfile iso/live diff --git a/iso/scripts/luks-unlock.py b/iso/scripts/luks-unlock.py new file mode 100755 index 00000000..546f15e0 --- /dev/null +++ b/iso/scripts/luks-unlock.py @@ -0,0 +1,352 @@ +#!/usr/bin/env python3 +""" +Automate LUKS passphrase entry for a VM booting with Plymouth. + +Adapted from projectbluefin/iso (src/luks-unlock.py, Apache-2.0) for Utah's +encrypted offline installer validation pipeline. Uses only Python standard +library modules so no external utilities (e.g. socat) are required. + +Plymouth renders the passphrase prompt on the EFI framebuffer and serial console. +This tool detects the prompt via serial output or screendump hash stabilization, +injects the passphrase keystrokes via QEMU HMP sendkey, and monitors boot +progression to graphical session. + +Usage: + qemu mode: luks-unlock.py qemu [ssh-port] + libvirt mode: luks-unlock.py libvirt + +Exit codes: + 0 — passphrase sent and boot succeeded (display re-stabilised after unlock or serial confirmed) + 1 — error (timed out, passphrase prompt never appeared, etc.) + 2 — passphrase sent but boot resulted in emergency shell +""" + +import hashlib +import os +import re +import socket +import subprocess +import sys +import time + +POLL_INTERVAL = 3 +PLYMOUTH_WAIT = 10 +PROMPT_DEADLINE = 300 +BOOT_DEADLINE = 900 +DARK_SCREEN_OVERRIDE_S = 90 + + +def monitor_command(sock_path: str, command: str, settle: float = 0.5) -> str: + """Send one HMP command to a QEMU monitor socket and return the response.""" + with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as client: + client.settimeout(10) + client.connect(sock_path) + client.sendall(command.encode() + b"\n") + time.sleep(settle) + chunks = [] + client.settimeout(1) + try: + while True: + data = client.recv(4096) + if not data: + break + chunks.append(data) + except (socket.timeout, TimeoutError): + pass + return b"".join(chunks).decode(errors="replace") + + +def qemu_screendump(sock: str, path: str) -> tuple: + """Return (brightness, md5_hash) for the screendump, or (-1, '') on error.""" + try: + monitor_command(sock, f"screendump {path}") + except OSError: + return -1, "" + time.sleep(0.5) + try: + with open(path, "rb") as f: + data = f.read() + except OSError: + return -1, "" + md5 = hashlib.md5(data).hexdigest() + try: + header_end = data.index(b"255\n") + 4 + except ValueError: + return -1, "" + pixel_data = data[header_end:] + if not pixel_data: + return -1, "" + sampled = pixel_data[::100] + return sum(sampled) / len(sampled), md5 + + +def qemu_send_passphrase(sock: str, passphrase: str): + """Send passphrase keystrokes followed by Enter over QEMU monitor.""" + key_map = {c: c for c in "abcdefghijklmnopqrstuvwxyz0123456789"} + key_map["-"] = "minus" + key_map["_"] = "shift-minus" + key_map[" "] = "spc" + + def _sendkey(key: str): + monitor_command(sock, f"sendkey {key}", settle=0.05) + + for ch in passphrase: + key = key_map.get(ch) + if key is None: + print(f"[luks-unlock] WARNING: no key mapping for {ch!r}", file=sys.stderr) + continue + _sendkey(key) + time.sleep(0.1) + _sendkey("ret") + + +def qemu_check_serial(serial_log: str) -> str: + """Return 'plymouth', 'gdm', 'graphical-ok', 'emergency', or ''.""" + try: + with open(serial_log, errors="replace") as f: + raw = f.read() + except OSError: + return "" + content = re.sub(r"\x1b\[[0-9;]*[A-Za-z]", "", raw) + content_flat = " ".join(content.split()) + + if "emergency mode" in content or "emergency shell" in content: + return "emergency" + if "UTAH_INSTALLED_GRAPHICAL_OK" in raw or "UTAH_INSTALLED_ENCRYPTED_OK" in raw: + return "graphical-ok" + if "Started gnome-initial-setup" in content_flat: + return "gnome-initial-setup" + if "Started gdm.service" in content_flat or "Started GNOME Display Manager" in content_flat: + return "gdm" + if "Reached target Graphical Interface" in content_flat or "Reached target graphical.target" in content_flat: + return "graphical-target" + if "Please enter passphrase for disk" in raw or "Passphrase:" in raw: + return "plymouth" + return "" + + +def ssh_reachable(port: int, timeout: int = 5) -> bool: + """Return True if sshd on localhost:port responds with an SSH banner.""" + try: + with socket.create_connection(("127.0.0.1", port), timeout=timeout) as s: + banner = s.recv(64) + return banner.startswith(b"SSH-") + except OSError: + return False + + +def run_qemu(monitor_sock: str, passphrase: str, serial_log: str, ssh_port: int = 0): + snap = "/tmp/luks-unlock-snap.ppm" + CONTENT_THRESHOLD = 0.5 + STABLE_POLLS = 2 + + print(f"[luks-unlock] qemu mode — watching monitor {monitor_sock}...", flush=True) + deadline = time.time() + PROMPT_DEADLINE + + had_content = False + stable_count = 0 + prev_hash = "" + + while time.time() < deadline: + serial_result = qemu_check_serial(serial_log) + if serial_result == "plymouth": + print("[luks-unlock] Plymouth passphrase prompt detected via serial", flush=True) + brightness, md5 = qemu_screendump(monitor_sock, snap) + prev_hash = md5 + print(f"[luks-unlock] Waiting {PLYMOUTH_WAIT}s for Plymouth to settle...", flush=True) + time.sleep(PLYMOUTH_WAIT) + print("[luks-unlock] Sending passphrase via QEMU monitor sendkey...", flush=True) + qemu_send_passphrase(monitor_sock, passphrase) + print("[luks-unlock] Passphrase sent — watching for boot...", flush=True) + break + + brightness, md5 = qemu_screendump(monitor_sock, snap) + print(f"[luks-unlock] screendump brightness={brightness:.2f} hash={md5[:8]}", flush=True) + + if brightness < 0: + stable_count = 0 + time.sleep(POLL_INTERVAL) + continue + + if not had_content and brightness > CONTENT_THRESHOLD: + had_content = True + print(f"[luks-unlock] VM is rendering (brightness {brightness:.2f})", flush=True) + + if had_content: + if md5 == prev_hash: + stable_count += 1 + else: + stable_count = 0 + prev_hash = md5 + + if had_content and stable_count >= STABLE_POLLS: + print( + f"[luks-unlock] Plymouth prompt stable" + f" (brightness={brightness:.2f}, {stable_count} identical polls)", + flush=True, + ) + print(f"[luks-unlock] Waiting {PLYMOUTH_WAIT}s for Plymouth to settle...", flush=True) + time.sleep(PLYMOUTH_WAIT) + print("[luks-unlock] Sending passphrase via QEMU monitor sendkey...", flush=True) + qemu_send_passphrase(monitor_sock, passphrase) + print("[luks-unlock] Passphrase sent — watching for boot...", flush=True) + break + + time.sleep(POLL_INTERVAL) + else: + print("[luks-unlock] ERROR: Plymouth takeover never detected", file=sys.stderr) + sys.exit(1) + + deadline = time.time() + BOOT_DEADLINE + passphrase_time = time.time() + passphrase_hash = prev_hash + screen_changed = False + gnome_stable_count = 0 + + while time.time() < deadline: + result = qemu_check_serial(serial_log) + if result == "emergency": + print("[luks-unlock] RESULT: emergency shell reached", flush=True) + sys.exit(2) + if result in ("graphical-ok", "graphical-target", "gnome-initial-setup", "gdm"): + print(f"[luks-unlock] RESULT: boot succeeded ({result} confirmed via serial)", flush=True) + sys.exit(0) + + if ssh_port and ssh_reachable(ssh_port): + print(f"[luks-unlock] RESULT: boot succeeded (sshd banner on port {ssh_port})", flush=True) + sys.exit(0) + + elapsed = time.time() - passphrase_time + if not screen_changed and elapsed > DARK_SCREEN_OVERRIDE_S: + if not ssh_port: + print( + f"[luks-unlock] Dark-screen override: screen unchanged for " + f"{int(elapsed)}s and no SSH port configured — assuming boot proceeded", + flush=True, + ) + sys.exit(0) + + brightness, md5 = qemu_screendump(monitor_sock, snap) + if md5 != passphrase_hash and not screen_changed: + screen_changed = True + print("[luks-unlock] Screen changed after passphrase — LUKS unlocked, boot proceeding", flush=True) + + GNOME_THRESHOLD = 1.8 + if md5 == prev_hash: + gnome_stable_count += 1 + else: + gnome_stable_count = 0 + prev_hash = md5 + + if screen_changed and gnome_stable_count >= 1: + if brightness > GNOME_THRESHOLD: + print( + f"[luks-unlock] RESULT: boot succeeded (framebuffer stable, brightness={brightness:.2f})", + flush=True, + ) + sys.exit(0) + + time.sleep(POLL_INTERVAL) + + print("[luks-unlock] ERROR: boot timed out after passphrase", file=sys.stderr) + sys.exit(1) + + +def virsh_screenshot_size(vm: str, path: str) -> int: + r = subprocess.run(["virsh", "screenshot", vm, path], capture_output=True) + if r.returncode != 0: + return 0 + try: + return os.path.getsize(path) + except OSError: + return 0 + + +def virsh_send_passphrase(vm: str, passphrase: str): + key_map = {c: f"KEY_{c.upper()}" for c in "abcdefghijklmnopqrstuvwxyz"} + key_map.update({str(i): f"KEY_{i}" for i in range(10)}) + key_map["-"] = "KEY_MINUS" + key_map["_"] = "KEY_MINUS" + key_map[" "] = "KEY_SPACE" + + for ch in passphrase: + key = key_map.get(ch) + if key is None: + continue + subprocess.run(["virsh", "send-key", vm, "--codeset", "linux", key], capture_output=True) + time.sleep(0.08) + subprocess.run(["virsh", "send-key", vm, "--codeset", "linux", "KEY_ENTER"], capture_output=True) + + +def virsh_dhcp_ip(mac: str) -> str: + r = subprocess.run(["virsh", "net-dhcp-leases", "default"], capture_output=True, text=True) + for line in r.stdout.splitlines(): + if mac.lower() in line.lower(): + for part in line.split(): + if "/" in part and "." in part: + return part.split("/")[0] + return "" + + +def run_libvirt(vm: str, passphrase: str, mac: str): + snap = "/tmp/luks-unlock-snap.png" + seen_content = False + + print(f"[luks-unlock] libvirt mode — watching {vm} for Plymouth takeover...", flush=True) + deadline = time.time() + PROMPT_DEADLINE + + while time.time() < deadline: + size = virsh_screenshot_size(vm, snap) + if not seen_content and size > 4096: + seen_content = True + print("[luks-unlock] Boot content visible (OVMF/bootloader)", flush=True) + if seen_content and size <= 4096: + print(f"[luks-unlock] Plymouth has display — waiting {PLYMOUTH_WAIT}s...", flush=True) + time.sleep(PLYMOUTH_WAIT) + virsh_send_passphrase(vm, passphrase) + print("[luks-unlock] Passphrase sent — waiting for boot...", flush=True) + break + time.sleep(POLL_INTERVAL) + else: + print("[luks-unlock] ERROR: Plymouth takeover never detected", file=sys.stderr) + sys.exit(1) + + deadline = time.time() + BOOT_DEADLINE + while time.time() < deadline: + ip = virsh_dhcp_ip(mac) + if ip: + print(f"[luks-unlock] RESULT: boot succeeded — guest IP {ip}", flush=True) + sys.exit(0) + time.sleep(5) + + print("[luks-unlock] WARNING: passphrase sent but no DHCP lease within timeout", file=sys.stderr) + sys.exit(2) + + +def main(): + if len(sys.argv) < 2: + print("Usage: luks-unlock.py [qemu|libvirt] ...", file=sys.stderr) + sys.exit(1) + + mode = sys.argv[1] + if mode == "qemu": + if len(sys.argv) < 5: + print("Usage: luks-unlock.py qemu [ssh-port]", file=sys.stderr) + sys.exit(1) + monitor_sock = sys.argv[2] + passphrase = sys.argv[3] + serial_log = sys.argv[4] + ssh_port = int(sys.argv[5]) if len(sys.argv) > 5 else 0 + run_qemu(monitor_sock, passphrase, serial_log, ssh_port) + elif mode == "libvirt": + if len(sys.argv) < 5: + print("Usage: luks-unlock.py libvirt ", file=sys.stderr) + sys.exit(1) + run_libvirt(sys.argv[2], sys.argv[3], sys.argv[4]) + else: + print(f"Unknown mode: {mode}", file=sys.stderr) + sys.exit(1) + + +if __name__ == "__main__": + main() diff --git a/iso/scripts/offline-e2e.sh b/iso/scripts/offline-e2e.sh new file mode 100755 index 00000000..b95e3295 --- /dev/null +++ b/iso/scripts/offline-e2e.sh @@ -0,0 +1,519 @@ +#!/usr/bin/env bash +# Boot a Utah live ISO, install its embedded OCI payload with Fisherman (with +# optional LUKS encryption), and boot the installed system without the ISO or a network. +# Usage: offline-e2e.sh ISO PAYLOAD_REF [TARGET_IMGREF] +# +# The live VM has a QEMU user-mode network only for the SSH control channel; +# 'restrict=on' prevents the guest from reaching the host or the outside +# network. The installed VM has no network device at all (-net none). This is +# deliberate: a successful install must come from the containers-storage payload +# in the ISO, not from a registry pull that happens to be available in CI. +set -euo pipefail + +ISO="${1:?live ISO path is required}" +PAYLOAD_REF="${2:?embedded payload reference is required}" +TARGET_IMGREF="${3:-${PAYLOAD_REF}}" +ENCRYPTION="${UTAH_E2E_ENCRYPTION:-luks}" +PASSPHRASE="${UTAH_E2E_PASSPHRASE:-testpassphrase}" +WORK="${UTAH_E2E_WORK:-/var/tmp/utah-iso-e2e}" +TEST_USER="${UTAH_E2E_USER:-utahtest}" +TEST_PASSWORD="${UTAH_E2E_PASSWORD:-utahtest}" +LIVE_PASSWORD="${UTAH_E2E_LIVE_PASSWORD:-live}" +SSH_PORT="${UTAH_E2E_SSH_PORT:-2222}" +SSH_TIMEOUT="${UTAH_E2E_SSH_TIMEOUT:-900}" +BOOT_TIMEOUT="${UTAH_E2E_BOOT_TIMEOUT:-900}" +QEMU_MEMORY="${UTAH_E2E_MEMORY:-8192}" +QEMU_CPUS="${UTAH_E2E_CPUS:-4}" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +ISO="$(realpath "${ISO}")" +mkdir -p "${WORK}/screenshots" +WORK="$(realpath "${WORK}")" +SHOTS="${WORK}/screenshots" +INSTALL_DISK="${WORK}/installed.qcow2" +LIVE_VARS="${WORK}/ovmf-vars-live.fd" +INSTALLED_VARS="${WORK}/ovmf-vars-installed.fd" +LIVE_MONITOR="${WORK}/live-monitor.sock" +INSTALLED_MONITOR="${WORK}/installed-monitor.sock" +LIVE_SERIAL="${WORK}/live-serial.log" +INSTALLED_SERIAL="${WORK}/installed-serial.log" +LIVE_PID_FILE="${WORK}/live.pid" +INSTALLED_PID_FILE="${WORK}/installed.pid" + +fail() { + echo "FAIL: $*" >&2 + exit 1 +} + +[[ -f "${ISO}" ]] || fail "ISO does not exist: ${ISO}" +[[ "${PAYLOAD_REF}" =~ ^[A-Za-z0-9./_-]+:[A-Za-z0-9._-]+$ ]] || \ + fail "payload reference must be a tag-shaped OCI reference: ${PAYLOAD_REF}" +[[ "${TARGET_IMGREF}" =~ ^[A-Za-z0-9./_-]+(:[A-Za-z0-9._-]+|@sha256:[0-9a-f]{64})$ ]] || \ + fail "tracking image must be a tag or digest OCI reference: ${TARGET_IMGREF}" + +QEMU="${QEMU_BINARY:-$(command -v qemu-system-x86_64 || true)}" +QEMU_IMG="${QEMU_IMG_BINARY:-$(command -v qemu-img || true)}" +[[ -n "${QEMU}" ]] || fail "qemu-system-x86_64 is not installed" +[[ -n "${QEMU_IMG}" ]] || fail "qemu-img is not installed" +command -v sshpass >/dev/null 2>&1 || fail "sshpass is not installed" + +OVMF_CODE="" +for candidate in \ + /usr/share/OVMF/OVMF_CODE_4M.fd \ + /usr/share/OVMF/OVMF_CODE.fd \ + /usr/share/edk2/ovmf/OVMF_CODE.fd \ + /usr/share/edk2/ovmf/OVMF_CODE_4M.fd \ + /usr/share/ovmf/OVMF.fd \ + /home/linuxbrew/.linuxbrew/share/qemu/edk2-x86_64-code.fd; do + if [[ -f "${candidate}" ]]; then + OVMF_CODE="${candidate}" + break + fi +done +OVMF_VARS_SOURCE="" +for candidate in \ + /usr/share/OVMF/OVMF_VARS_4M.fd \ + /usr/share/OVMF/OVMF_VARS.fd \ + /usr/share/edk2/ovmf/OVMF_VARS.fd \ + /usr/share/edk2/ovmf/OVMF_VARS_4M.fd \ + /usr/share/ovmf/OVMF_VARS.fd \ + /home/linuxbrew/.linuxbrew/share/qemu/edk2-i386-vars.fd; do + if [[ -f "${candidate}" ]]; then + OVMF_VARS_SOURCE="${candidate}" + break + fi +done +[[ -n "${OVMF_CODE}" ]] || fail "OVMF code firmware is not installed" +[[ -n "${OVMF_VARS_SOURCE}" ]] || fail "OVMF variable store is not installed" + +if [[ -r /dev/kvm ]]; then + ACCEL=(-accel kvm) + echo "QEMU acceleration: KVM" +else + ACCEL=(-accel tcg,thread=multi) + echo "QEMU acceleration: TCG (no /dev/kvm)" +fi + +SSH_OPTS=( + -o StrictHostKeyChecking=no + -o UserKnownHostsFile=/dev/null + -o LogLevel=ERROR + -o ConnectTimeout=5 + -o PreferredAuthentications=password + -o PubkeyAuthentication=no + -o PasswordAuthentication=yes + -o ServerAliveInterval=30 + -o ServerAliveCountMax=10 +) + +ssh_live() { + sshpass -p "${LIVE_PASSWORD}" ssh "${SSH_OPTS[@]}" \ + -p "${SSH_PORT}" liveuser@127.0.0.1 "$@" +} + +scp_live() { + sshpass -p "${LIVE_PASSWORD}" scp "${SSH_OPTS[@]}" \ + -P "${SSH_PORT}" "$@" +} + +monitor() { + python3 - "$1" "$2" <<'PY' +import socket +import sys +import time + +path, command = sys.argv[1:] +with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as client: + client.settimeout(10) + client.connect(path) + client.sendall(command.encode() + b"\n") + time.sleep(0.4) +PY +} + +capture_screen() { + local label="$1" + local socket_path="$2" + local ppm="${SHOTS}/${label}.ppm" + local png="${SHOTS}/${label}.png" + + [[ -S "${socket_path}" ]] || { + echo "screenshot monitor is unavailable: ${socket_path}" >&2 + return 1 + } + monitor "${socket_path}" "screendump ${ppm}" || { + echo "QEMU screendump failed for ${label}" >&2 + return 1 + } + for _ in $(seq 1 10); do + [[ -s "${ppm}" ]] && break + sleep 1 + done + [[ -s "${ppm}" ]] || { + echo "QEMU produced no framebuffer for ${label}" >&2 + return 1 + } + if command -v ffmpeg >/dev/null 2>&1 && \ + ffmpeg -y -loglevel error -i "${ppm}" "${png}" >/dev/null 2>&1; then + rm -f "${ppm}" + echo "screenshot: ${png}" + else + echo "screenshot: ${ppm}" + fi +} + +kill_qemu() { + local pid="$1" + [[ -n "${pid}" ]] || return 0 + if kill -0 "${pid}" 2>/dev/null; then + kill "${pid}" 2>/dev/null || true + for _ in $(seq 1 20); do + kill -0 "${pid}" 2>/dev/null || return 0 + sleep 1 + done + kill -KILL "${pid}" 2>/dev/null || true + fi +} + +cleanup() { + local status=$? + set +e + if [[ "${status}" -ne 0 ]]; then + capture_screen live-failure "${LIVE_MONITOR}" + capture_screen installed-failure "${INSTALLED_MONITOR}" + fi + if [[ -f "${LIVE_PID_FILE}" ]]; then + kill_qemu "$(cat "${LIVE_PID_FILE}")" + fi + if [[ -f "${INSTALLED_PID_FILE}" ]]; then + kill_qemu "$(cat "${INSTALLED_PID_FILE}")" + fi + echo "E2E output retained at ${WORK}" + exit "${status}" +} +trap cleanup EXIT + +rm -f "${INSTALL_DISK}" "${LIVE_VARS}" "${INSTALLED_VARS}" \ + "${LIVE_MONITOR}" "${INSTALLED_MONITOR}" "${LIVE_SERIAL}" \ + "${INSTALLED_SERIAL}" "${LIVE_PID_FILE}" "${INSTALLED_PID_FILE}" +"${QEMU_IMG}" create -f qcow2 "${INSTALL_DISK}" 64G >/dev/null +cp -f "${OVMF_VARS_SOURCE}" "${LIVE_VARS}" + +echo "=== Phase 1/4: boot the Utah live ISO ===" +"${QEMU}" \ + -name utah-live-e2e \ + -machine q35 \ + "${ACCEL[@]}" \ + -cpu max \ + -m "${QEMU_MEMORY}" \ + -smp "${QEMU_CPUS}" \ + -drive "if=pflash,format=raw,readonly=on,file=${OVMF_CODE}" \ + -drive "if=pflash,format=raw,file=${LIVE_VARS}" \ + -drive "if=none,id=iso,file=${ISO},media=cdrom,readonly=on,format=raw" \ + -device virtio-scsi-pci,id=scsi \ + -device scsi-cd,drive=iso \ + -drive "if=none,id=disk,file=${INSTALL_DISK},format=qcow2" \ + -device virtio-blk-pci,drive=disk \ + -netdev "user,id=net0,restrict=on,hostfwd=tcp::${SSH_PORT}-:22" \ + -device virtio-net-pci,netdev=net0 \ + -display none \ + -vnc 127.0.0.1:2 \ + -monitor "unix:${LIVE_MONITOR},server,nowait" \ + -serial "file:${LIVE_SERIAL}" \ + -no-reboot \ + -daemonize \ + -pidfile "${LIVE_PID_FILE}" + +echo "Live VM network: QEMU user mode with restrict=on; only host SSH forwarding is available." +echo "Waiting for the live SSH control channel and UTAH_LIVE_READY marker..." +live_ready=0 +for _ in $(seq 1 "${SSH_TIMEOUT}"); do + if grep -aFq UTAH_LIVE_READY "${LIVE_SERIAL}" 2>/dev/null && \ + ssh_live true >/dev/null 2>&1; then + live_ready=1 + break + fi + sleep 1 +done +(( live_ready == 1 )) || { + tail -120 "${LIVE_SERIAL}" >&2 2>/dev/null || true + fail "live VM did not expose SSH and UTAH_LIVE_READY within ${SSH_TIMEOUT}s" +} + +echo "=== Phase 2/4: prove the live graphical session ===" +live_graphical=0 +for _ in $(seq 1 180); do + if ssh_live 'systemctl is-active graphical.target' 2>/dev/null | grep -qx active && \ + ssh_live 'systemctl is-active gdm.service' 2>/dev/null | grep -qx active && \ + ssh_live 'pgrep -u liveuser -x gnome-shell >/dev/null' 2>/dev/null; then + live_graphical=1 + break + fi + sleep 5 +done +(( live_graphical == 1 )) || fail "live VM did not reach a GNOME graphical session" +echo "Live graphical.target, gdm.service, and gnome-shell are active." +capture_screen live-desktop "${LIVE_MONITOR}" + +echo "=== Phase 3/4: install the embedded payload with no registry access (encryption=${ENCRYPTION}) ===" +RECIPE="${WORK}/recipe.json" +python3 - "${RECIPE}" "${PAYLOAD_REF}" "${TARGET_IMGREF}" "${TEST_USER}" "${TEST_PASSWORD}" "${ENCRYPTION}" "${PASSPHRASE}" <<'PY' +import json +import pathlib +import sys + +path, payload, target, user, password, encryption_mode, passphrase = sys.argv[1:] +if encryption_mode == "luks": + encryption = {"type": "luks-passphrase", "passphrase": passphrase} +else: + encryption = {"type": "none"} + +recipe = { + "disk": "/dev/vda", + "filesystem": "btrfs", + "btrfsSubvolumes": False, + "encryption": encryption, + "image": f"containers-storage:{payload}", + "targetImgref": target, + "local_imgref": f"containers-storage:{payload}", + "selinuxDisabled": False, + "unifiedStorage": True, + "composeFsBackend": False, + "bootloader": "grub2", + "hostname": "utah-e2e", + "user": { + "username": user, + "fullname": "Utah E2E", + "password": password, + "groups": ["wheel"], + }, + "flatpaks": [], +} +pathlib.Path(path).write_text(json.dumps(recipe, indent=2) + "\n") +PY +scp_live "${RECIPE}" liveuser@127.0.0.1:/tmp/utah-e2e-recipe.json + +# The isolated network is part of the test contract. Fisherman must resolve +# the image through the embedded containers-storage graphroot; it cannot +# satisfy the install by pulling from the registry. +ssh_live 'sudo /usr/local/bin/fisherman /tmp/utah-e2e-recipe.json' || \ + fail "Fisherman could not install the embedded OCI payload" + +echo "Fisherman completed from containers-storage:${PAYLOAD_REF}; tracking ${TARGET_IMGREF}." +echo "Preparing boot entries, verifying offline Flatpaks/payload, and staging graphical boot assertion..." +ssh_live "sudo TARGET_USER='${TEST_USER}' ENCRYPTION='${ENCRYPTION}' PASSPHRASE='${PASSPHRASE}' bash -s" <<'TARGET_SETUP' +set -euo pipefail + +root_mount=/mnt/utah-e2e-root +esp_mount=/mnt/utah-e2e-esp +boot_mount=/mnt/utah-e2e-boot +mkdir -p "${root_mount}" "${esp_mount}" "${boot_mount}" + +esp_part="$(blkid -t TYPE=vfat -o device | head -1)" +[[ -n "${esp_part}" ]] || { echo "installed EFI partition not found" >&2; exit 1; } + +crypt_opened=0 +if [[ "${ENCRYPTION}" == "luks" ]]; then + luks_part="$(blkid -t TYPE=crypto_LUKS -o device | head -1)" + [[ -n "${luks_part}" ]] || { echo "LUKS encrypted partition not found" >&2; exit 1; } + echo "Found LUKS partition: ${luks_part}" + echo -n "${PASSPHRASE}" | cryptsetup open "${luks_part}" utah-e2e-crypt-root - + crypt_opened=1 + root_part="/dev/mapper/utah-e2e-crypt-root" +else + root_part="$(blkid -t TYPE=btrfs -o device | head -1)" + [[ -n "${root_part}" ]] || { echo "installed btrfs partition not found" >&2; exit 1; } +fi + +mount "${root_part}" "${root_mount}" +mount "${esp_part}" "${esp_mount}" + +boot_part="$(blkid -t TYPE=ext4 -o device | head -1)" +if [[ -n "${boot_part}" && "${boot_part}" != "${root_part}" ]]; then + mount "${boot_part}" "${boot_mount}" +fi + +cleanup() { + umount "${boot_mount}" 2>/dev/null || true + umount "${esp_mount}" 2>/dev/null || true + umount "${root_mount}" 2>/dev/null || true + if [[ "${crypt_opened}" -eq 1 ]]; then + cryptsetup close utah-e2e-crypt-root 2>/dev/null || true + fi +} +trap cleanup EXIT + +# 1. Verify Utah identity +grep -q '^ID=utah$' "${root_mount}/etc/os-release" +grep -q '^IMAGE_ID=utah$' "${root_mount}/etc/os-release" + +# 2. Verify offline payload contract +test -s "${root_mount}/usr/share/utah/contract.txt" + +# 3. Verify default Flatpaks remain available after installation +test -d "${root_mount}/var/lib/flatpak/repo" +# Ensure the Flatpak repository has objects and refs preserved from the offline install +test -d "${root_mount}/var/lib/flatpak/repo/objects" +echo "Offline payload and default Flatpaks verified on installed root filesystem." + +# 4. Configure autologin for testing +mkdir -p "${root_mount}/etc/gdm" +cat >"${root_mount}/etc/gdm/custom.conf" <"${root_mount}/etc/utah-e2e-graphical.sh" <<'EOF' +#!/usr/bin/env bash +set -u +for _ in $(seq 1 120); do + if grep -q '^ID=utah$' /etc/os-release && \ + grep -q '^IMAGE_ID=utah$' /etc/os-release && \ + test -d /var/lib/flatpak/repo && \ + systemctl is-active --quiet graphical.target && \ + systemctl is-active --quiet gdm.service && \ + pgrep -u "${TARGET_USER}" -x gnome-shell >/dev/null 2>&1; then + echo UTAH_INSTALLED_GRAPHICAL_OK + exit 0 + fi + sleep 2 +done +echo UTAH_INSTALLED_GRAPHICAL_FAIL +exit 1 +EOF +chmod 0755 "${root_mount}/etc/utah-e2e-graphical.sh" + +cat >"${root_mount}/etc/systemd/system/utah-e2e-graphical.service" </dev/null +) +for entry in "${entries[@]}"; do + grep -q '^options ' "${entry}" || continue + sed -i 's/ rhgb//g; s/ quiet//g' "${entry}" + grep -q 'console=ttyS0' "${entry}" || \ + sed -i 's|^options .*|& console=tty0 console=ttyS0,115200n8|' "${entry}" + grep -q 'forward_to_console' "${entry}" || \ + sed -i 's|^options .*|& systemd.journald.forward_to_console=yes|' "${entry}" + grep -q 'default_device_timeout_sec' "${entry}" || \ + sed -i 's|^options .*|& systemd.default_device_timeout_sec=180|' "${entry}" +done + +# 7. Install UEFI fallback loader on ESP +if [[ -f "${esp_mount}/EFI/fedora/shimx64.efi" ]]; then + mkdir -p "${esp_mount}/EFI/BOOT" + cp -f "${esp_mount}/EFI/fedora/shimx64.efi" "${esp_mount}/EFI/BOOT/BOOTX64.EFI" +fi +if [[ -f "${esp_mount}/EFI/fedora/grubx64.efi" ]]; then + cp -f "${esp_mount}/EFI/fedora/grubx64.efi" "${esp_mount}/EFI/BOOT/grubx64.efi" +fi + +sync +blockdev --flushbufs "${root_part}" 2>/dev/null || true +blockdev --flushbufs "${esp_part}" 2>/dev/null || true +if [[ -n "${boot_part}" && "${boot_part}" != "${root_part}" ]]; then + blockdev --flushbufs "${boot_part}" 2>/dev/null || true +fi +echo "Utah identity, Flatpaks, and installed graphical assertion staged." +TARGET_SETUP + +echo "Powering off the live VM before booting its installed disk..." +ssh_live 'sudo systemctl poweroff --no-block' >/dev/null 2>&1 || true +live_pid="$(cat "${LIVE_PID_FILE}")" +for _ in $(seq 1 180); do + kill -0 "${live_pid}" 2>/dev/null || break + sleep 1 +done +if kill -0 "${live_pid}" 2>/dev/null; then + echo "Live VM did not power off cleanly; stopping it after disk flush." >&2 + kill_qemu "${live_pid}" +fi +cp -f "${LIVE_VARS}" "${INSTALLED_VARS}" + +echo "=== Phase 4/4: boot the installed Utah system without ISO or network ===" +"${QEMU}" \ + -name utah-installed-e2e \ + -machine q35 \ + "${ACCEL[@]}" \ + -cpu max \ + -m "${QEMU_MEMORY}" \ + -smp "${QEMU_CPUS}" \ + -drive "if=pflash,format=raw,readonly=on,file=${OVMF_CODE}" \ + -drive "if=pflash,format=raw,file=${INSTALLED_VARS}" \ + -drive "if=none,id=disk,file=${INSTALL_DISK},format=qcow2" \ + -device virtio-blk-pci,drive=disk \ + -net none \ + -display none \ + -vnc 127.0.0.1:3 \ + -monitor "unix:${INSTALLED_MONITOR},server,nowait" \ + -serial "file:${INSTALLED_SERIAL}" \ + -no-reboot \ + -daemonize \ + -pidfile "${INSTALLED_PID_FILE}" + +if [[ "${ENCRYPTION}" == "luks" ]]; then + echo "Running LUKS unlock helper..." + python3 "${SCRIPT_DIR}/luks-unlock.py" qemu \ + "${INSTALLED_MONITOR}" "${PASSPHRASE}" "${INSTALLED_SERIAL}" || { + echo "LUKS unlock helper reported error or emergency shell" >&2 + } +fi + +installed_ready=0 +for _ in $(seq 1 "${BOOT_TIMEOUT}"); do + if grep -aFq UTAH_INSTALLED_GRAPHICAL_OK "${INSTALLED_SERIAL}" 2>/dev/null; then + installed_ready=1 + break + fi + if grep -aEiq 'kernel panic|UTAH_INSTALLED_GRAPHICAL_FAIL|emergency mode' \ + "${INSTALLED_SERIAL}" 2>/dev/null; then + break + fi + sleep 1 +done +(( installed_ready == 1 )) || { + echo "--- installed serial log ---" >&2 + tail -200 "${INSTALLED_SERIAL}" >&2 2>/dev/null || true + fail "installed disk did not reach Utah's graphical-session marker" +} +capture_screen installed-desktop "${INSTALLED_MONITOR}" + +cat >"${WORK}/e2e-summary.txt" <