From b579633ab1f213489c7b27233d2f5f6b810b39ce Mon Sep 17 00:00:00 2001 From: Phoebus Date: Thu, 24 Sep 2026 21:23:47 -0700 Subject: [PATCH] fix(install,admin): use the legacy sys probe at finalize and keep personal preferences out of the system transaction log --- docs/CHANGELOG.md | 27 +++++++++++ docs/HANDOFF.md | 46 ++++++++++++------- docs/STATUS.md | 7 ++- .../phoebus-executor/src/sys_runtime.rs | 9 ++-- .../crates/phoebus-installer/src/bin/sys.rs | 6 ++- .../crates/phoebus-installer/tests/sys_cli.rs | 41 +++++++++++++++++ 6 files changed, 114 insertions(+), 22 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 10c873f..7db57a9 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -3,6 +3,33 @@ All notable changes are recorded here. The authoritative history is `git log`; this file is the curated, human-readable summary. +## 2026-09-25 — Installed-VM verification fixes (installer finalize probe, personal preference transactions) + +Found while running the acceptance on a fresh disposable installed system: + +- **Installer `finalize` probe used the AI-first path (`phoebus-executor::sys_runtime`).** + The target `sys` verification ran `sys history`, which is AI-first and + (correctly) refuses to run without a connected model, so a non-interactive + `--install --no-ai` aborted at the `finalize` stage with `INSTALL-RC=1`. The + offline-safe deterministic probe is now `sys history --legacy`. Unit-tested; + `sys history --legacy` succeeds in the booted target (`HIST_RC:0`). +- **A personal preference no longer requires the root-owned transaction log + (`sys` `execute_action`).** A normal account saving a personal package + preference wrote the preference successfully but then failed with permission + denied recording it in `/var/lib/phoebus/transactions.toml`, returning a + misleading nonzero exit. Personal preferences are user-owned state and are no + longer written to the system transaction history; only `requires_root()` + actions are recorded. Covered by a CLI regression test that makes the system + transaction directory read-only. +- **Installed-VM evidence (disposable qcow2, detached boot):** LUKS unlock and + login; systemd PID1 `running`; `sys 0.1.0`; `sys history --legacy` exit 0; + and `installer/tests/vm/sys-acceptance.sh` with the fixed `sys` reports + `SUMMARY PASS=24 FAIL=0`, including `personal-preference PASS saved to user + config` and `nonroot-systemwide` correctly refused. The privileged `--broker` + plan path and replay rejection are unit-tested at the privileged entry point + but were not exercised end-to-end in the VM (no root/Polkit agent on the + serial console; `sudo -n` denied). + ## 2026-09-25 — Bind per-step reviewed effects into the approval digest - **Per-step effect binding (`phoebus-installer::service`):** the canonical diff --git a/docs/HANDOFF.md b/docs/HANDOFF.md index f05b9af..e12d142 100644 --- a/docs/HANDOFF.md +++ b/docs/HANDOFF.md @@ -54,30 +54,44 @@ commit it. It should be short and current; use `git log` for detail. `transaction::begin` reaches a terminal result. - **Last verified (this session):** - `cargo fmt --all -- --check` clean. - - `cargo test --workspace`: 601 passed, 0 failed. New per-step binding + - `cargo test --workspace`: 602 passed, 0 failed. New per-step binding adversarial tests: single-action and multi-action General plans with `step_effects` swapped (with and without a matching aggregate) while the approved digest is retained are rejected before any command, ledger claim or - transaction; a legitimate bound multi-step plan still validates. The prior - session's adversarial tests (swapped action resealed for every plan kind; - replay after a summary/presentation edit or recreating an identical plan; - live-vs-abandoned reconciliation; reconcile-vs-finish; personal ownership; - cross-uid refusal) all still pass. + transaction; a legitimate bound multi-step plan still validates. New CLI + regression: a personal preference succeeds when the system transaction + directory is read-only. The prior session's adversarial tests all still pass. - `cargo clippy --workspace --all-targets` exits 0 (only the pre-existing `result_large_err`, one arg-count and one `DiskPhase` lints remain). - `cargo build --release -p phoebus-installer` clean. + - **Disposable installed VM (qcow2, detached boot):** LUKS unlock + login; + PID 1 `systemd`, `systemd is-system-running = running`; `sys 0.1.0`; + `sys history --legacy` exit 0; `installer/tests/vm/sys-acceptance.sh` with + the fixed `sys` reports `SUMMARY PASS=24 FAIL=0` (includes + `personal-preference PASS saved to user config` and `nonroot-systemwide` + correctly refused). + - Two defects found and fixed by the VM run: (a) the installer `finalize` + `sys` probe ran the AI-first `sys history` and aborted a `--no-ai` install; + it now runs `sys history --legacy` (`phoebus-executor::sys_runtime`, + unit-tested); (b) a personal preference wrote the preference but then failed + recording it in the root-owned `/var/lib/phoebus/transactions.toml`; personal + preferences are now excluded from the system transaction history. - **Not yet verified this session (BLOCKED):** - - Installed-VM journey and the 12-step acceptance list. The existing - disposable installed disk (`/var/tmp/phoebus-vm/disks/test-disk.qcow2`) - reaches the LUKS prompt but **no passphrase in this environment opens it**: - the harness default (`phoebus-luks-test`, which is also the content of - `/home/dominic/vmlab/serve/luks.pw`) is rejected, and no other credential is - available. Do not guess or brute-force. + - The privileged `sys --broker --execute-plan` path and replay rejection were + **not** exercised end-to-end in the VM: the serial console has no root + access and no Polkit agent (`sudo -n` denied), so `pkexec` elevation cannot + complete. These paths remain unit-tested at the `execute_plan_privileged` + entry point (replacement, recomputed digest, step_effects tampering, replay, + concurrency, interruption). A graphical/seat-providing VM or a + passwordless-sudo test image is required for the end-to-end run. + - The existing `test-disk.qcow2` still cannot be unlocked (unknown passphrase); + do not guess or brute-force. A clean re-install with the fixed installer is + running at the time of writing (`verify-disk2.qcow2`); its result is recorded + in the follow-up if it completes. - No AI provider credential is present; do not invent one. - - A real privileged `chown` (running as root) could not be exercised in this - unprivileged host; the ownership logic is verified through the injectable - fixer seam and the cross-uid refusal test. A root-run confirmation is a - follow-up. + - A real privileged `chown` (running as root) could not be exercised on this + unprivileged host; verified through the injectable fixer seam and the + cross-uid refusal test. - **Public repo:** (remote `origin`, SSH port 2222). diff --git a/docs/STATUS.md b/docs/STATUS.md index cfeb887..cb148ff 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -90,9 +90,12 @@ still not VM-verified. | Per-step effect binding into the approval digest (contents + aggregate) | yes | yes (adversarial: step_effects swap rejected; legit multi-step validates) | no | n/a | | Stable approval identity (replay after presentation edit/reseal) | yes | yes (summary/other fields/identical id/concurrent/new-id) | no | n/a | | Live-safe monotonic recovery (owner liveness, immutable terminal) | yes | yes (live vs abandoned, reconcile/finish race) | no | n/a | -| Personal preferences + alert state (user-owned, system-default precedence) | yes | yes (save/reload/isolation/precedence/failure) | no | no | +| Personal preferences + alert state (user-owned, system-default precedence) | yes | yes (save/reload/isolation/precedence/failure) | yes (installed VM: saved to user config, exit 0) | no | | Personal write ownership (elevated chown, symlink refusal, cross-uid refusal) | yes | yes (ownership-fixer seam + CLI refusal) | no | no | -| Transaction log (outcomes, protective snapshots) | yes | yes | no | no | +| Personal preference does not need the root-owned system transaction log | yes | yes (CLI regression: read-only transaction dir) | yes (installed VM acceptance) | n/a | +| Installed `sys` acceptance matrix (read-only/failure) | yes | yes | yes (installed VM: `PASS=24 FAIL=0`) | no | +| Privileged `--broker` plan execution + replay rejection in a VM | yes | yes (privileged entry point) | no (needs root/Polkit agent; unit-tested only) | n/a | +| Transaction log (outcomes, protective snapshots) | yes | yes | read-only in installed VM; write path needs root | no | | Flatpak/Nix bounded typed actions | yes | yes | no | no | | Shared hardware-aware source selection (all lanes) | yes | yes | no | no | | Snap lane (detect/install/list/remove/refresh/connections) | yes | yes | no | no | diff --git a/installer-rs/crates/phoebus-executor/src/sys_runtime.rs b/installer-rs/crates/phoebus-executor/src/sys_runtime.rs index d49560e..2e03c0b 100644 --- a/installer-rs/crates/phoebus-executor/src/sys_runtime.rs +++ b/installer-rs/crates/phoebus-executor/src/sys_runtime.rs @@ -144,13 +144,16 @@ pub fn install_sys_to_target(exec: &Exec) -> Result { ) })?; - // Verify execution inside target chroot: run harmless deterministic `sys history` + // Verify execution inside target chroot with the deterministic legacy + // interface: `sys history` without `--legacy` is AI-first and (correctly) + // refuses to run without a connected model, so the offline-safe probe must + // select `--legacy`. let root = Path::new(&exec.root); - portage::chroot(exec, root, "/usr/local/bin/sys", &["history"]).map_err(|e| { + portage::chroot(exec, root, "/usr/local/bin/sys", &["history", "--legacy"]).map_err(|e| { ExecError::operation( "sys_runtime", "verify sys in chroot", - format!("running sys history in target chroot failed: {e}"), + format!("running sys history --legacy in target chroot failed: {e}"), ) })?; diff --git a/installer-rs/crates/phoebus-installer/src/bin/sys.rs b/installer-rs/crates/phoebus-installer/src/bin/sys.rs index 80ac49b..e232f77 100644 --- a/installer-rs/crates/phoebus-installer/src/bin/sys.rs +++ b/installer-rs/crates/phoebus-installer/src/bin/sys.rs @@ -444,7 +444,11 @@ fn execute_action( } println!("{}", outcome.output); - if action.is_mutating() { + // Only system-level mutations belong in the root-owned transaction history. + // A personal preference is user-owned state: recording it in + // `/var/lib/phoebus/transactions.toml` would fail for a normal account + // (permission denied) even though the preference was saved successfully. + if action.requires_root() { let described = action.describe(); let record = TransactionRecord { id: 0, diff --git a/installer-rs/crates/phoebus-installer/tests/sys_cli.rs b/installer-rs/crates/phoebus-installer/tests/sys_cli.rs index 0284e0d..73a4912 100644 --- a/installer-rs/crates/phoebus-installer/tests/sys_cli.rs +++ b/installer-rs/crates/phoebus-installer/tests/sys_cli.rs @@ -245,6 +245,47 @@ fn a_personal_preference_is_saved_by_a_normal_account_outside_etc() { .exists()); } +#[test] +fn a_personal_preference_does_not_require_the_root_owned_transaction_log() { + if effective_uid_is_root() { + return; + } + use std::os::unix::fs::PermissionsExt; + let root = tempfile::tempdir().expect("temp root"); + let personal = tempfile::tempdir().expect("personal dir"); + // Simulate the installed system: /var/lib/phoebus is root-owned, so a normal + // account cannot write the system transaction log. + let tx_dir = root.path().join("var/lib/phoebus"); + std::fs::create_dir_all(&tx_dir).expect("create tx dir"); + std::fs::set_permissions(&tx_dir, std::fs::Permissions::from_mode(0o555)).expect("chmod"); + + let out = sys() + .arg("--root") + .arg(root.path()) + .env("PHOEBUS_PERSONAL_DIR", personal.path()) + .args([ + "--legacy", + "--action", + r#"{"action":"set_package_preference","name":"firefox","backend":"flatpak"}"#, + ]) + .output() + .expect("run sys"); + assert!( + out.status.success(), + "a personal preference must succeed without the system transaction log: {}", + String::from_utf8_lossy(&out.stderr) + ); + // The preference was saved; no system transaction was attempted. + assert!(personal + .path() + .join(".config/phoebus/package-preferences.toml") + .is_file()); + assert!( + !tx_dir.join("transactions.toml").exists(), + "no system transaction should be attempted for a personal preference" + ); +} + #[test] fn a_personal_preference_is_refused_when_the_initiating_uid_differs_from_the_euid() { if effective_uid_is_root() {