fix(live): scope the live privilege policy to the typed brokers

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.
This commit is contained in:
Phoebus 2026-09-23 06:22:19 -07:00
parent c759477c7f
commit 4265aefacd
6 changed files with 91 additions and 8 deletions

View file

@ -1197,6 +1197,27 @@ pub fn default_session_command(profile: DesktopProfile) -> &'static str {
/// The live ISO's unprivileged user.
pub const LIVE_USER: &str = "phoebus";
/// The live medium's passwordless privilege policy.
///
/// The recovery console keeps full root through the **password-authenticated**
/// `sudo` group (the live-only `phoebus`/`phoebus` credential, printed in
/// `installer/live/README.md`), so a serial or VT operator can still repair a
/// broken live session. Unattended escalation is limited to the two typed
/// brokers — the installer and `sys` — which validate actions before doing
/// anything. `systemctl` power actions are included because the welcome and
/// installer UIs offer them. There is no `ALL` command, no `sh -c`, and no
/// wildcard: a permitted program cannot become a general shell.
pub const LIVE_SUDOERS: &str = "\
# Phoebus live-medium privilege policy (generated).
# The recovery console authenticates with the live-only password; only the
# typed brokers below can escalate without a prompt. Do not add ALL or
# wildcards here.
phoebus ALL=(root) NOPASSWD: /usr/local/bin/phoebus-installer
phoebus ALL=(root) NOPASSWD: /usr/local/bin/sys
phoebus ALL=(root) NOPASSWD: /usr/bin/systemctl poweroff
phoebus ALL=(root) NOPASSWD: /usr/bin/systemctl reboot
";
/// `phoebus-nvidia-load`: live-only. It runs before the graphical session and
/// asks the installer for a deterministic decision based on the actual PCI
/// display devices and the bundled branch's capabilities. Systems without an
@ -1312,6 +1333,8 @@ pub fn desktop_asset(name: &str) -> Option<String> {
"install-desktop" => PHOEBUS_INSTALL_DESKTOP_ENTRY.to_string(),
"greetd-installed" => greetd_config(default_cmd),
"greetd-live" => greetd_config_live(LIVE_USER, live_cmd),
// Live-only privilege policy (scoped, never NOPASSWD: ALL).
"live-sudoers" => LIVE_SUDOERS.to_string(),
// Live-only NVIDIA driver loading and diagnostics.
"nvidia-load" => PHOEBUS_NVIDIA_LOAD_SCRIPT.to_string(),
"nvidia-service" => PHOEBUS_NVIDIA_SERVICE.to_string(),
@ -1946,6 +1969,42 @@ mod tests {
assert!(desktop_asset("does-not-exist").is_none());
}
#[test]
fn live_sudoers_is_scoped_and_valid() {
let sudoers = desktop_asset("live-sudoers").unwrap();
assert!(sudoers.contains("/usr/local/bin/phoebus-installer"));
assert!(sudoers.contains("/usr/local/bin/sys"));
assert!(sudoers.contains("systemctl poweroff"));
// The unattended rule must never be a general root escape.
assert!(!sudoers.contains("NOPASSWD: ALL"), "{sudoers}");
assert!(!sudoers.contains("(ALL)"), "{sudoers}");
assert!(!sudoers.contains('*'), "{sudoers}");
assert!(sudoers.ends_with('\n'));
// `visudo` is the authority on syntax; validate when the host has it.
let Ok(mut child) = std::process::Command::new("visudo")
.args(["-cf", "/dev/stdin"])
.stdin(std::process::Stdio::piped())
.stdout(std::process::Stdio::null())
.stderr(std::process::Stdio::piped())
.spawn()
else {
return;
};
{
use std::io::Write;
if let Some(stdin) = child.stdin.as_mut() {
let _ = stdin.write_all(sudoers.as_bytes());
}
}
if let Ok(out) = child.wait_with_output() {
assert!(
out.status.success(),
"visudo rejected the live policy: {}",
String::from_utf8_lossy(&out.stderr)
);
}
}
#[test]
fn live_nvidia_assets_are_bounded_and_ordered_before_greetd() {
let load = desktop_asset("nvidia-load").unwrap();

View file

@ -83,8 +83,14 @@ launcher is missing; it never silently emits a text-only ISO.
completion. A second launch never opens a duplicate session. If Quickshell or
Wayland is unavailable the launcher falls back to the TUI/CLI.
- A text recovery console is available on the serial line and on another VT
(`Ctrl+Alt+F2`): log in as `phoebus` / `phoebus` (live-only credential),
passwordless `sudo`.
(`Ctrl+Alt+F2`): log in as `phoebus` / `phoebus` (live-only credential) and
use `sudo` with that password. Unattended (`NOPASSWD`) escalation is scoped
to the two typed brokers — `/usr/local/bin/phoebus-installer` and
`/usr/local/bin/sys` — plus `systemctl poweroff`/`reboot`. There is no
`NOPASSWD: ALL`, no `sh -c` and no wildcard; the policy is emitted as
`live-sudoers`, installed to `/etc/sudoers.d/90-phoebus-live` and validated
with `visudo` at build time. The password-authenticated recovery console is
deliberate and preserved.
- The `phoebus-dwl` session remains selectable as a fallback.
## NVIDIA accelerated graphics

View file

@ -102,7 +102,7 @@ assets=(
session-mango session-dwl assistant install welcome menu lock idle
mango-config mango-session-target install-desktop
wayland-session-mango wayland-session-dwl
waybar-config waybar-style greetd-live
waybar-config waybar-style greetd-live live-sudoers
brand-emblem brand-wordmark brand-wallpaper brand-tokens
nvidia-load nvidia-service gpu-report
)
@ -256,6 +256,18 @@ install_asset waybar-style /etc/xdg/waybar/style.css
# Live-only automatic login (never copied to an installed system).
install_asset greetd-live /etc/greetd/config.toml
# Live-only privilege policy. The recovery console keeps root through the
# password-authenticated sudo group; unattended escalation is scoped to the
# typed brokers. Reject a broad or malformed policy rather than ship it.
install -d -m 0755 "$rootfs/etc/sudoers.d"
install -D -m 0440 "$work/assets/live-sudoers" "$rootfs/etc/sudoers.d/90-phoebus-live"
if command -v visudo >/dev/null 2>&1; then
visudo -cf "$rootfs/etc/sudoers.d/90-phoebus-live" >/dev/null || {
echo "the emitted live sudoers policy is invalid" >&2; exit 1; }
fi
grep -qE 'NOPASSWD:[[:space:]]*ALL|ALL=\(ALL\)' "$rootfs/etc/sudoers.d/90-phoebus-live" && {
echo "refusing to ship an unscoped live sudoers policy" >&2; exit 1; } || true
# NVIDIA accelerated driver: load it before greetd/Mango, and provide
# diagnostics. The driver modules themselves are built into the rootfs by
# livefs-hook.sh; nouveau blacklisting and module options come from Debian's

View file

@ -33,8 +33,9 @@ if ! in_root id "$LIVE_USER" >/dev/null 2>&1; then
--groups sudo,video,render,input,audio "$LIVE_USER"
fi
install -d -m 0755 "$root/etc/sudoers.d"
printf '%s ALL=(ALL) NOPASSWD: ALL\n' "$LIVE_USER" > "$root/etc/sudoers.d/90-phoebus-live"
chmod 440 "$root/etc/sudoers.d/90-phoebus-live"
# The live privilege policy is the scoped, visudo-validated asset installed by
# build.sh (only the typed brokers escalate without a prompt). The recovery
# console keeps root through the password-authenticated sudo group below.
# A well-known live password so the serial/recovery console is usable; the
# graphical session still logs in automatically via greetd. This is live-only
# and is never written to an installed system.

View file

@ -944,10 +944,15 @@ class Driver:
# Preseed the wizard defaults so the run is bounded (safe kernel, no
# desktop) while the wizard, validation, AI gate and the direct
# "Install now" authorization remain the real graphical path.
# The live privilege policy no longer grants bare `install`, so stage
# the config and authenticate the one privileged write with the
# live-only credential, fetched to a 0600 file (never on the command
# line and never in the serial transcript).
self.shell(
f"curl -fsSL {SERVE_URL}/test.conf -o /tmp/gui-install.conf && "
"sudo -n install -D -m 0644 /tmp/gui-install.conf /etc/phoebus/install.conf && "
"echo PRESEED-$(printf DONE)",
f"curl -fsSL {SERVE_URL}/live.pw -o /tmp/live.pw && chmod 600 /tmp/live.pw && "
"sudo -S -p '' install -D -m 0644 /tmp/gui-install.conf /etc/phoebus/install.conf "
"< /tmp/live.pw && echo PRESEED-$(printf DONE)",
"PRESEED-DONE", timeout=60, label="preseed-config",
)
# Start the loopback relay to the host OpenCode server.

View file

@ -110,7 +110,7 @@ def main():
"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; "
"sudo -n systemctl is-enabled greetd; "
"systemctl is-enabled greetd; "
"echo ===CHECKS-$(printf END)===",
)
child.sendline(checks)