Repository navigation
fix(exec): start session children in the service account's $HOME (RFC-0002) - #199
Conversation
…-0002) RFC-0002's execution contract sets the child's cwd to the service account's $HOME, but spawn and spawn_pty never set a working directory: every exec and shell inherited the directory the server was started from — `/` under systemd, the crate directory in the tests. Both now call current_dir with the server's own HOME (the value the sanitised environment passes on), falling back to `/` when HOME is unset, relative or not a directory. Tests: `pwd -P` on pipes (accept.rs) and on a PTY (pty.rs) returns the canonical HOME; both fail without the fix (they print the crate directory). Found by Codex on #197. Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW Signed-off-by: Gonzalo Fleming <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
…s in $HOME (RFC-0002, #199) Codex on #197: under the unit the working directory is `/`, and the server did not set the children's. #199 fixes that in the server, for every deployment; the unit needs no WorkingDirectory=. Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW Signed-off-by: Gonzalo Fleming <[email protected]>
|
APIError: Insufficient Balance (request_id: c078ac05-2186-4cf1-8d23-4991713dca8b) |
…HOME systemd starts the server in `/`; with #199 merged in, a session's `pwd -P` is the account's home. The check fails with the pre-#199 binary and passes with it. Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW Signed-off-by: Gonzalo Fleming <[email protected]>
PR Review: fix(exec): start session children in the service account's $HOME (RFC-0002) (#199)Decision: 🟢 Approved Executive summaryThis PR makes New findingsNo findings reached the ≥ 80 confidence threshold. LimitationsCommit signature verification ( 🤖 Generated with Claude Code |
…ess protocol, reference unit (Proposed) (#197) * docs(adr): ADR-0043 — systemd Type=notify service, first-party readiness protocol, reference unit (Proposed) - The binary sends READY=1 once listening and STOPPING=1 with EXTEND_TIMEOUT_USEC (drain + 5 s) at the first SIGTERM/SIGINT, as one AF_UNIX datagram over std's UnixDatagram: no libsystemd, no crate, no unsafe (as OpenSSH 9.8p1 did after CVE-2024-3094). - Reference unit contrib/systemd/quantumssh.service: Type=notify, NotifyAccess=main, User=quantumssh, KillMode=mixed (ADR-0028's drain unchanged; cgroup leftovers killed at stop), Restart=on-failure, NoNewPrivileges=yes; no capability for port 22 and no sandboxing that would also confine sessions. - docs/deployment.md is the operator guide; CI runs the unit under real systemd on the Ubuntu runner. Refs #109 Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW Signed-off-by: Gonzalo Fleming <[email protected]> * docs(adr): ADR-0043 — no WorkingDirectory=; the server starts sessions in $HOME (RFC-0002, #199) Codex on #197: under the unit the working directory is `/`, and the server did not set the children's. #199 fixes that in the server, for every deployment; the unit needs no WorkingDirectory=. Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW Signed-off-by: Gonzalo Fleming <[email protected]> * docs(adr): ADR-0043 §4 — ProtectSystem=strict example without SFTP, which is not on main yet Codex on #198 (the same text is in the guide). Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW Signed-off-by: Gonzalo Fleming <[email protected]> --------- Signed-off-by: Gonzalo Fleming <[email protected]>
…de (ADR-0043) (#198) * docs(adr): ADR-0043 — systemd Type=notify service, first-party readiness protocol, reference unit (Proposed) - The binary sends READY=1 once listening and STOPPING=1 with EXTEND_TIMEOUT_USEC (drain + 5 s) at the first SIGTERM/SIGINT, as one AF_UNIX datagram over std's UnixDatagram: no libsystemd, no crate, no unsafe (as OpenSSH 9.8p1 did after CVE-2024-3094). - Reference unit contrib/systemd/quantumssh.service: Type=notify, NotifyAccess=main, User=quantumssh, KillMode=mixed (ADR-0028's drain unchanged; cgroup leftovers killed at stop), Restart=on-failure, NoNewPrivileges=yes; no capability for port 22 and no sandboxing that would also confine sessions. - docs/deployment.md is the operator guide; CI runs the unit under real systemd on the Ubuntu runner. Refs #109 Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW Signed-off-by: Gonzalo Fleming <[email protected]> * feat(systemd): Type=notify readiness, reference unit and operator guide (ADR-0043) - notify.rs (binary): the sd_notify datagram protocol on std's UnixDatagram, path and Linux abstract addresses; no libsystemd, no crate, no unsafe. READY=1 after the listener is bound and the SIGTERM/SIGINT handlers are installed; STOPPING=1 with EXTEND_TIMEOUT_USEC (drain + 5 s) at the first signal. - The signal handlers are now installed before the listener task is spawned, so a stop that follows READY=1 always drains. - contrib/systemd/quantumssh.service: Type=notify, NotifyAccess=main, User=quantumssh, KillMode=mixed, Restart=on-failure, NoNewPrivileges=yes. - docs/deployment.md: service account, StrictModes file layout, config, port 22 (nftables redirect, or the capability and its cost), logs, stop/restart/reload, and what each sandboxing directive does to sessions. - tests/systemd: the reference unit under a real systemd, in a container built from the interop gate's pinned Debian image; run by a new step in build (ubuntu-latest). - Unit tests for the sender and an integration test that runs the binary with NOTIFY_SOCKET. Refs #109 Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW Signed-off-by: Gonzalo Fleming <[email protected]> * docs(adr): accept ADR-0043 with its implementation; README and Phase-2 scoping mark systemd landed - ADR-0043 flips to Accepted with this implementing PR (#198); the date assumes a merge on 2026-10-13 (adjust if merged another day). Links name the implementing files. - README's Phase-2 roadmap and the scoping note's workstream row and ordering mark systemd integration as landed. Refs #109 Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW Signed-off-by: Gonzalo Fleming <[email protected]> * fix(exec): start session children in the service account's $HOME (RFC-0002) RFC-0002's execution contract sets the child's cwd to the service account's $HOME, but spawn and spawn_pty never set a working directory: every exec and shell inherited the directory the server was started from — `/` under systemd, the crate directory in the tests. Both now call current_dir with the server's own HOME (the value the sanitised environment passes on), falling back to `/` when HOME is unset, relative or not a directory. Tests: `pwd -P` on pipes (accept.rs) and on a PTY (pty.rs) returns the canonical HOME; both fail without the fix (they print the crate directory). Found by Codex on #197. Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW Signed-off-by: Gonzalo Fleming <[email protected]> * docs(adr): ADR-0043 — no WorkingDirectory=; the server starts sessions in $HOME (RFC-0002, #199) Codex on #197: under the unit the working directory is `/`, and the server did not set the children's. #199 fixes that in the server, for every deployment; the unit needs no WorkingDirectory=. Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW Signed-off-by: Gonzalo Fleming <[email protected]> * test(systemd): the reference-unit check asserts the session runs in $HOME systemd starts the server in `/`; with #199 merged in, a session's `pwd -P` is the account's home. The check fails with the pre-#199 binary and passes with it. Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW Signed-off-by: Gonzalo Fleming <[email protected]> * fix(server): the accept loop's shutdown receiver exists before any signal Codex on #198: serve subscribed its receiver when its future first ran, and the binary dropped the channel's initial receiver. A broadcast only reaches receivers that exist when it is sent, so a SIGTERM delivered right after READY=1 — a stop job systemd queued during the start — could be broadcast before serve subscribed, and the drain deadline was lost. Server::serve now takes the loop's receiver: the one broadcast::channel returns, alive from the channel's creation. The binary and the test support pass it instead of dropping it. Test: shutdown_sent_before_serve_first_runs_is_not_lost sends the deadline before the spawned serve is first polled; with the old subscribe-on-first-run it fails (SendError: no receiver). Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW Signed-off-by: Gonzalo Fleming <[email protected]> * docs(deployment): no SFTP in the guide until it lands (#196) Codex on #198: SFTP is not on main yet, so the guide must not present it as available. Sessions start in the home; ProtectSystem=strict's row names every write instead of SFTP uploads. Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW Signed-off-by: Gonzalo Fleming <[email protected]> * docs(adr): ADR-0043 §4 — ProtectSystem=strict example without SFTP, which is not on main yet Codex on #198 (the same text is in the guide). Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW Signed-off-by: Gonzalo Fleming <[email protected]> --------- Signed-off-by: Gonzalo Fleming <[email protected]>
Summary
execandshellchildren now start in the service account's$HOME, as RFC-0002's execution contract states (cwd = $HOME of the service account). Before,spawnandspawn_ptynever set a working directory, so every command inherited the directory the server was started from:/under the systemd reference unit of feat(systemd): Type=notify readiness, reference unit and operator guide (ADR-0043) #198;Codex found this while reviewing #197.
Motivation
This is a bug fix in the plain-PR lane. RFC-0002 (Accepted) already decides the behaviour, and the code did not follow it. The operator guide in #198 says sessions start in the account's home, which is only true with this fix.
Type of change
Changes
exec.rs:home_dir()returns the server's ownHOME(the value the sanitised environment passes on). It falls back to/whenHOMEis unset, relative or not a directory.spawnandspawn_ptycallcurrent_dir(home_dir()). The PTY helper keeps the directory across itssetsidandexec.CHANGELOG.md: aFixedentry.Checklist
git commit -s).cargo fmt --allandcargo clippy --workspace --all-targets -- -D warningslocally.docs/, orREADME.md) where appropriate.CHANGELOG.mdentry under## [Unreleased]if this change is user-visible.cargo deny check. (No new dependency.)Security considerations
env(ADR-0023)./fallback gives the same reach a/working directory had before.Tests
accept.rsexec_runs_in_the_home_directory:pwd -Pon pipes returns the canonicalHOME. The test first asserts that its own working directory is notHOME.pty.rsexec_on_a_pty_runs_in_the_home_directory: the same check on a PTY, through the re-exec helper.…/crates/quantumssh-coreand…/crates/quantumsshinstead ofHOME.Notes for reviewers
pwdunder the reference unit. Merge this PR first.Automated reviews
PRs authored by
dependabot[bot](and other bots) do not trigger opencode or Claude Code Review. Codex reviews through the Codex cloud GitHub App (ADR-0037).They are covered by CI (
commit-lint,build (ubuntu-latest)andbuild (macos-latest)— fmt, clippy, tests, release build —,cargo deny,openssh-interop;cargo auditruns weekly, not per PR) and manual review when needed.https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW