Repository navigation
docs(adr): ADR-0043 — systemd Type=notify service, first-party readiness protocol, reference unit (Proposed) - #197
Conversation
…ess 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]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
APIError: Insufficient Balance (request_id: 3dca9dd7-5bf6-4f2b-9b80-046616f0fc59) |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5a48d3ac2b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…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: b8c0c2f4-1eb2-47c8-a5df-77c19eddb9cd) |
…hich 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]>
|
APIError: Insufficient Balance (request_id: 04df71ac-1b93-4d67-883b-99e623a1b18f) |
…-0002) (#199) 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]>
|
APIError: Insufficient Balance (request_id: 58f37e95-e4e4-4ab1-bd8a-3978a47a2e85) |
Resolves the conflicts with #197 (squashed ADR-0043: keep this branch's Accepted status and Links), #201 (Server::serve: its # Errors doc with this branch's loop_rx signature) and the CHANGELOG Fixed section. Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW 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
ADR-0043 decides how QuantumSSH runs under systemd, the last Phase-2 workstream before the
0.1.0freeze (#109; the scoping note places it in the ADR lane).READY=1once its port accepts connections and its signal handlers are installed. At the first SIGTERM/SIGINT it sendsSTOPPING=1withEXTEND_TIMEOUT_USEC=set to the drain plus 5 s. Each message is oneAF_UNIXdatagram over std'sUnixDatagram.libsystemd, no crate and nounsafe.libsystemdlink after CVE-2024-3094 and has used a standalone implementation since 9.8p1.contrib/systemd/quantumssh.service:Type=notifyandNotifyAccess=main, written out because it is load-bearing: sessions are processes of the unit.User=quantumssh, per ADR-0016.KillMode=mixed: ADR-0028's drain runs unchanged, and processes that escaped their channel are killed at stop.Restart=on-failureandNoNewPrivileges=yes.DynamicUser=and the watchdog are rejected or deferred, with reasons.docs/deployment.md. It also writes the operator guidance ADR-0016 left open.The ADR stays
Proposed. The implementing PR (stacked on this one) flips it toAccepted.Refs #109
Type of change
Changes
docs/adr/0043-systemd-notify-service-and-reference-unit.md(new,Proposed).Evidence behind the decision
v262sources:man/sd_notify.xml: address forms, "Standalone Implementations", and theREADY=1,STOPPING=1andEXTEND_TIMEOUT_USEC=entries;man/notify-selfcontained-example.py: "guaranteed to be stable";man/systemd.kill.xml:KillMode=mixed;man/systemd.service.xml:Type=notifyforcesNotifyAccess=main;man/systemd.exec.xml:NoNewPrivileges=andAmbientCapabilities=;meson_options.txt: the 90 s default stop timeout.src/core/service.catv262::5516handlesSTOPPING=1before:5746handlesEXTEND_TIMEOUT_USEC=, so one datagram is enough;:436: the extension never shortens the timer;:2714: stop-by-notify sends no signal.openbsd-compat/port-linux.c:133-188atV_10_6_P1, and commit08f5792(2024-04-03, "Standalone implementation that does not depend on libsystemd"). It is absent atV_9_7_P1and present atV_9_8_P1.TimeoutStopSec=2and a 4 s drain, the stop ends withResult=success;STOPPING=1without the extension, the same stop ends withState 'stop-sigterm' timed out. Killing.andResult=timeout;KillMode=control-group, sessions die at once and the drain is lost (stopped after 0 s).Checklist
git commit -s).cargo fmt --allandcargo clippy --workspace --all-targets -- -D warningslocally. (Documentation only.)docs/, orREADME.md) where appropriate.CHANGELOG.mdentry under## [Unreleased]if this change is user-visible. (Not user-visible; the implementing PR adds it.)cargo deny check. (No new dependency.)Security considerations
unsafe. The decision explicitly rejects linkinglibsystemd(the CVE-2024-3094 path) and socket activation, which would needFromRawFdon the listener.NotifyAccess=mainkeeps sessions, which are processes of the unit, from driving the service manager.NoNewPrivileges=yesremoves setuid/setgid elevation from every session.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