Skip to content

feat(core): M5 — channel layer + single-command exec - #84

Merged
gonzafg2 merged 5 commits into
mainfrom
feat/m5-channels-exec
Jun 26, 2026
Merged

gonzafg2 merged 5 commits into
mainfrom
feat/m5-channels-exec

Conversation

@gonzafg2

Copy link
Copy Markdown
Owner

What

Implements M5, the final tranche of the Phase 1 walking skeleton (ADR-0023): one session channel carrying one exec, streaming output, then a clean close. ssh host 'echo hello' now works end-to-end against a real OpenSSH 10.x client.

This is the work tracked under issue #9 (closed) — the channel/exec layer the M4 terminal reject_channel_open was a placeholder for.

How it's built

  • transport.rs — new Session type-state stage with a cancel-safe read_packet (resumable inbuf) that shares the decrypt path with read_sealed via factored helpers — no second framing path. AuthAccepted → Session threads the authenticated key fingerprint for the audit events.
  • channel.rs — the RFC 4254 connection layer scoped to ADR-0023: eleven channel messages, one honoured exec, real bidirectional flow control (2 MiB window / 32 KiB packet; inbound credit returned only as the child drains stdin), and a total, fail-closed dispatch. The driver multiplexes inbound packets against blocking-thread child output with one tokio::select!, never holding two &mut borrows of the wire.
  • exec.rs — /bin/sh -c child on spawn_blocking (ADR-0022) with dedicated stdin/stdout/stderr pumps + reap; rustix for getuid and kill-on-early-close; sanitised env (ADR-0016); exec.started/exec.finished audit events (ADR-0024).
  • server.rs — the handshake budget now bounds only up to authentication; the channel phase runs un-timed.

