Spaces OS spacesos.org

pi-sessiond: Landlock sandbox + supervisor inversion (squashed, cleaned) #32

Open pinpox.com
targeting main
Open opened by pinpox.com
targeting main

Squashed + cleaned form of the runtime-isolation stack since main; the granular 8-commit history is preserved under bookmark landlock-unify.

What this branch does:

  • Inverts pi-sessiond into a supervisor that drives one pi --mode rpc child per session over a JSON-line pipe; the daemon runs no model loop, tools, or bash (only the memory extension stays in-process, daemon-side).
  • Confines every child in a self-applied Landlock domain via pi-landlock-exec (deny-by-default FS allowlist + egress-port allowlist + IPC scoping, plus a seccomp denylist on the unit). This is the SOLE sandbox path for BOTH the desktop (user service, uid 1000) and the system/remote executor (root daemon that drops each unit to a fixed pi-session uid via systemd-run --uid + chown). The managed-userns/nsresourced path is deleted outright.
  • test-machine OpenRouter wiring (eval-time + runtime key injection).

Cleanup folded in:

  • Drop the dead bind-mount-era fields from the skill-bind data model: SandboxBind.target (Landlock grants the path in place, no remapping) and .optional (pi-landlock-exec already skips a missing grant non-fatally). Removed from sandbox.ts, the services.pi-sessiond-local.bashBinds and services.pi-chat.sandboxBinds submodules, the env-builder, and every caller (signal-cli, pi-chat baselines). The daemon emits/reads only { source, mode }.
  • Factor the child/extension/settings wiring shared by the two pi-sessiond deployment modules into modules/nixos/pi-sessiond/lib.nix.
  • Fix the stale comment/description cluster left from before the supervisor inversion and the bind-mount era (per-bash transient units, ProtectHome/ BindPaths/TRUSTED framing, in-process-pi / SDK wording) across both modules.
  • Factor the duplicated cheap-check launcher stubs into one helper, checks/pi-sessiond-sidechannel/launcher-stubs.nix.
  • Update the bind-schema checks to the { source, mode } contract (pi-chat-sandbox-binds-nix, spaces-signal-nix-eval).

Signal DB access (regression fix):

  • The supervisor inversion repoints each session HOME to a private per-session agent dir (main.ts), but the in-sandbox signal CLI resolves messages.db from $HOME (db.default_db_path). With the old bind-mount sandbox HOME was the login home, so ~/.local/state/spaces/signal was the granted store; under Landlock + the remapped HOME the CLI looked under the empty agent dir and failed with "unable to open database file" (DB-reading subcommands only; socket-backed send/contacts kept working). Pure-read of the WAL store under the read-only Landlock grant is itself fine while the bridge holds its long-lived connection open (the -wal/-shm sidecars stay live) — the failure was the path, not the grant.
  • Fix: add services.pi-chat.sandboxEnv (attrsOf str), forwarded into services.pi-sessiond-local.bashEnv after the pi-chat baseline — the env-side mirror of sandboxBinds. signal-cli.nix publishes SPACES_SIGNAL_DB = "%h/.local/state/spaces/signal/messages.db" through it (%h expands to the login home in the daemon unit Environment=, matching the RO bind source); db.default_db_path already honors that var first, so the CLI resolves the granted store regardless of the remapped HOME.

Verified: signal-cli pytest 144 green incl. a new TestSandboxHomeRemap that pins the contract (HOME-relative default misses the login store; the published SPACES_SIGNAL_DB targets it) and reads a read-only WAL store through the CLI with a live bridge-style writer; spaces-signal-nix-eval extended to assert the forwarded env carries SPACES_SIGNAL_DB (red without the publish, green with it); pi-sessiond-local-nix-eval and pi-chat-sandbox-binds-nix green; bun unit tests (15) green; the local module + helper are output-preserving; the system module emits the expected settings.json/env and the pi-sessiond-lifecycle VM boots, applies a fully-enforced Landlock domain, and passes cold-attach / resume / LRU-eviction end-to-end.

This pull request has no versions submitted yet.

Sign up or Sign in to add to the discussion.