Repository navigation
docs(adr): draft ADR-0022 — multi-threaded Tokio, minimal feature set - #47
Merged
Merged
Conversation
Fixes the Phase 1 async runtime: multi-threaded Tokio from the first commit (chosen for its compile-time Send bound on transport futures, not for parallelism), with a sequential accept loop and no spawn until Phase 2. Pins tokio 1.51 (active LTS, backports through March 2027, MSRV-1.92 compatible) with default-features = false and an explicit six-feature allowlist: net, io-util, rt-multi-thread, macros, time, sync. Excludes fs, process, and signal with rationale. The Send-bound argument is the crux: a current_thread runtime would let non-Send state into the type-state machine undetected and surface only as a Phase 2 refactor. rt-multi-thread makes that a line-1 compile error instead. Signed-off-by: Gonzalo Fleming <[email protected]>
This was referenced Jun 11, 2026
5 tasks done
3 tasks done
3 tasks done
…C-0004 Review findings from #47, applied: - The Send bound is imposed by tokio::spawn (identical on both schedulers), not by the runtime choice; what relaxes it is spawn_local/LocalSet and what skips it is not spawning at all. The accept loop becomes spawn-and-join (tokio::spawn(handle(..)).await): effective concurrency one, Send enforced from line one, and panic isolation per connection for free. Phase 2 removes the join. - quantumssh-core's feature list gains rt: spawn_blocking and tokio::spawn are gated behind it; the previous list could not compile the exec model the ADR commits to. - LTS wording aligned with Tokio's published policy (per-line end-of-support dates, at least a year of backports; README lists 1.51.x until March 2027 — the date claim was correct). - Sequential-loop slowloris window acknowledged in Negative: the timeout bounds one connection's hold, not a serialising adversary; accepted per threat model 8.3 until Phase 2's concurrent accept. - Adoption re-anchored as subsidiary to RFC-0004 (#61); future-file references marked TBD. Signed-off-by: Gonzalo Fleming <[email protected]>
gonzafg2
added a commit
that referenced
this pull request
Jun 12, 2026
…c audit boundary Review findings from #49, applied: - A second exec on the same channel (child running or exited) gets SSH_MSG_CHANNEL_FAILURE — the channel's single exec is consumed by the first accepted request; previously only 'other request types' were specified. - One channel per CONNECTION LIFETIME: a CHANNEL_OPEN after the first channel's close handshake also gets OPEN_FAILURE, preserving the 'exactly one exec per connection' invariant end to end; previously the rule was scoped to 'while a session channel is live'. - The exec acceptance point is now explicitly the audit boundary, binding exec.started/exec.finished with authenticated_identity and executing_uid as separate structured fields and command never interpolated (ADR-0024, TBD in review; CLAUDE.md hard rule). The ADR-0021 links resolve on this branch (merged to main); the ADR-0022 links resolve once #47 merges first (merge order: Signed-off-by: Gonzalo Fleming <[email protected]> #61 RFC-0004 -> #47 -> this PR -> #50).
gonzafg2
added a commit
that referenced
this pull request
Jun 12, 2026
A new pin is 'now we decide Y' — ADR-0015 routes decision changes to supersession; errata are only for factual corrections. Review finding on #61, also applied to ADR-0022's matching sentence in #47. Signed-off-by: Gonzalo Fleming <[email protected]>
Same ADR-0015 boundary fix as RFC-0004 (#61): a new pin is a decision change, routed to supersession; errata are for factual corrections only. Signed-off-by: Gonzalo Fleming <[email protected]>
gonzafg2
added a commit
that referenced
this pull request
Jun 12, 2026
…61) * docs(rfc): draft RFC-0004 — adopt Tokio as the Phase 1 async runtime The RFC process routes 'a new dependency that materially expands the trust base (anything in the crypto, networking, or process-spawning paths)' to the RFC lane, and the async runtime is the networking path the entire pre-auth surface flows through. RFC-0003 is silent on it. This short RFC decides the adoption; ADR-0022 (PR #47) remains the subsidiary operative decision (version pin, feature allowlist, threading model) and will cite it. Signed-off-by: Gonzalo Fleming <[email protected]> * docs(rfc): version bumps supersede ADR-0022, they are not errata A new pin is 'now we decide Y' — ADR-0015 routes decision changes to supersession; errata are only for factual corrections. Review finding on #61, also applied to ADR-0022's matching sentence in #47. Signed-off-by: Gonzalo Fleming <[email protected]> * docs: qualify the threat model's no-unsafe guarantee as first-party Review finding on #61: threat-model 3.2.4, 5.1.2 and 6.2 stated 'no unsafe in the pre-authentication path' without the first-party qualifier that ADR-0018 defines — a literal guarantee any dependency with internal unsafe on that path (the RFC-0003 primitives included, not just Tokio) would already read as violating, and 5.1.2 is framed as an auditor test handle. The three passages now state the first-party rule, name ADR-0018's forbid as the enforced mechanism, and route dependency-internal unsafe through the RFC lane explicitly. The RFC's trust-base section records that it carries this companion qualification — the RFC PR being precisely the lane the threat model's maintenance header requires for substantive edits. Signed-off-by: Gonzalo Fleming <[email protected]> * docs(rfc): future-tense and TBD markers for not-yet-landed artefacts Two review findings on #61: the server module and ADR-0022's feature allowlist were described in present tense as existing artefacts; both now use future tense with TBD/in-review markers per the CLAUDE.md rule. Signed-off-by: Gonzalo Fleming <[email protected]> --------- Signed-off-by: Gonzalo Fleming <[email protected]>
…1.3 deadline gap Two review findings from #47, applied: - The accept-loop snippet used 'let _ =', silently discarding the very JoinError the same sentence claimed gets logged. The loop now reads 'if let Err(join_err) = ... { emit connection.closed }' and the text makes capture-and-log a binding requirement. - Threat model 5.1.3 requires configurable handshake deadlines with documented defaults; the ADR cited the section but specified neither. New binding detail: 30 seconds from accept to userauth completion, --handshake-timeout flag, default in --help; rate limits and half-open caps land with Phase 2's concurrent accept (sequential loop = effective cap of one). Signed-off-by: Gonzalo Fleming <[email protected]>
Contributor
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
gonzafg2
added a commit
that referenced
this pull request
Jun 12, 2026
…#49) * docs(adr): draft ADR-0023 — Phase 1 channel layer scope (single-exec) Fulfils RFC-0003's deferred "ADR-TBD (scope of single-command execution)". Phase 1 implements exactly one `session` channel per connection carrying one `exec` request: eleven channel messages (OPEN..FAILURE), exec-only requests, exit-status sent, and explicit SSH_MSG_CHANNEL_FAILURE for pty-req/shell/subsystem/env/signal. Settles the non-obvious bits the ADR-0020 interop gate needs: stdin accepted, exit-status emitted before CLOSE, and real flow control (2 MiB initial window / 32 KiB max packet, matching OpenSSH's channels.h defaults so the interop client's assumptions hold). One channel per connection; global requests refused; exit-signal and env deferred to Phase 2. Child runs as the service-account UID per §8.12. Signed-off-by: Gonzalo Fleming <[email protected]> * docs(adr): close the second-exec and channel-reuse gaps; bind the exec audit boundary Review findings from #49, applied: - A second exec on the same channel (child running or exited) gets SSH_MSG_CHANNEL_FAILURE — the channel's single exec is consumed by the first accepted request; previously only 'other request types' were specified. - One channel per CONNECTION LIFETIME: a CHANNEL_OPEN after the first channel's close handshake also gets OPEN_FAILURE, preserving the 'exactly one exec per connection' invariant end to end; previously the rule was scoped to 'while a session channel is live'. - The exec acceptance point is now explicitly the audit boundary, binding exec.started/exec.finished with authenticated_identity and executing_uid as separate structured fields and command never interpolated (ADR-0024, TBD in review; CLAUDE.md hard rule). The ADR-0021 links resolve on this branch (merged to main); the ADR-0022 links resolve once #47 merges first (merge order: Signed-off-by: Gonzalo Fleming <[email protected]> #61 RFC-0004 -> #47 -> this PR -> #50). * docs(adr): specify the inbound window discipline — bound, overrun disconnect, backpressure Review finding from #49: 'flow control is real' covered outbound correctness but not the receiver-side policy, which is the security-relevant half. Now binding: per-channel buffered memory is bounded by the advertised inbound window; a peer exceeding it violates RFC 4254 5.2 and gets SSH_MSG_DISCONNECT (SSH_DISCONNECT_PROTOCOL_ERROR) rather than over-buffering; inbound WINDOW_ADJUST is granted only as the child's stdin consumes data, so a stalled child backpressures the wire instead of growing a queue. Signed-off-by: Gonzalo Fleming <[email protected]> * docs(adr): define hostile/out-of-order channel traffic and the stdin-stall semantics Four review findings from #49, applied: - Inbound EXTENDED_DATA rejected: RFC 4254 defines no client-to-server extended-data type, so message 95 inbound terminates the connection (PROTOCOL_ERROR) — no accept-and-branch path. - Inbound DATA before exec is buffered within the window (legitimate stdin pipelining) and delivered when the child starts; discarded if the channel closes without an exec. - DATA after the client's EOF violates RFC 4254 5.3 -> disconnect; client CLOSE with a live child (no prior EOF, RFC-permitted) closes stdin, terminates the child, replies CLOSE, frees the channel, omits exit-status — no orphaned child survives its channel. - The stdin-ignoring-child window stall is documented as intentional backpressure (draining unread stdin would silently discard data and unbound the memory the window bounds); messages for unknown channel numbers fail closed with PROTOCOL_ERROR. Signed-off-by: Gonzalo Fleming <[email protected]> * docs(adr): define the server-initiated half-close window Review finding from #49: RFC 4254 5.3 lets the two CHANNEL_CLOSEs cross in flight, so frames arriving after the server's CLOSE but before the client's are legitimate — yet the child has exited and there is no sink. Decision: accept and silently discard channel messages during that window; free the channel on the client's CLOSE; messages addressed to the freed channel number after that fall under the unknown-channel rule and terminate the connection. Signed-off-by: Gonzalo Fleming <[email protected]> * docs(adr): correct OPEN_FAILURE reason codes; audit record survives early close Three review findings from #49, applied: - RFC 4254 5.1 distinguishes the codes: non-session types (no Phase 1 handler) get SSH_OPEN_UNKNOWN_CHANNEL_TYPE (3); a second session — understood but policy-refused — keeps ADMINISTRATIVELY_PROHIBITED (1). One code for both cases was a conformance bug. - exec.finished is emitted on every path that produced exec.started, including client-initiated early close (with the terminated child's conventional non-zero exit status) — omitting the wire exit-status never skips the audit record. - The audit-boundary sentence no longer cites TBD ADR-0024 as the normative authority ('per'): the binding authority is CLAUDE.md's hard rule; ADR-0024 (in review) fixes the full schema. Signed-off-by: Gonzalo Fleming <[email protected]> * docs(adr): mark the ADR-0024 reference TBD per convention Signed-off-by: Gonzalo Fleming <[email protected]> --------- Signed-off-by: Gonzalo Fleming <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds ADR-0022, fixing the Phase 1 async runtime: multi-threaded Tokio from the first commit, sequential accept loop via spawn-and-join (no concurrent/unjoined
spawnuntil Phase 2), pinned totokio = "1.51"(active LTS) withdefault-features = falseand an explicit six-feature allowlist.Motivation
The root
Cargo.tomlcarriestokioonly as a commentedfeatures = ["full"]placeholder.server.rscannot be written without fixing the runtime and — more importantly — the threading model, because it decides theSendbound on every type that crosses an.await.The crux: the tempting move is "Phase 1 is sequential → use
current_thread." That relaxes theSendbound, which lets non-Sendstate (Rc,RefCell, …) into the type-state transport machine undetected. It compiles now and breaks as an invasive refactor when Phase 2 adds concurrency.rt-multi-threadmakes that a line-1 compile error instead. The multi-threaded runtime is chosen for that compile-time effect, not for parallelism Phase 1 doesn't use.Feature allowlist
netTcpListener/TcpStreamio-utilAsyncReadExt/AsyncWriteExtfor binary-packet framingrt-multi-threadSendboundmacros#[tokio::main],#[tokio::test]timetimeout— handshake budget (threat model §5.1.3)syncbroadcast— graceful shutdownExcluded with rationale:
fs(startup reads usestd::fs),process(exec viaspawn_blocking+std::process::Command),signal(Phase 2).Type of change
Checklist
Security considerations
Tightens surface (
default-features = false+ allowlist instead offull). Thetimefeature backs the handshake-budget control in threat model §5.1.3. Tokio's ownunsafelives in the dependency, untouched by the first-partyunsafe_code = "forbid"of ADR-0018.Notes for reviewers
1.51.xis the LTS line supported through March 2027; latest stable is1.52.3. I deliberately pin the LTS, not latest, for a foundational dependency.spawn_blocking+std::process::Commandexec model is explicitly provisional — Phase 2 PTY work will likely revisit it. Flagged in the ADR so it is not read as final.Proposed; advances toAcceptedwith the first crate, like ADR-0016–0021.