Decisions (see plan docs/plans/m5-channels.md)

  • /bin/sh -c for exec (ADR-0023 erratum): interop requires shell interpretation, and the service account's login shell is nologin. Bounded by the service-account UID + sanitised env + one-channel/one-exec scope.
  • rustix over nix for getuid/kill (ADR-0016 amended): smaller surface (MANIFIESTO chore(security): mark quantumssh.org aliases as live #4); one dep, process feature only. All subtree licences (Apache-2.0/MIT) are in the deny.toml allowlist.
  • ADRs amended in place (still Proposed); status flip to Accepted deferred — all Phase-1 ADRs (0016–0024) share that lag, so a separate governance sweep is the right place, not a one-off flip here.

Verification

Local, against OpenSSH 10.2p1:

ok: openssh_smoke              # echo hello -> hello, exit 0
ok: openssh_verbose_kex        # kex: algorithm: mlkem768x25519-sha256
ok: negative_no_hybrid         # classical-only client rejected
ok: exit_status_propagation    # exit 3 -> 3
INTEROP PASS

Plus cargo fmt --check, clippy -D warnings, 80 unit + 20 integration tests (incl. cancel_safety_under_load, 3 MiB), shellcheck clean.

Interop CI gate (ADR-0020)

Adds tests/interop/run_openssh_client.sh and .github/workflows/interop.yml (Debian trixie container → OpenSSH 10.0p1). One follow-up before merge: the container is referenced by tag; ADR-0020 wants it pinned to an image digest (debian@sha256:…) — marked TODO in the workflow, to be resolved with a docker pull.

https://claude.ai/code/session_01BRMdwxsqYQPbjrWB1Cek6o

Implements the final tranche of the Phase 1 walking skeleton (ADR-0023):
one session channel carrying one exec, streaming output, clean close.
`ssh host 'echo hello'` now works end-to-end against a real OpenSSH 10.x.

- transport.rs: new `Session` type-state stage with a cancel-safe
  `read_packet` (resumable inbuf) sharing the decrypt path with
  `read_sealed`; `AuthAccepted -> Session` threads the key fingerprint.
- channel.rs: the RFC 4254 connection layer scoped to ADR-0023 — eleven
  channel messages, one honoured exec, real bidirectional flow control
  (2 MiB window / 32 KiB packet), total fail-closed dispatch.
- exec.rs: /bin/sh -c child on spawn_blocking (ADR-0022) with stdin/
  stdout/stderr pumps; rustix for getuid + kill-on-early-close; sanitised
  env (ADR-0016); exec.started/exec.finished audit events (ADR-0024).
- server.rs: handshake budget bounds auth only; channel phase un-timed.
- Cargo.toml: add rustix (process feature), justified. ADR-0016 amended
  (rustix over nix); ADR-0023 erratum (/bin/sh -c + sanitised env).
- tests: 8 channel unit tests + 8 exec integration tests incl.
  cancel-safety-under-load (3 MiB); tests/interop OpenSSH gate (ADR-0020).

Verified locally against OpenSSH 10.2p1: smoke, verbose-kex (hybrid KEX),
negative-no-hybrid, and exit-status propagation all pass.

Claude-Session: https://claude.ai/code/session_01BRMdwxsqYQPbjrWB1Cek6o
Signed-off-by: Gonzalo Fleming <[email protected]>
@opencode-agent

Copy link
Copy Markdown

Now I have a complete picture. Here's my review.


PR Review: feat(core): M5 — channel layer + single-command exec

Classification: APPROVE with 1 non-blocking finding

Verification results

Check Result
cargo fmt --check clean
cargo clippy -D warnings clean
cargo test --workspace 80 unit + 20 integration, all pass
unsafe in first-party code none
cargo deny would pass (rustix: Apache-2.0/MIT)
Legacy crypto compiled in none

High-signal findings

1. dtolnay/rust-toolchain@stable in interop workflow is unpinned (.github/workflows/interop.yml:53)

The workflow's container runs with debian:trixie-slim, not on the Ubuntu runner directly, so the installed Rust via apt-get in step 1 may not align with rust-toolchain.toml. The dtolnay/rust-toolchain@stable action picks whatever the latest stable is at runtime, sidestepping the pinned toolchain in rust-toolchain.toml. The PR already has a TODO on the container tag for ADR-0020; this action pin is the same category: a mutable ref on a path that decides what Rust compiles the binary the interop client tests against. The project's own rust-toolchain.toml pins stable with MSRV 1.92; the CI job should honour it. This is a threat-model §6.1 (supply-chain/infrastructure) issue, not a code issue — but it is the CI gate ADR-0020 authorises as a hard gate.

Recommendation: Replace dtolnay/rust-toolchain@stable with either (a) an explicit toolchain spec that matches rust-toolchain.toml, or (b) defer to the system Rust if the Debian trixie package version suffices.


Audit event compliance: PASS

Both events fire on target: "audit" with the mandated fields (CLAUDE.md:72-73, ADR-0024):

  • exec.started (channel.rs:547-553): authenticated_identity, executing_uid, command (structured, not interpolated)
  • exec.finished (channel.rs:406-413): authenticated_identity, executing_uid, exit_status
  • exec.finished is emitted exactly once, on every path that produced exec.started (including spawn-failure, early close, and normal exit), satisfying ADR-0023's requirement that omitting a wire message never skips the audit record.

MANIFIESTO commitment compliance: PASS on all five

  1. Memory-safe by construction — zero unsafe in all new/changed first-party files. rustix wraps raw syscalls in audited safe abstractions.
  2. Post-quantum by default — no new KEX introduced; mlkem768x25519-sha256 remains the sole KEX. The interop gate asserts it.
  3. Zero legacy — no RSA, DSA, ECDSA-NIST, CBC, password auth, or compression compiled in. pty-req, shell, subsystem, env are all explicitly refused.
  4. Small surface, sharp edges — rustix chosen over nix (MANIFIESTO chore(security): mark quantumssh.org aliases as live #4), process feature only. One new dep, justified in PR body and ADR-0016 erratum.
  5. Permanently open — rustix license (Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT) is in deny.toml allowlist. No relicensing.

Security rules: PASS

  • Pre-auth surface unchanged — M5 operates post-auth only.
  • Fail closed — non-hybrid KEX, missing strict-kex, unknown channel types, inbound extended data, data-after-EOF, window overflow all disconnect with protocol error.
  • AEAD-only maintained — no MAC path exercised.
  • Key material — SharedSecret and ExchangeHash remain Zeroizing. Session carries no secret material.
  • Type-state machine — Session is a proper stage (implements SealedRead/SealedWrite), no accept-and-branch regression. Internal channel states are a private enum inside the driver.
  • Cancel-safe read — shared frame_body_len/open_frame helpers with read_sealed, resumable inbuf, no second framing path.

CI/workflow: 1 finding (non-blocking)

The container tag debian:trixie-slim is mutable — acknowledged by the PR's own TODO. The @stable action ref on line 53 is the actionable one. Neither blocks merge for a pre-alpha walking skeleton, but both should be fixed before the interop gate has downstream consumers.

github run

trixie's openssh-client package 1:10.0p1-7 now ships binary OpenSSH_10.0p2
via security update deb13u4; the exact-p1 assertion rejected it. Assert
the 10.0p line and the mlkem768x25519-sha256 KEX (the real requirement).

Claude-Session: https://claude.ai/code/session_01BRMdwxsqYQPbjrWB1Cek6o
Signed-off-by: Gonzalo Fleming <[email protected]>
@opencode-agent

Copy link
Copy Markdown

Now I have a complete picture. Here's my review.


PR Review: feat(core): M5 — channel layer + single-command exec

Classification: APPROVE with 2 non-blocking CI findings

Verification results

Check Result
unsafe in first-party code zero — grep confirmed only doc-comment mention
authenticated_identity / executing_uid on exec.* events both fields present on exec.started (channel.rs:547-553) and exec.finished (channel.rs:401-413)
command is a structured field, never interpolated command = %command (structured tracing field, channel.rs:551)
exec.finished emitted on all paths that produce exec.started spawn-success (normal close + early close), spawn-failure (exit 127), emit_finished() on Closed state — exactly once per command_started
Legacy crypto compiled in none
KEX: mlkem768x25519-sha256 only unchanged from M4
MAC path exercised no — AEAD-only maintained
Type-state machine Session is a proper stage, implements SealedRead/SealedWrite, transitions via AuthAccepted::serve
ADR amendment rules ADR-0016/0023 still Proposed — in-place edits are permitted by ADR-0015 before acceptance

High-signal findings

1. dtolnay/rust-toolchain@stable is a mutable action ref (.github/workflows/interop.yml:57)

The stable tag follows the latest stable Rust, sidestepping the pinned rust-toolchain.toml (MSRV 1.92). This is threat-model §5.5.2 (supply-chain compromise of dependencies) territory: the action ref that decides the compiler for the interop-gate binary is mutable. The PR's own TODO on the container tag (line 29-32) acknowledges the same class of problem for the OS layer; this action ref is the same category on the toolchain layer. Not blocking for a pre-alpha walking skeleton, but should be fixed before the interop gate has downstream consumers that trust it.

Recommendation: Pin to a specific Rust version matching rust-toolchain.toml (e.g. dtolnay/[email protected]) or use rust-toolchain: stable with a file reference.

2. debian:trixie-slim is a mutable container tag (.github/workflows/interop.yml:34)

Already acknowledged by the PR's own TODO(ADR-0020) comment on lines 29-32. The tag resolves to a floating Debian snapshot; an upstream OpenSSH update in trixie could break or silently change the interop gate without a reviewed code change. The ADR-0020 requirement is to pin to an image digest.


MANIFIESTO commitment compliance: PASS on all five

  1. Memory-safe by construction — zero unsafe in all new/changed first-party files. rustix wraps raw syscalls in audited safe abstractions.
  2. Post-quantum by default — no new KEX introduced; mlkem768x25519-sha256 remains the sole KEX. The interop gate asserts it at lines 64-66 and is verified in testing.
  3. Zero legacy — no RSA, DSA, ECDSA-NIST, CBC, password auth, or compression compiled in. pty-req, shell, subsystem, env are all explicitly refused in on_channel_request (channel.rs:499-535).
  4. Small surface, sharp edges — rustix (process feature only) chosen over nix per MANIFIESTO chore(security): mark quantumssh.org aliases as live #4. One new dep, justified in PR body, ADR-0016 erratum, and plan §7.2. License (Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT) is in deny.toml allowlist.
  5. Permanently open — no relicensing. rustix license posture is Apache-2.0-compatible.

Security rules: PASS

  • Pre-auth surface — unchanged; M5 operates post-auth only.
  • Fail closed — handle_inbound (channel.rs:419-451) is a total, 12-arm match: 11 honoured/refused channel messages + DISCONNECT. Unknown messages → protocol_disconnect. Inbound EXTENDED_DATA (95) → disconnect. DATA-after-EOF → disconnect. Window overflow → disconnect. Unknown channel → disconnect.
  • AEAD-only maintained — no MAC path exercised.
  • Key material — SharedSecret and ExchangeHash remain Zeroizing. Session carries no key material, only the cipher pair and authenticated identity fingerprint.
  • Type-state machine — Session is stage 8, implements SealedRead/SealedWrite, transitions cleanly from AuthAccepted::serve() (transport.rs:838-851). Internal channel states are a private enum (ChannelState), not a type-state regression.
  • Cancel-safe read — read_packet (transport.rs:870-889) stores partial progress in inbuf; fill_inbuf (transport.rs:896-910) extends atomically (no .await between read and extend_from_slice). Shares frame_body_len/open_frame helpers with read_sealed — one framing path.
  • Flow control is real — inbound window enforced (channel.rs:603-604: data_len > in_window → disconnect), outbound window tracked in u64 to detect u32 overflow (channel.rs:634-637), credit returned only as child consumes stdin (channel.rs:269-275, 359-363).

ADR amendments: SOUND

  • ADR-0016 (line 35): replaces nix::unistd::Uid::current() with rustix::process::getuid(). Rationale (smaller surface, same process feature covers kill too) is stated in the erratum. ADR is Proposed — amendments are permitted per ADR-0015.
  • ADR-0023 (line 38): adds /bin/sh -c erratum. Rationale is sound: SSH exec delivers an opaque string; interpreting it requires a shell; the service account's login shell is /usr/sbin/nologin. Bounded by service-account UID + sanitised env + one-channel/one-exec scope.

CI/workflow: 2 findings (non-blocking)

Both are the mutable-ref class — acknowledged by the PR's own design:

  1. dtolnay/rust-toolchain@stable — mutable action ref, sidesteps rust-toolchain.toml (see finding ci(deps): Bump actions/checkout from 4 to 6 #1 above).
  2. debian:trixie-slim — mutable container tag (already marked TODO(ADR-0020), line 29-32).

The interop script itself (tests/interop/run_openssh_client.sh) is shellcheck-clean, uses set -euo pipefail, generates ephemeral keys, and properly cleans up. The four assertions (smoke, verbose_kex, negative_no_hybrid, exit_status_propagation) map exactly to ADR-0020/ADR-0023 requirements.

github run

Comment thread .github/workflows/interop.yml Resolved
Comment thread crates/quantumssh-core/src/channel.rs Resolved
Comment thread .github/workflows/interop.yml Resolved
Comment thread crates/quantumssh-core/src/exec.rs Resolved
Addresses claude-review findings on PR #84:

- channel.rs: reject `maximum_packet_size == 0` at channel open. A zero
  max-packet makes flush_output compute a send size of 0 forever — output
  never drains, the close sequence never fires, and the un-timed channel
  phase hangs while the child's stdout pump pins a blocking-pool thread.
  An authenticated user could exhaust the pool. Fail closed (RFC 4254
  §5.1 sets no minimum, so the server enforces one).
- exec.rs: add `Drop for ChildIo` that kills the child unless the reap
  task has already waited on it. A `reaped` flag, set before the exit is
  reported, ensures a Drop-time kill never targets a pid the OS may have
  reused. Guarantees no child outlives its channel on abrupt transport
  failure (TCP reset, decrypt error), not only on a cooperative
  CHANNEL_CLOSE — closing the other blocking-pool-exhaustion vector.
- interop.yml: pin the Debian trixie container by image digest (ADR-0020),
  replacing the mutable tag; no placeholder left in a merged path.

Adds the zero_max_packet_is_rejected integration test (21 integration
tests now). fmt/clippy/test/interop all green locally.

Claude-Session: https://claude.ai/code/session_01BRMdwxsqYQPbjrWB1Cek6o
Signed-off-by: Gonzalo Fleming <[email protected]>
@opencode-agent

Copy link
Copy Markdown

PR Review: feat(core): M5 — channel layer + single-command exec

Classification: APPROVE — no blocking findings

Previous findings resolved in this revision

All three issues flagged by earlier reviewers are now addressed:

Finding Status Location
debian:trixie-slim mutable container tag Fixed — pinned to debian@sha256:28de0877... .github/workflows/interop.yml:36
max_pkt == 0 stalls channel permanently Fixed — max_pkt == 0 triggers fail-closed disconnect channel.rs:488-495
ChildIo lacks Drop, orphans child on abrupt disconnect Fixed — Drop impl kills child unless already reaped exec.rs:77-88

Remaining finding (non-blocking)

dtolnay/rust-toolchain@stable is a mutable action ref (.github/workflows/interop.yml:59). The stable branch tag floats to whatever is current at runtime, sidestepping the pinned rust-toolchain.toml that the rest of CI honours. This is the same class of mutable-ref concern as the container tag that was already fixed — the action that decides the compiler for the interop-gate binary should be pinned. Not blocking for a pre-alpha walking skeleton, but should be resolved before the interop gate has downstream consumers.

Verification

Check Result
unsafe in first-party code zero
authenticated_identity / executing_uid on exec.* events present on both exec.started (channel.rs:555-561) and exec.finished (channel.rs:401-413)
command structured, never interpolated command = %command (channel.rs:559)
exec.finished emitted on all paths spawn-success, spawn-failure, early-close, normal exit — exactly once
max_pkt == 0 → fail closed channel.rs:493-494
ChildIo::Drop → kill unless reaped exec.rs:83-87
Legacy crypto compiled in none
KEX: mlkem768x25519-sha256 only unchanged
AEAD-only, no MAC path maintained
Type-state: Session is stage 8 transitions via AuthAccepted::serve() (transport.rs:838-851)
One-channel-per-connection BeforeOpen guard (channel.rs:469), second open → SSH_OPEN_ADMINISTRATIVELY_PROHIBITED
Non-session channel type refused SSH_OPEN_UNKNOWN_CHANNEL_TYPE (channel.rs:479-487)
pty-req/shell/subsystem/env all refused total else branch (channel.rs:532-541)
rustix license in allowlist deny.toml has Apache-2.0 WITH LLVM-exception (line 23)
Interop script shellcheck-clean, set -euo pipefail tests/interop/run_openssh_client.sh

MANIFIESTO commitments: PASS all five

  1. Memory-safe — zero first-party unsafe; rustix wraps syscalls in safe abstractions
  2. PQ by default — mlkem768x25519-sha256 sole KEX; interop gate asserts it
  3. Zero legacy — no RSA/DSA/ECDSA-NIST/CBC/password/compression compiled in; all non-exec requests refused
  4. Small surface — rustix (process feature only) chosen over nix per MANIFIESTO chore(security): mark quantumssh.org aliases as live #4; one new dep, justified
  5. Permanently open — rustix license compat confirmed; no relicensing

ADR amendments: SOUND

  • ADR-0016 (line 35): replaces nix::unistd::Uid::current() with rustix::process::getuid() — rationale documented, still Proposed, permitted per ADR-0015
  • ADR-0023 (line 38): adds /bin/sh -c erratum — bounded by service-account UID + sanitised env + one-channel/one-exec; still Proposed

github run

Comment thread crates/quantumssh-core/src/channel.rs Resolved
Comment thread crates/quantumssh-core/src/exec.rs Resolved
Comment thread crates/quantumssh-core/src/channel.rs Resolved
Addresses claude-review's second-pass findings on PR #84:

- exec.rs: the reap now polls `try_wait` and kills through the owned
  `Child` handle (`Child::kill()`), never by raw pid. This removes the
  pid-reuse TOCTOU the previous `reaped`-flag fix still carried (a pid
  freed by `wait()` could be reused before the flag was set). Drops the
  `kill_process` use of rustix (getuid only now). ≤20 ms exit-detection
  latency, imperceptible since output already streamed.
- channel.rs: `exec.finished` now carries the structured `command` field
  (CLAUDE.md / ADR-0023 mandate the fields on *every* exec.* event); the
  driver stores the command string instead of a bare started latch.
- channel.rs: pre-exec stdin is no longer dropped beyond the pump's
  queue bound. `handoff_stdin` drains `pre_exec_stdin` under flow control
  and closes the child's stdin only once it (and any pending chunk) is
  delivered — so buffered stdin is never lost and its window credit is
  never leaked. EOF handling moved out of `on_channel_eof` accordingly.

Verified against OpenSSH 10.2p1: interop still green; exec.finished log
now includes `command`. 80 unit + 21 integration tests pass.

Claude-Session: https://claude.ai/code/session_01BRMdwxsqYQPbjrWB1Cek6o
Signed-off-by: Gonzalo Fleming <[email protected]>
@opencode-agent

Copy link
Copy Markdown

I've now traced the root cause of the failing test. Here is my review.


PR Review: feat(core): M5 — channel layer + single-command exec

Classification: REJECT (1 blocking finding)

Verification

Check Result
cargo fmt --check clean
cargo clippy -D warnings clean
unsafe in first-party code zero
Legacy crypto compiled in none
KEX: mlkem768x25519-sha256 only unchanged
Type-state: Session is stage 8 implements SealedRead/SealedWrite
Audit event fields PASS on exec.started and exec.finished
cargo test --workspace 1 FAILURE: client_early_close_kills_child

Blocking: orphaned grandchild blocks stdout/stderr pumps indefinitely, prevents close handshake

Test: client_early_close_kills_child (tests/accept.rs:889) — fails consistently with a 5-second timeout waiting for the server's CHANNEL_CLOSE.

Root cause: When the server spawns /bin/sh -c "sleep 30", dash forks a child to run sleep and waits. child.kill() sends SIGKILL to dash, which exits — but sleep is orphaned and continues running for 30 seconds holding the write ends of the stdout/stderr pipes open. The stdout/stderr pumps on the blocking thread pool remain blocked on read(), never drop their out_tx senders, so out_rx never closes (never returns None), child_out_closed never becomes true, ready_to_close() never returns true, and the server's CHANNEL_CLOSE is never sent. The un-timed channel phase hangs.

The Drop impl on ChildIo (exec.rs:80-88) sets the kill flag correctly, but reap_child calls child.kill() — which kills only the immediate child (dash), not its grandchildren. This is a general property of /bin/sh -c on any shell that forks for external commands (which is most shells by default).

Recommended fix: Use std::os::unix::process::CommandExt::process_group(0) to place the child in its own process group, and in reap_child kill the process group via rustix::process::kill_process_group instead of child.kill(). This is the approach the plan (docs/plans/m5-channels.md:130) originally described and the one that correctly bounds the kill to all descendants.

Steps:

  1. exec.rs: add cmd.process_group(0) via std::os::unix::process::CommandExt
  2. exec.rs: in reap_child, replace child.kill() with rustix::process::kill_process_group(Pid::from_raw(child.id() as i32).unwrap(), Signal::Kill) when the kill flag is set
  3. docs/adr/0016-*.md: update the erratum — rustix::process feature is needed for process-group kill, not optional

Pinned to: threat model §5.4 (session-layer vectors — resource exhaustion via orphaned processes), CLAUDE.md "No 'not implemented yet' left in a merged path" (the test fails, so the impl is incomplete), ADR-0023 §"Child-process lifecycle" ("No orphaned child survives its channel").


Non-blocking: dtolnay/rust-toolchain@stable mutable action ref

.github/workflows/interop.yml:59 — the stable branch tag floats, sidestepping the pinned rust-toolchain.toml. Same class as the now-fixed container tag. Not blocking for pre-alpha.


Previously-fixed findings confirmed resolved

Finding Status
debian:trixie-slim mutable tag → digest pin Fixed (interop.yml:36)
max_pkt == 0 stall Fixed (channel.rs:516-518)
ChildIo lacks Drop Fixed (exec.rs:80-88)
exec.finished missing command Fixed (channel.rs:430)
TOCTOU race on PID reuse Fixed (kill via owned Child handle, not raw PID)
Pre-exec stdin silently dropped Fixed (drained chunk-by-chunk under flow control, channel.rs:590-605)

Remaining MANIFIESTO/security checks: ALL PASS

github run

@claude

claude Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

CI on ubuntu caught client_early_close_kills_child hanging 30s: dash
(Linux /bin/sh) fork+execs its command, so SIGKILL to the shell leaves
the grandchild (e.g. `sleep`) running and holding the stdio pipes open
— the pumps never see EOF and the channel never closes. macOS /bin/sh
exec-replaces, so it passed there; the multi-OS matrix surfaced it.

Spawn the child in its own process group (`CommandExt::process_group(0)`,
making it the leader) and signal the whole group on kill via
`rustix::process::kill_process_group`. The kill is issued from the reap
task, which holds the un-waited Child, so the leader's pid (= pgid)
cannot have been reused — no pid-reuse race. Restores rustix's kill use
(getuid + kill_process_group); doc/comments updated.

Local: clippy clean, 21 integration tests pass, OpenSSH interop green.

Claude-Session: https://claude.ai/code/session_01BRMdwxsqYQPbjrWB1Cek6o
Signed-off-by: Gonzalo Fleming <[email protected]>
@opencode-agent

Copy link
Copy Markdown

All previous findings are verified against the current code. Here is my consolidated review.


PR Review: feat(core): M5 — channel layer + single-command exec

Classification: APPROVE — no blocking findings

Previous findings: all resolved

Finding Disposition Evidence
debian:trixie-slim mutable tag Fixed Pinned to debian@sha256:28de0877... (interop.yml:36)
max_pkt == 0 permanent stall Fixed Fail-closed disconnect at channel.rs:516-518
ChildIo lacks Drop Fixed Drop impl at exec.rs:80-88 sets kill flag
exec.finished missing command Fixed command = %command at channel.rs:432
TOCTOU race on PID reuse Fixed Kill via owned Child handle + process-group, never raw PID (exec.rs:232-250)
Pre-exec stdin silently dropped Fixed handoff_stdin drains deque under flow control, re-stashes on pump-full (channel.rs:344-367)
Orphaned grandchild blocks close Fixed process_group(0) + kill_process_group kills whole tree (exec.rs:144,238-242); client_early_close_kills_child passes

Remaining finding (non-blocking)

dtolnay/rust-toolchain@stable is a mutable action ref (.github/workflows/interop.yml:59). The stable tag floats to the latest Rust at runtime, sidestepping the pinned rust-toolchain.toml (MSRV 1.92). This is the same class of mutable-ref concern as the now-fixed container tag — the action that decides the compiler for the interop-gate binary should be pinned. Not blocking for a pre-alpha walking skeleton.

Verification

Check Result
cargo fmt --check clean
cargo clippy -D warnings clean
cargo test --workspace 21/21 passed (including client_early_close_kills_child, cancel_safety_under_load)
unsafe in first-party code zero (only doc-comment mention, lib.rs:8)
rustix licence in deny.toml Apache-2.0 WITH LLVM-exception allowed (line 23)
Legacy crypto compiled in none
KEX mlkem768x25519-sha256 only, unchanged

MANIFIESTO commitments: PASS all five

  1. Memory-safe — zero first-party unsafe; rustix wraps syscalls in safe abstractions
  2. Post-quantum — sole KEX unchanged; interop gate asserts it (run_openssh_client.sh:64-66)
  3. Zero legacy — no RSA/DSA/ECDSA-NIST/CBC/password/compression; all non-exec requests refused at channel.rs:557-565
  4. Small surface — rustix (process feature only) chosen over nix; one new dep, justified in PR body + ADR-0016 erratum
  5. Permanently open — rustix licences in deny.toml allowlist; no relicensing

Security rules: PASS

  • Pre-auth surface unchanged — M5 operates post-auth only
  • Fail closed — 12-arm total match in handle_inbound (channel.rs:454-473); EXTENDED_DATA inbound, data-after-EOF, window overflow, zero max_pkt, unknown channel → all disconnect
  • AEAD-only — no MAC path exercised
  • Type-state machine — Session is stage 8, implements SealedRead/SealedWrite, transitions via AuthAccepted::serve() (transport.rs:838-851); internal channel states are private enum
  • Cancel-safe read — read_packet stores partial progress in inbuf; fill_inbuf extends atomically; shares frame_body_len/open_frame helpers with read_sealed — one framing path (transport.rs:870-910)
  • Flow control is real — inbound window enforced (channel.rs:632-634), outbound u64 overflow detection (channel.rs:664), credit returned only as child consumes stdin
  • Child lifecycle — Drop guarantee + process-group kill (exec.rs:80-88, 238-242); exec.finished emitted exactly once on all paths (channel.rs:422-437)
  • Audit events — authenticated_identity, executing_uid, command (structured) on both exec.started (channel.rs:578-584) and exec.finished (channel.rs:428-435)

ADR amendments: SOUND

  • ADR-0016 (line 35): nix::Uid::current() → rustix::process::getuid() + kill_process_group; rationale documented; still Proposed, permitted per ADR-0015
  • ADR-0023 (line 38): /bin/sh -c erratum; bounded by service-account UID + sanitised env + one-channel/one-exec; still Proposed

github run

@gonzafg2

Copy link
Copy Markdown
Owner Author

All review findings addressed across commits 7ad0ca9, aea00b0, c4d4493 — resolving the threads:

Finding Fix
max_pkt == 0 stalls the channel (DoS) channel.rs: reject maximum_packet_size == 0 at channel open (zero_max_packet_is_rejected test).
ChildIo no Drop → orphaned child (DoS) exec.rs: Drop for ChildIo signals the reap to kill on any unwind.
TOCTOU: pid reuse after wait() exec.rs: reap polls try_wait and kills the child's process group from the reap while it still holds the un-waited Child — no kill-by-pid after wait, no reuse race.
exec.finished missing command channel.rs: driver stores the command; both exec.* events carry the structured command field (verified in the audit log).
Pre-exec stdin dropped beyond queue bound channel.rs: handoff_stdin drains pre_exec_stdin under flow control and closes stdin only once delivered — no loss, no leaked window credit.
Mutable container tag (ADR-0020) interop.yml: pinned to debian@sha256:28de08….

Bonus: the ubuntu CI matrix caught a process-group leak (dash fork+execs /bin/sh -c, so killing the shell orphaned the grandchild) — fixed in c4d4493 by killing the whole group. All checks green; OpenSSH 10.0p2 interop passes end-to-end.

@gonzafg2
gonzafg2 merged commit a96cdb7 into main Jun 26, 2026
11 checks passed
@gonzafg2
gonzafg2 deleted the feat/m5-channels-exec branch June 26, 2026 18:22
gonzafg2 added a commit that referenced this pull request Sep 22, 2026
…events; ADR-0020 and 0017 drafting-time sentences

ADR-0024's Related line and banner still grouped the subscriber
initialisation under M4/M5 after the Links line moved it to M0;
all three now agree (subscriber M0, events M4/M5, formatter #101).
ADR-0020's Consequences said the gate is wired up in the first-crate
PR; it was wired up in M5 (#84), once a connectable binary existed,
and the banner records the edit. ADR-0017's Context no longer calls
the workspace currently empty. Raised by Codex and opencode on #159.

Claude-Session: https://claude.ai/code/session_018UmL9wcgKBGFjdjGSSLafa
Signed-off-by: Gonzalo Fleming <[email protected]>
gonzafg2 added a commit that referenced this pull request Sep 23, 2026
…rom (ADR-0034)

Implements the package-version pin ADR-0020 decided and #84 left out.
The digest-pinned image (debian:trixie-20260623-slim) records in its
own debian.sources the snapshot.debian.org timestamp it was built
from; apt now reads from that timestamp, installs
openssh-client=1:10.0p1-7+deb13u4 with the build prerequisites, and
the job asserts the exact `ssh -V` string, OpenSSL build included.
The step checks that SNAPSHOT matches the image before apt runs.

#98 failed by pointing apt at a snapshot older than the image (its
libc6 was already newer than the archive). Reproduced locally in the
same image on 2026-09-22: the build timestamp installs with no libc6
change; later timestamps install the same package but move libc6 and
OpenSSL under it; earlier ones cannot resolve libc6-dev. Timestamp and
version pin together, and the timestamp is read from the image.

http rather than https because the slim image has no CA bundle and
apt verifies the Release signatures anyway; Check-Valid-Until off
because the archived trixie-updates/-security Release files are past
their validity window. ADR-0034 records the mechanism and the bump
procedure; ADR-0020's Status line points at it.

Claude-Session: https://claude.ai/code/session_018UmL9wcgKBGFjdjGSSLafa
Signed-off-by: Gonzalo Fleming <[email protected]>
gonzafg2 added a commit that referenced this pull request Nov 20, 2026
…atum

Two corrections from review.

- The row on password authentication cited `README.md`, which §1 does not
  list as a document a case may rest on. Threat model §5.3.1 states the
  behaviour, with RFC-0011. The row cites them.
- The ADR said ADR-0023 does not say which failure a forwarding channel
  gets while a session is open. It does: a non-`session` type gets
  "unknown channel type". The server checks for an open channel first and
  answers "administratively prohibited", and has since M5 (#84), which
  merged before ADR-0023 was accepted. That is a text that was wrong at
  acceptance, so §2 and §9 now send it to an erratum under ADR-0015
  instead of to a sentence in another document.

Refs #248

Signed-off-by: Gonzalo Fleming <[email protected]>
gonzafg2 added a commit that referenced this pull request Nov 21, 2026
…client (#289)

* docs(adr): ADR-0062, a conformance suite driven by the stock OpenSSH client

Phase 3 lists conformance tests against the OpenSSH client, and #248
gives the work an ADR that extends ADR-0020. This is it, as Proposed.

The interop gate makes 15 checks, each added by the ADR of a feature. No
rule says which behaviours get one, and nothing lists what is not
checked. The ADR decides how the gate grows into the suite:

- a behaviour belongs when a document states it and a stock client tool
  reaches it, refusals included;
- one case per behaviour, citing its document, and the document gets its
  sentence first when none states the behaviour;
- a catalogue file that the run enforces, so a dropped case fails;
- a refusal case asserts the refusal, and a case about which side acted
  reads it from the audit log;
- the same bash script, on the pinned client, with nothing added to the
  gate image, on every PR and on every release artifact.

A probe of 22 behaviours with OpenSSH 10.6p2 backs it. Nineteen behaved
as documented. Three are stated in no document, or not in full: the
server refuses ssh-keyscan, which negotiates no strict-kex; the size of
the authentication budget; and which failure a forwarding channel gets
while a session is open. The re-key after 1 GiB turned out to be started
by the client under ChaCha20, and by the server only under AES-GCM.

Nothing is implemented here.

Refs #248

Signed-off-by: Gonzalo Fleming <[email protected]>

* docs(adr): ADR-0062 cites the threat model, and ADR-0023 takes an erratum

Two corrections from review.

- The row on password authentication cited `README.md`, which §1 does not
  list as a document a case may rest on. Threat model §5.3.1 states the
  behaviour, with RFC-0011. The row cites them.
- The ADR said ADR-0023 does not say which failure a forwarding channel
  gets while a session is open. It does: a non-`session` type gets
  "unknown channel type". The server checks for an open channel first and
  answers "administratively prohibited", and has since M5 (#84), which
  merged before ADR-0023 was accepted. That is a text that was wrong at
  acceptance, so §2 and §9 now send it to an erratum under ADR-0015
  instead of to a sentence in another document.

Refs #248

Signed-off-by: Gonzalo Fleming <[email protected]>

---------

Signed-off-by: Gonzalo Fleming <[email protected]>
gonzafg2 added a commit that referenced this pull request Nov 21, 2026
* test(interop): the OpenSSH conformance suite, with a catalogue the run enforces

ADR-0062: the interop gate grows from 15 checks into 43 cases, one for
every behaviour that a document states and a stock OpenSSH client can
reach, refusals included.

- tests/interop/CASES.md is the catalogue: one line per case, the
  document it checks, and what a client may lack for it to skip.
- tests/interop/cases.sh holds the cases, one function each.
- run_openssh_client.sh is the driver. Before the first case it fails if
  a case has no line, a line has no case, or a line is repeated. After
  the last it fails unless every case reported ok, or a skip that both
  its line and INTEROP_ALLOW_SKIP allow. A run that stops early with
  status 0 fails too.
- negative_no_hybrid now asserts the client's "no matching key exchange
  method found", not only a non-zero exit.
- The server-initiated re-key runs under AES-GCM and reads `initiator`
  from the audit log: under ChaCha20 the client's own 1 GiB limit fires
  first.
- The client reads no ssh_config and no agent of the account that runs
  it. A developer's AddKeysToAgent otherwise left every run's throwaway
  keys in their agent, and the agent reordered the keys a client offers.
- The macOS release leg allows four skips: its client has no OpenSSL and
  no zlib, so no AES-GCM, no RSA or ECDSA, and no compression. Its
  no-fallback check now covers ssh-keyscan and ssh-agent, which the suite
  uses. The PR gate and the Linux release legs allow none.

Run locally: 43 of 43 in the gate image with OpenSSH_10.6p1 Debian-1 on
aarch64, five times, 11 to 14 s; 43 of 43 on macOS with 10.6p2, under
bash 5.3 and bash 3.2; 39 and 4 skipped with 10.6p1 built as the macOS
leg builds it.

Refs #248

Signed-off-by: Gonzalo Fleming <[email protected]>

* docs: what the conformance suite found, put right in the documents

The probe behind ADR-0062 found three behaviours that no document
stated, or stated differently from the server. ADR-0062 §2 puts the
document right before the case rests on it.

- docs/deployment.md §3: ssh-keyscan cannot fetch the host key. It does
  not negotiate strict-kex, so the server disconnects it with code 3
  before it sends one. The section says how to trust the key from its
  .pub line instead, and the case known_hosts_from_pub checks that way.
- Threat model §5.3.1: a connection has a budget of 12 authentication
  requests, and the twelfth ends it with code 11. It was in the code
  only.
- ADR-0023 takes an erratum (ADR-0015). Its table gave every non-session
  channel type code 3. Since M5 (#84), before the ADR was accepted, the
  server checks for an open channel first, so a forwarding channel
  opened during a session gets code 1. Both refuse it, and the decision
  does not change.

Refs #248

Signed-off-by: Gonzalo Fleming <[email protected]>

* docs(adr): ADR-0062 is Accepted with its implementation

- ADR-0062 is Accepted, dated with this PR. Its text records what the
  implementation found: the catalogue's place and form, the client run
  with no ssh_config and no agent, four skips on the macOS leg where the
  draft named two, the times measured, and that the pinned clients gave
  the probe's results. The interactive shell on a PTY, which the draft
  left open, has its case.
- The rule of §8 goes into CLAUDE.md, next to ADR-0060 §9's rule for
  fuzz targets, and into AGENTS.md's Code Review Rules.
- CLAUDE.md, AGENTS.md and docs/infrastructure.md describe the suite
  where they described the gate.
- The README's Phase 3 item on conformance tests is done.
- The changelog has the suite and the three documents it corrected.

Refs #248

Signed-off-by: Gonzalo Fleming <[email protected]>

* docs(adr): ADR-0062 records the suite's time on the PR runner

§6 said the implementing PR reports the step's time on the PR runner.
On x86_64 it took 17 seconds, up from 3, and passed all 43 cases with
none skipped (run 44864009111).

Refs #248

Signed-off-by: Gonzalo Fleming <[email protected]>

* test(interop): the certificate refusals assert their reason

openssh_cert_refusals passed whenever ssh exited non-zero, so a server
that was down, or any other failure, satisfied it. ADR-0062 §4 says a
refusal case asserts the refusal, and every other refusal case already
did.

Each of the three runs now shows that the client offered that
certificate (its ED25519-CERT offer in `ssh -v`) and was denied with
"Permission denied (publickey).".

Refs #248

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