From ab67bf2037d56c17ef91d062590e1f93a8b0079a Mon Sep 17 00:00:00 2001 From: Danathar Date: Sun, 20 Sep 2026 20:54:25 +0000 Subject: [PATCH 1/6] fix(justfile): probe install-vm kiosk readiness from inside the guest The kiosk proxy publishes hostPort 8080 on the guest's loopback only (files/k0s/manifests/kubestellar/41-kubestellar-kiosk-proxy.yaml) and terminates TLS (files/k0s/kiosk/nginx.conf, `listen 8080 ssl`). This broke install-vm's readiness wait and advertised access URLs the same way #218/#220 diagnosed for the installer-test smoke recipe: 1. A QEMU/libslirp hostfwd with an unspecified guest address is delivered to the guest's DHCP address, never to 127.0.0.1, so hostfwd=tcp::8080-:8080 could never reach the loopback-bound proxy. 2. The host-side poll spoke plain HTTP against a TLS listener. 3. The printed LAN/local access URLs and xdg-open call were therefore unreachable. Probe readiness from inside the guest instead: inject a oneshot systemd unit via an smbios(11) credential that polls the proxy over TLS from inside the guest and echoes a marker on the system console, which is captured to a host-side serial log file the host polls instead of curl. This is the same in-guest-probe approach proposed for test-installer-artifact in #220 (not yet merged); test-installer- artifact itself still probes from the host on this branch. Order ttyS0 last on the kernel cmdline so /dev/console resolves to the serial device the host captures, matching the ordering test-installer-artifact already uses for the same reason. The in-guest probe deliberately does not parse the /healthz response body: curl --fail already fails on a non-2xx response, which is exactly "healthz ok and / returns 200", and it avoids embedding quotes inside a systemd ExecStart= line, whose escaping rules differ from a plain shell. Drop the non-working direct 8080 hostfwd and the LAN/local URLs and xdg-open call that depended on it; print instructions for reaching the console from the host over an SSH tunnel through the existing hostfwd=tcp::2222-:22 forward instead, per the issue's suggested direction. Preserve the unrelated hostfwd=tcp::6443-:6443 (Kubernetes API) forward. Correct the kiosk proxy manifest comment, which still claimed the VM flow reaches the proxy via the existing hostfwd. Fixes #222 Assisted-by: Claude (Anthropic) via Hive Signed-off-by: Danathar --- Justfile | 52 +++++++++-- .../41-kubestellar-kiosk-proxy.yaml | 10 +-- tests/unit/test_install_vm_kiosk_readiness.py | 86 +++++++++++++++++++ 3 files changed, 137 insertions(+), 11 deletions(-) create mode 100644 tests/unit/test_install_vm_kiosk_readiness.py diff --git a/Justfile b/Justfile index ea47448f..42e010b2 100644 --- a/Justfile +++ b/Justfile @@ -469,6 +469,40 @@ install-vm: fi echo "==> Booting the installed kiosk..." + SERIAL_LOG="$STATE_DIR/kiosk-serial.log" + : > "$SERIAL_LOG" + + # The kiosk proxy binds hostPort 8080 on the guest's loopback interface only + # (files/k0s/manifests/kubestellar/41-kubestellar-kiosk-proxy.yaml) and + # terminates TLS (files/k0s/kiosk/nginx.conf, `listen 8080 ssl`). A + # QEMU/libslirp hostfwd with an unspecified guest address is delivered to + # the guest's DHCP address, never to 127.0.0.1, so a host-side forward of + # 8080 can never reach the proxy, and a plaintext probe would fail against + # its TLS listener regardless. Probe readiness from inside the guest + # instead and report the verdict on the system console, which is captured + # in $SERIAL_LOG — the same in-guest-probe approach proposed for + # test-installer-artifact in #220. Host access, when wanted, goes over + # the existing SSH hostfwd rather than a direct (non-working) 8080 + # forward. The readiness check deliberately does not parse the /healthz + # response body: curl --fail already fails on a non-2xx response, which + # is exactly "healthz ok and / returns 200", and it avoids embedding + # quotes inside a systemd ExecStart= line, where escaping rules differ + # from a plain shell. + READY_MARKER="KIOSK_CONSOLE_READY" + READY_UNIT=$(base64 -w0 <<'UNIT' + [Unit] + Description=Report KubeStellar Console readiness on the system console + ConditionPathExists=!/etc/initrd-release + After=k0s-first-boot.service + + [Service] + Type=oneshot + TimeoutStartSec=infinity + StandardOutput=journal+console + ExecStart=/usr/bin/bash -c 'until curl --silent --fail --insecure --max-time 2 --output /dev/null https://127.0.0.1:8080/healthz && curl --silent --fail --insecure --max-time 2 --output /dev/null https://127.0.0.1:8080/; do sleep 2; done; echo KIOSK_CONSOLE_READY' + UNIT + ) + qemu-system-x86_64 \ -enable-kvm \ -m "${MEM_SIZE}" \ @@ -477,7 +511,10 @@ install-vm: -drive file="$TARGET_RAW",format=raw,if=virtio \ -drive if=pflash,format=raw,readonly=on,file="$OVMF_CODE" \ -drive if=pflash,format=raw,file="$OVMF_VARS" \ - -nic user,model=virtio-net-pci,hostfwd=tcp::8080-:8080,hostfwd=tcp::2222-:22,hostfwd=tcp::6443-:6443 & + -nic user,model=virtio-net-pci,hostfwd=tcp::2222-:22,hostfwd=tcp::6443-:6443 \ + -smbios "type=11,value=io.systemd.credential.binary:systemd.extra-unit.bluefin-kiosk-ready.service=${READY_UNIT}" \ + -smbios "type=11,value=io.systemd.stub.kernel-cmdline-extra=console=tty0 console=ttyS0,,115200 systemd.wants=bluefin-kiosk-ready.service" \ + -serial file:"$SERIAL_LOG" & QEMU_PID=$! cleanup() { if kill -0 "$QEMU_PID" 2>/dev/null; then @@ -487,7 +524,8 @@ install-vm: } trap cleanup INT TERM - until curl --silent --show-error --max-time 2 --output /dev/null http://127.0.0.1:8080/; do + echo "==> Waiting for the KubeStellar Console to become ready inside the guest..." + until grep -q "$READY_MARKER" "$SERIAL_LOG" 2>/dev/null; do if ! kill -0 "$QEMU_PID" 2>/dev/null; then wait "$QEMU_PID" exit 1 @@ -495,11 +533,13 @@ install-vm: sleep 2 done - HOST_IP="$(ip -4 -o addr show scope global | awk '{print $4}' | cut -d/ -f1 | head -n1)" echo "==> KubeStellar Console is ready!" - echo "==> Access URL (LAN): http://${HOST_IP:-localhost}:8080/" - echo "==> Access URL (Local): http://localhost:8080/" - xdg-open "http://${HOST_IP:-localhost}:8080/" || xdg-open http://localhost:8080/ || true + echo "==> The kiosk proxy binds the guest's loopback interface only and terminates" + echo "==> TLS with a self-signed certificate, so it is not directly reachable from" + echo "==> the host. To view it in a host browser, start sshd inside the VM" + echo "==> (systemctl start sshd) and open a tunnel over the forwarded SSH port:" + echo "==> ssh -p 2222 -L 8080:127.0.0.1:8080 @127.0.0.1" + echo "==> then browse https://localhost:8080/ and accept the self-signed certificate." wait "$QEMU_PID" # Set up KubeStellar kc-agent for the user in ONE command. diff --git a/files/k0s/manifests/kubestellar/41-kubestellar-kiosk-proxy.yaml b/files/k0s/manifests/kubestellar/41-kubestellar-kiosk-proxy.yaml index 8ade0861..588288ae 100644 --- a/files/k0s/manifests/kubestellar/41-kubestellar-kiosk-proxy.yaml +++ b/files/k0s/manifests/kubestellar/41-kubestellar-kiosk-proxy.yaml @@ -30,11 +30,11 @@ spec: ports: - containerPort: 8080 # Kiosk-only proxy: bind loopback so the console is never published on - # the node's external interfaces. A QEMU hostfwd cannot reach this - # binding, because libslirp delivers a forward with an unspecified - # guest address to the guest's DHCP address rather than to 127.0.0.1; - # the installer smoke test therefore probes the proxy from inside the - # guest. LAN access, if ever wanted, must go through an + # the node's external interfaces. A QEMU/libslirp hostfwd with an + # unspecified guest address is delivered to the guest's DHCP address, + # not to 127.0.0.1, so no QEMU hostfwd can reach this binding; + # `just install-vm` and the installer smoke test probe the proxy from + # inside the guest instead. LAN access, if ever wanted, must go through an # authenticated front end. hostIP: 127.0.0.1 hostPort: 8080 diff --git a/tests/unit/test_install_vm_kiosk_readiness.py b/tests/unit/test_install_vm_kiosk_readiness.py new file mode 100644 index 00000000..26bc19ec --- /dev/null +++ b/tests/unit/test_install_vm_kiosk_readiness.py @@ -0,0 +1,86 @@ +"""Contracts for `just install-vm` reaching the loopback-bound, TLS-terminating +kiosk proxy (files/k0s/manifests/kubestellar/41-kubestellar-kiosk-proxy.yaml, +files/k0s/kiosk/nginx.conf).""" + +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +JUSTFILE = ROOT / "Justfile" +KIOSK_PROXY_MANIFEST = ( + ROOT / "files/k0s/manifests/kubestellar/41-kubestellar-kiosk-proxy.yaml" +) + + +def _install_vm_recipe() -> str: + justfile = JUSTFILE.read_text(encoding="utf-8") + start = justfile.index("install-vm:") + end = justfile.index("setup-kubestellar", start) + return justfile[start:end] + + +def test_install_vm_drops_the_unreachable_direct_kiosk_forward() -> None: + recipe = _install_vm_recipe() + + # A QEMU/libslirp hostfwd with an unspecified guest address is delivered + # to the guest's DHCP address, never to 127.0.0.1, so it can never reach + # a loopback-bound service. This forward must be gone, and the host must + # not claim a URL it cannot reach. + assert "hostfwd=tcp::8080-:8080" not in recipe + assert "http://127.0.0.1:8080/" not in recipe + assert "http://${HOST_IP" not in recipe + assert "xdg-open" not in recipe + + # Unrelated forwards used elsewhere in the recipe must survive. + assert "hostfwd=tcp::2222-:22" in recipe + assert "hostfwd=tcp::6443-:6443" in recipe + + +def test_install_vm_probes_readiness_inside_the_guest_over_tls() -> None: + recipe = _install_vm_recipe() + + # Readiness is probed from inside the guest, over TLS (the proxy + # terminates TLS with a self-signed certificate), and reported on the + # system console, which is captured to a host-side serial log file. + assert "https://127.0.0.1:8080/healthz" in recipe + assert "--insecure" in recipe + assert "systemd.extra-unit.bluefin-kiosk-ready.service" in recipe + assert "systemd.wants=bluefin-kiosk-ready.service" in recipe + assert "-serial file:" in recipe + assert 'SERIAL_LOG="$STATE_DIR/kiosk-serial.log"' in recipe + assert 'grep -q "$READY_MARKER" "$SERIAL_LOG"' in recipe + + # The in-guest probe deliberately avoids parsing the /healthz response + # body (with jq, grep, or otherwise): curl --fail already fails on a + # non-2xx response, which is exactly "healthz ok and / returns 200", + # and it avoids embedding quotes inside a systemd ExecStart= line, whose + # escaping rules differ from a plain shell. + assert "ExecStart=/usr/bin/bash -c 'until curl" in recipe + assert "jq" not in recipe + + # ttyS0 must be the last (and therefore primary) console so /dev/console + # resolves to the serial device the host captures, matching the ordering + # test-installer-artifact already relies on for the same reason. + assert "console=tty0 console=ttyS0,,115200 systemd.wants=bluefin-kiosk-ready.service" in recipe + + # Dies-while-waiting must still fail fast instead of polling forever. + assert 'if ! kill -0 "$QEMU_PID" 2>/dev/null; then' in recipe + + +def test_install_vm_documents_ssh_tunnel_for_host_access() -> None: + recipe = _install_vm_recipe() + + # Host access, when wanted, goes over the existing SSH hostfwd instead of + # a direct forward the loopback-bound proxy can never receive. + assert "ssh -p 2222" in recipe + assert "127.0.0.1:8080" in recipe + assert "self-signed certificate" in recipe + + +def test_kiosk_proxy_manifest_comment_matches_actual_reachability() -> None: + manifest = KIOSK_PROXY_MANIFEST.read_text(encoding="utf-8") + + # The comment must not claim a hostfwd can reach a loopback-only bind; + # a QEMU/libslirp hostfwd with an unspecified guest address never lands + # on the guest's loopback interface. + assert "existing hostfwd of 127.0.0.1:8080" not in manifest + assert "hostIP: 127.0.0.1" in manifest From 302e8aaeb10bafbebff1c0cf14d222c2ff7efca5 Mon Sep 17 00:00:00 2001 From: Danathar Date: Sun, 20 Sep 2026 23:01:34 +0000 Subject: [PATCH 2/6] fix(os): correct login banner and de-brittle the jq test assertion files/os/issue.d/40-kubestellar.issue still advertised 'KubeStellar Console: http://\4:8080/ (or http://127.0.0.1:8080 from host)', which is doubly wrong after this PR: the proxy binds guest loopback and terminates TLS, and the direct 8080 hostfwd is gone. Fix in-scope rather than deferring, since the fix is one line and the PR already changed the reachability story the banner describes: point at https://127.0.0.1:8080/ and name the SSH tunnel the Justfile recipe now prints instead. Anchor test_install_vm_kiosk_readiness.py's jq-absence check to the ExecStart= line instead of the whole recipe body, so a future comment or variable elsewhere in the recipe containing 'jq' cannot fail it for the wrong reason, and it stays anchored to the actual contract: the ExecStart command line has no jq in it. Verified test_install_vm_kiosk_readiness.py's four module-level tests directly (no pytest in this environment): all pass, including the updated assertion. test_console_issue.py needs PyYAML, unavailable here; its one-line assertion update is a straight text match against the corrected banner and needs a real run in CI before merge. Signed-off-by: Danathar --- files/os/issue.d/40-kubestellar.issue | 2 +- tests/unit/test_console_issue.py | 2 +- tests/unit/test_install_vm_kiosk_readiness.py | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/files/os/issue.d/40-kubestellar.issue b/files/os/issue.d/40-kubestellar.issue index 61319dc5..a3465aac 100644 --- a/files/os/issue.d/40-kubestellar.issue +++ b/files/os/issue.d/40-kubestellar.issue @@ -1,5 +1,5 @@ Bluefin Server (\l) Default login: root / bluefin -KubeStellar Console: http://\4:8080/ (or http://127.0.0.1:8080 from host) +KubeStellar Console: https://127.0.0.1:8080/ (loopback + TLS only on this host; tunnel with `ssh -L 8080:127.0.0.1:8080 @` to reach it remotely) diff --git a/tests/unit/test_console_issue.py b/tests/unit/test_console_issue.py index af83ead1..7ef61a08 100644 --- a/tests/unit/test_console_issue.py +++ b/tests/unit/test_console_issue.py @@ -15,7 +15,7 @@ def test_issue_file_exists_and_contains_kubestellar_url() -> None: assert ISSUE_FILE.is_file(), f"{ISSUE_FILE} must exist" content = ISSUE_FILE.read_text(encoding="utf-8") assert "Bluefin Server" in content - assert "KubeStellar Console: http://\\4:8080/" in content + assert "KubeStellar Console: https://127.0.0.1:8080/" in content def test_os_issue_element_target_usr_lib_issue_d() -> None: diff --git a/tests/unit/test_install_vm_kiosk_readiness.py b/tests/unit/test_install_vm_kiosk_readiness.py index 26bc19ec..9a775fa8 100644 --- a/tests/unit/test_install_vm_kiosk_readiness.py +++ b/tests/unit/test_install_vm_kiosk_readiness.py @@ -54,8 +54,11 @@ def test_install_vm_probes_readiness_inside_the_guest_over_tls() -> None: # non-2xx response, which is exactly "healthz ok and / returns 200", # and it avoids embedding quotes inside a systemd ExecStart= line, whose # escaping rules differ from a plain shell. - assert "ExecStart=/usr/bin/bash -c 'until curl" in recipe - assert "jq" not in recipe + exec_start_line = next( + line for line in recipe.splitlines() if line.strip().startswith("ExecStart=") + ) + assert exec_start_line.strip().startswith("ExecStart=/usr/bin/bash -c 'until curl") + assert "jq" not in exec_start_line # ttyS0 must be the last (and therefore primary) console so /dev/console # resolves to the serial device the host captures, matching the ordering From 2d1502304028655189ba027ba7865b3cff6ee661 Mon Sep 17 00:00:00 2001 From: Danathar Date: Sun, 20 Sep 2026 23:14:07 +0000 Subject: [PATCH 3/6] fix(os): reformat login banner for TTY legibility The banner line grew from 71 to ~152 chars and would wrap badly on an 80-column console -- the entire point of /etc/issue.d is legibility at a getty prompt. Split it across two lines and dropped the markdown backticks, which render literally there: KubeStellar Console: https://127.0.0.1:8080/ (loopback, TLS only) Remote access: ssh -L 8080:127.0.0.1:8080 @ Added an assertion for the tunnel line to tests/unit/test_console_issue.py. Mutation-tested the ExecStart jq guard against the real Justfile instead of an in-memory copy: piped the echo through 'jq -R .', confirmed test_install_vm_probes_readiness_inside_the_guest_over_tls fails, reverted. Inverse check: added a harmless '# jq' comment elsewhere in the install-vm recipe, confirmed the test still passes -- proving the anchor to the ExecStart= line, not just narrowing the match by luck. Signed-off-by: Danathar --- files/os/issue.d/40-kubestellar.issue | 3 ++- tests/unit/test_console_issue.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/files/os/issue.d/40-kubestellar.issue b/files/os/issue.d/40-kubestellar.issue index a3465aac..862fc3b5 100644 --- a/files/os/issue.d/40-kubestellar.issue +++ b/files/os/issue.d/40-kubestellar.issue @@ -1,5 +1,6 @@ Bluefin Server (\l) Default login: root / bluefin -KubeStellar Console: https://127.0.0.1:8080/ (loopback + TLS only on this host; tunnel with `ssh -L 8080:127.0.0.1:8080 @` to reach it remotely) +KubeStellar Console: https://127.0.0.1:8080/ (loopback, TLS only) +Remote access: ssh -L 8080:127.0.0.1:8080 @ diff --git a/tests/unit/test_console_issue.py b/tests/unit/test_console_issue.py index 7ef61a08..809fc946 100644 --- a/tests/unit/test_console_issue.py +++ b/tests/unit/test_console_issue.py @@ -16,6 +16,7 @@ def test_issue_file_exists_and_contains_kubestellar_url() -> None: content = ISSUE_FILE.read_text(encoding="utf-8") assert "Bluefin Server" in content assert "KubeStellar Console: https://127.0.0.1:8080/" in content + assert "ssh -L 8080:127.0.0.1:8080" in content def test_os_issue_element_target_usr_lib_issue_d() -> None: From ed79c4550408ea6cb36c00f79b34c7e61edfe8aa Mon Sep 17 00:00:00 2001 From: Jorge Castro Date: Mon, 21 Sep 2026 10:36:13 -0400 Subject: [PATCH 4/6] fix(justfile): verify target partition layout before marking install complete Assert that bluefin-server-root-a and var partitions exist on TARGET_RAW before touching INSTALL_COMPLETE, preventing failed QEMU installer runs from falsely marking installation as finished. Assisted-by: github-copilot/gemini-3.8-flash via GitHub Copilot Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Justfile | 7 +++++++ tests/unit/test_install_vm_kiosk_readiness.py | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/Justfile b/Justfile index 42e010b2..dffced48 100644 --- a/Justfile +++ b/Justfile @@ -465,6 +465,13 @@ install-vm: -drive file="$TARGET_RAW",format=raw,if=virtio \ -drive if=pflash,format=raw,readonly=on,file="$OVMF_CODE" \ -drive if=pflash,format=raw,file="$OVMF_VARS" + echo "==> Verifying target partition layout before marking installation complete..." + if ! lsblk -p -n -o PARTLABEL "$TARGET_RAW" 2>/dev/null | grep -Fxq 'bluefin-server-root-a' || \ + ! lsblk -p -n -o PARTLABEL "$TARGET_RAW" 2>/dev/null | grep -Fxq 'var'; then + echo "ERROR: Target disk $TARGET_RAW does not contain expected partitions (bluefin-server-root-a, var)!" >&2 + lsblk -p -o NAME,TYPE,PARTLABEL,SIZE "$TARGET_RAW" >&2 || true + exit 1 + fi touch "$INSTALL_COMPLETE" fi diff --git a/tests/unit/test_install_vm_kiosk_readiness.py b/tests/unit/test_install_vm_kiosk_readiness.py index 9a775fa8..b83c8a3d 100644 --- a/tests/unit/test_install_vm_kiosk_readiness.py +++ b/tests/unit/test_install_vm_kiosk_readiness.py @@ -87,3 +87,12 @@ def test_kiosk_proxy_manifest_comment_matches_actual_reachability() -> None: # on the guest's loopback interface. assert "existing hostfwd of 127.0.0.1:8080" not in manifest assert "hostIP: 127.0.0.1" in manifest + +def test_install_vm_verifies_target_partition_layout_before_marking_complete() -> None: + recipe = _install_vm_recipe() + + assert "bluefin-server-root-a" in recipe + assert "lsblk -p -n -o PARTLABEL" in recipe + assert 'grep -Fxq \'bluefin-server-root-a\'' in recipe + assert 'grep -Fxq \'var\'' in recipe + assert 'touch "$INSTALL_COMPLETE"' in recipe From faffaf8e804a20f99c16ae0b270e117c5e7a26dc Mon Sep 17 00:00:00 2001 From: Jorge Castro Date: Mon, 21 Sep 2026 10:38:54 -0400 Subject: [PATCH 5/6] fix(justfile): use sfdisk --json to parse regular target disk partition table in install-vm lsblk does not inspect partitions inside a regular file image; use sfdisk --json and jq to parse partitiontable.partitions.name instead. Assisted-by: github-copilot/gemini-3.8-flash via GitHub Copilot Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Justfile | 9 ++++++--- tests/unit/test_install_vm_kiosk_readiness.py | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Justfile b/Justfile index dffced48..40b9abdd 100644 --- a/Justfile +++ b/Justfile @@ -466,10 +466,13 @@ install-vm: -drive if=pflash,format=raw,readonly=on,file="$OVMF_CODE" \ -drive if=pflash,format=raw,file="$OVMF_VARS" echo "==> Verifying target partition layout before marking installation complete..." - if ! lsblk -p -n -o PARTLABEL "$TARGET_RAW" 2>/dev/null | grep -Fxq 'bluefin-server-root-a' || \ - ! lsblk -p -n -o PARTLABEL "$TARGET_RAW" 2>/dev/null | grep -Fxq 'var'; then + TARGET_PARTS=$(sfdisk --json "$TARGET_RAW" 2>/dev/null | jq -r '.partitiontable.partitions[]?.name // empty' || true) + if ! echo "$TARGET_PARTS" | grep -Fxq 'bluefin-server-root-a' || \ + ! echo "$TARGET_PARTS" | grep -Fxq 'var'; then echo "ERROR: Target disk $TARGET_RAW does not contain expected partitions (bluefin-server-root-a, var)!" >&2 - lsblk -p -o NAME,TYPE,PARTLABEL,SIZE "$TARGET_RAW" >&2 || true + echo "Observed partitions:" >&2 + echo "$TARGET_PARTS" >&2 + sfdisk -l "$TARGET_RAW" >&2 || true exit 1 fi touch "$INSTALL_COMPLETE" diff --git a/tests/unit/test_install_vm_kiosk_readiness.py b/tests/unit/test_install_vm_kiosk_readiness.py index b83c8a3d..a766a3b3 100644 --- a/tests/unit/test_install_vm_kiosk_readiness.py +++ b/tests/unit/test_install_vm_kiosk_readiness.py @@ -92,7 +92,7 @@ def test_install_vm_verifies_target_partition_layout_before_marking_complete() - recipe = _install_vm_recipe() assert "bluefin-server-root-a" in recipe - assert "lsblk -p -n -o PARTLABEL" in recipe + assert 'sfdisk --json "$TARGET_RAW"' in recipe assert 'grep -Fxq \'bluefin-server-root-a\'' in recipe assert 'grep -Fxq \'var\'' in recipe assert 'touch "$INSTALL_COMPLETE"' in recipe From 0e37c2bca5acf79952a121105f8425218b6fb866 Mon Sep 17 00:00:00 2001 From: "sec-check[bot]" Date: Mon, 21 Sep 2026 11:46:53 -0400 Subject: [PATCH 6/6] fix(justfile): mount /var and bound readiness wait in install-vm The installed target carries no fstab entry for /var and gpt-auto cannot mount it, so the install-vm boot needs the same SMBIOS fstab.extra credential test-installer-artifact passes. Without it, k0s state (and the kiosk proxy it serves) is missing and the readiness marker never appears. Bound the readiness wait with INSTALL_VM_READY_DEADLINE (default 600s) and dump the serial log tail on timeout or premature QEMU exit, so a broken guest boot fails loudly instead of hanging forever. Also document why the target partition layout is verified before marking the install complete, and tell the operator to re-run the installer when an interactive install was aborted. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Justfile | 35 ++++++++++++++++++- tests/unit/test_install_vm_kiosk_readiness.py | 24 +++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/Justfile b/Justfile index 40b9abdd..724c30ce 100644 --- a/Justfile +++ b/Justfile @@ -465,11 +465,18 @@ install-vm: -drive file="$TARGET_RAW",format=raw,if=virtio \ -drive if=pflash,format=raw,readonly=on,file="$OVMF_CODE" \ -drive if=pflash,format=raw,file="$OVMF_VARS" + # The interactive installer is driven by hand, so it can be aborted or + # fail without a non-zero exit here. Marking the install complete in that + # case caches a broken target that every later run boots forever. Gate + # the marker on the partition labels files/repart.d creates; an aborted + # install now fails loudly and re-runs the installer next invocation + # instead of silently booting an unusable disk. echo "==> Verifying target partition layout before marking installation complete..." TARGET_PARTS=$(sfdisk --json "$TARGET_RAW" 2>/dev/null | jq -r '.partitiontable.partitions[]?.name // empty' || true) if ! echo "$TARGET_PARTS" | grep -Fxq 'bluefin-server-root-a' || \ ! echo "$TARGET_PARTS" | grep -Fxq 'var'; then echo "ERROR: Target disk $TARGET_RAW does not contain expected partitions (bluefin-server-root-a, var)!" >&2 + echo "The installation did not complete; re-run 'just install-vm' to install again." >&2 echo "Observed partitions:" >&2 echo "$TARGET_PARTS" >&2 sfdisk -l "$TARGET_RAW" >&2 || true @@ -498,6 +505,11 @@ install-vm: # is exactly "healthz ok and / returns 200", and it avoids embedding # quotes inside a systemd ExecStart= line, where escaping rules differ # from a plain shell. + # The installed image carries no fstab entry for /var and gpt-auto cannot + # mount it, so /var (which holds k0s state and therefore the kiosk proxy) + # stays empty unless the same SMBIOS fstab.extra credential + # test-installer-artifact passes is supplied here too. Without it k0s never + # starts and the readiness marker never appears. READY_MARKER="KIOSK_CONSOLE_READY" READY_UNIT=$(base64 -w0 <<'UNIT' [Unit] @@ -522,6 +534,7 @@ install-vm: -drive if=pflash,format=raw,readonly=on,file="$OVMF_CODE" \ -drive if=pflash,format=raw,file="$OVMF_VARS" \ -nic user,model=virtio-net-pci,hostfwd=tcp::2222-:22,hostfwd=tcp::6443-:6443 \ + -smbios "type=11,value=io.systemd.credential.binary:fstab.extra=L2Rldi9kaXNrL2J5LXBhcnRsYWJlbC92YXIgL3ZhciB4ZnMgZGVmYXVsdHMgMCAwCg==" \ -smbios "type=11,value=io.systemd.credential.binary:systemd.extra-unit.bluefin-kiosk-ready.service=${READY_UNIT}" \ -smbios "type=11,value=io.systemd.stub.kernel-cmdline-extra=console=tty0 console=ttyS0,,115200 systemd.wants=bluefin-kiosk-ready.service" \ -serial file:"$SERIAL_LOG" & @@ -534,12 +547,32 @@ install-vm: } trap cleanup INT TERM - echo "==> Waiting for the KubeStellar Console to become ready inside the guest..." + READY_DEADLINE_SECS="${INSTALL_VM_READY_DEADLINE:-600}" + READY_START_TIME=$(date +%s) + echo "==> Waiting for the KubeStellar Console to become ready inside the guest (deadline: ${READY_DEADLINE_SECS}s)..." until grep -q "$READY_MARKER" "$SERIAL_LOG" 2>/dev/null; do if ! kill -0 "$QEMU_PID" 2>/dev/null; then + echo "ERROR: QEMU process ($QEMU_PID) died before the kiosk became ready!" >&2 + if [ -f "$SERIAL_LOG" ]; then + echo "==> Serial log tail (last 100 lines):" >&2 + tail -n 100 "$SERIAL_LOG" >&2 + fi wait "$QEMU_PID" exit 1 fi + + NOW=$(date +%s) + ELAPSED=$((NOW - READY_START_TIME)) + if [ "$ELAPSED" -ge "$READY_DEADLINE_SECS" ]; then + echo "ERROR: Timed out after ${READY_DEADLINE_SECS}s waiting for KubeStellar Console readiness!" >&2 + if [ -f "$SERIAL_LOG" ]; then + echo "==> Serial log tail (last 100 lines):" >&2 + tail -n 100 "$SERIAL_LOG" >&2 + fi + cleanup + exit 1 + fi + sleep 2 done diff --git a/tests/unit/test_install_vm_kiosk_readiness.py b/tests/unit/test_install_vm_kiosk_readiness.py index a766a3b3..67a875a5 100644 --- a/tests/unit/test_install_vm_kiosk_readiness.py +++ b/tests/unit/test_install_vm_kiosk_readiness.py @@ -69,6 +69,30 @@ def test_install_vm_probes_readiness_inside_the_guest_over_tls() -> None: assert 'if ! kill -0 "$QEMU_PID" 2>/dev/null; then' in recipe +def test_install_vm_mounts_var_from_the_partlabel_credential() -> None: + recipe = _install_vm_recipe() + + # The installed image has no fstab entry for /var and gpt-auto cannot + # mount it, so the boot needs the same SMBIOS fstab.extra credential + # test-installer-artifact passes. Without /var, k0s (and the kiosk proxy + # it runs) never starts and the readiness marker never appears. + assert ( + "io.systemd.credential.binary:fstab.extra=" + "L2Rldi9kaXNrL2J5LXBhcnRsYWJlbC92YXIgL3ZhciB4ZnMgZGVmYXVsdHMgMCAwCg==" + ) in recipe + + +def test_install_vm_readiness_wait_has_a_deadline_and_diagnostics() -> None: + recipe = _install_vm_recipe() + + # A broken guest boot must not hang forever silently: bound the wait and + # dump the serial log on both timeout and premature QEMU exit, matching + # test-installer-artifact. + assert 'READY_DEADLINE_SECS="${INSTALL_VM_READY_DEADLINE:-600}"' in recipe + assert 'if [ "$ELAPSED" -ge "$READY_DEADLINE_SECS" ]; then' in recipe + assert recipe.count('tail -n 100 "$SERIAL_LOG" >&2') == 2 + + def test_install_vm_documents_ssh_tunnel_for_host_access() -> None: recipe = _install_vm_recipe()