Skip to content

fix(exec): start session children in the service account's $HOME (RFC-0002) - #199

Merged
gonzafg2 merged 1 commit into
mainfrom
fix/exec-cwd-home
Oct 13, 2026
Merged

gonzafg2 merged 1 commit into
mainfrom
fix/exec-cwd-home

Conversation

@gonzafg2

Copy link
Copy Markdown
Owner

Summary

exec and shell children now start in the service account's $HOME, as RFC-0002's execution contract states (cwd = $HOME of the service account). Before, spawn and spawn_pty never set a working directory, so every command inherited the directory the server was started from:

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that changes existing behaviour)
  • Documentation only
  • Refactor / chore / CI / build

Changes

  • exec.rs:
    • home_dir() returns the server's own HOME (the value the sanitised environment passes on). It falls back to / when HOME is unset, relative or not a directory.
    • spawn and spawn_pty call current_dir(home_dir()). The PTY helper keeps the directory across its setsid and exec.
  • CHANGELOG.md: a Fixed entry.

Checklist

  • My commits are signed off under the Developer Certificate of Origin (git commit -s).
  • My commit messages follow Conventional Commits.
  • I have run cargo fmt --all and cargo clippy --workspace --all-targets -- -D warnings locally.
  • I have added or updated tests where appropriate.
  • I have updated documentation (rustdoc, docs/, or README.md) where appropriate.
  • I have added a CHANGELOG.md entry under ## [Unreleased] if this change is user-visible.
  • If this change introduces a new dependency, I have justified it in the PR description and verified it passes cargo deny check. (No new dependency.)

Security considerations

  • No privilege change. The UID, the environment allowlist and the process group are untouched.
  • The directory comes from the server's own environment. The client cannot influence it, because the channel layer refuses env (ADR-0023).
  • The / fallback gives the same reach a / working directory had before.

Tests

  • accept.rs exec_runs_in_the_home_directory: pwd -P on pipes returns the canonical HOME. The test first asserts that its own working directory is not HOME.
  • pty.rs exec_on_a_pty_runs_in_the_home_directory: the same check on a PTY, through the re-exec helper.
  • Both fail without the fix. They print …/crates/quantumssh-core and …/crates/quantumssh instead of HOME.
  • macOS: clippy is clean. All workspace tests pass: 122 unit and 41 integration tests in the core, 7 PTY tests and 34 in the binary.

Notes for reviewers

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) and build (macos-latest) — fmt, clippy, tests, release build —, cargo deny, openssh-interop; cargo audit runs weekly, not per PR) and manual review when needed.

https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW

…-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]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

gonzafg2 added a commit that referenced this pull request Oct 13, 2026
…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]>
@opencode-agent

Copy link
Copy Markdown

APIError: Insufficient Balance (request_id: c078ac05-2186-4cf1-8d23-4991713dca8b)

github run

gonzafg2 added a commit that referenced this pull request Oct 13, 2026
…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]>
@claude

claude Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

PR Review: fix(exec): start session children in the service account's $HOME (RFC-0002) (#199)

Decision: 🟢 Approved
Iteration: First review
Lenses applied: Rust under crates/, CHANGELOG.md

Executive summary

This PR makes exec and shell children (both pipe-based and PTY-based) start in the server's $HOME instead of the server process's working directory, implementing the execution contract from RFC-0002. The fix is minimal — two one-line additions to spawn() and spawn_pty(), a small private helper home_dir(), and matching tests for both paths. No new dependencies, no unsafe code, no legacy crypto, no type-state loosening; all five MANIFIESTO commitments are satisfied.

New findings

No findings reached the ≥ 80 confidence threshold.

Limitations

Commit signature verification (commit.verification.verified from the GitHub API) could not be run in this review environment. Branch protection enforces signed commits on main; verify before merging with:

gh api repos/gonzafg2/quantumssh/commits/5c19ff4056497d811d48d10808d9b20a8a6618c6 --jq '.commit.verification'

🤖 Generated with Claude Code

@gonzafg2
gonzafg2 merged commit fc3edf8 into main Oct 13, 2026
10 of 11 checks passed
@gonzafg2
gonzafg2 deleted the fix/exec-cwd-home branch October 13, 2026 06:02
gonzafg2 added a commit that referenced this pull request Oct 13, 2026
…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]>
gonzafg2 added a commit that referenced this pull request Oct 13, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant