Repository navigation
fix(channel): drop-guard so a panic cannot skip the exec.finished audit event - #124
Conversation
…it event ADR-0023 (Accepted) mandates that every path producing an exec.started produces an exec.finished, but the event was emitted only on the normal close path (Driver::emit_finished at the end of the drive loop) — a panic unwinding the connection task between the two events dropped the Driver without its terminal audit record, leaving exec.started unmatched in the trail. impl Drop for Driver now calls emit_finished as a backstop: a no-op on the normal path (already-emitted latch), and on unwind it emits the owed event with the conventional exit status the spawn-failure path already uses. It runs before the field drops, so the record precedes the child teardown ChildIo's own Drop triggers. This is also the mechanism ADR-0028 requires for the Phase-2 abort path, which will reuse it as-is. Tests capture audit events through a scoped thread-local subscriber (tracing dev-dependency gains the std feature — no new crate): panic after exec.started emits exactly one exec.finished; the normal path does not duplicate; no exec means no event. Claude-Session: https://claude.ai/code/session_01J2SZwLuDm1KjfYyPM8npTa Signed-off-by: Gonzalo Fleming <[email protected]>
|
Full test suite passes (92 unit + 30 integration = 122 passed). Clean. Review:
|
| Rule | Verdict |
|---|---|
No unsafe (CLAUDE.md #1, ADR-0018) |
Clean — Drop calls a safe &mut self method; tests use standard AssertUnwindSafe wrapping a fully-owned value |
| Audit fields mandated (CLAUDE.md audit rule, ADR-0024) | emit_finished() preserves authenticated_identity, executing_uid, command (structured), exit_status — the same fields the normal path emits |
| Emit-exactly-once (threat-model §2.7 integrity) | finished_emitted latch (line 551) gates the info! call; test #2 verifies no duplication after explicit-emit + drop |
| No new dependency (CLAUDE.md #4) | Only a std feature enable on the existing tracing dev-dependency — same pattern the binary crate already uses (quantumssh/Cargo.toml:26); zero new crates |
command as structured field (ADR-0024, threat-model §5.4.3) |
Uses %command (Display as field value), not string interpolation — unchanged from existing emit_finished(), not introduced by this PR |
| Threat-model §4.3 (key material never logged) | No key material touched — emit_finished() logs only audit metadata |
| Tests functional, not stub (CLAUDE.md "no placeholder code") | Three targeted unit tests with a scoped capture subscriber exercising panic-unwind, normal-then-drop, and no-exec paths |
No regressions
Dropis a leaf addition — no upstream code path modified, no protocol surface widened, no negotiation path touched.- The
finished_emittedflag (set before theinfo!call, line 553) prevents double-emission even if a subscriber panic were to unwind throughemit_finished(). cargo fmt,cargo clippy -- -D warnings,cargo test --workspace(122 passed),cargo build --release— all clean per the PR author's report and confirmed here.
There was a problem hiding this comment.
Pull request overview
This PR closes an audit-log gap in quantumssh-core’s channel driver by ensuring the terminal exec.finished audit event is emitted even if the connection task unwinds (panic) before the normal close path completes, preserving the ADR-0023 invariant that every exec.started has exactly one corresponding exec.finished.
Changes:
- Add a
Dropbackstop onDriverthat calls the existingemit_finished()(still emit-exactly-once via the existing latch). - Add unit tests that install a scoped
tracingsubscriber to countexec.finishedevents across unwind vs normal drop vs no-exec scenarios. - Enable
tracing’sstdfeature for dev builds to usetracing::subscriber::with_defaultin tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/quantumssh-core/src/channel.rs | Adds Drop-guard emission and unit tests to verify exec.finished is not skipped on unwind and not duplicated. |
| crates/quantumssh-core/Cargo.toml | Enables tracing std feature in dev-dependencies for scoped-subscriber-based tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
Review:
|
| Rule | Verdict |
|---|---|
No first-party unsafe |
Clean — Drop calls &mut self method; tests use AssertUnwindSafe wrapping a fully-owned value |
| Audit fields mandated (ADR-0024) | emit_finished() preserves authenticated_identity, executing_uid, command (structured %command), exit_status |
| Emit-exactly-once | finished_emitted set before info!() (line 553) — subscriber panic during emission won't cause duplicate on re-drop |
| No new dependency (manifest #4) | std feature on existing tracing dev-dependency only; zero new crates; matches the binary crate's own usage |
| Key material never logged (§4.3) | Untouched — emit_finished() logs only audit metadata |
| Tests functional, not stubs | Three targeted unit tests: unwind path, normal-then-drop no-duplicate, no-exec no-event |
| Pre-auth surface unchanged | Drop is a post-auth leaf addition |
| Transport type-state machine unchanged | No protocol surface touched |
Mechanics are sound:
command.clone()at line 550 is infallible (String::clone), so thefinished_emittedlatch at line 553 is reachable.- Drop order is correct:
Drop::dropruns before field destruction, so the audit event precedesChildIo's own teardownDrop. - The
with_defaultsubscriber guard wrapscatch_unwind, so it's still alive whendis dropped during unwind inside the catch.
2 changed files, 102 additions, 0 deletions. No regressions. No governance impact (plain PR, bug fix lane).
What
Closes the pre-existing audit gap surfaced by the ADR-0028 adversarial review (#123 discussion): a panic unwinding the connection task between
exec.startedandexec.finisheddropped theDriverwithout its terminal audit record, violating the ADR-0023 invariant — "every path that produced anexec.startedproduces anexec.finished".Lane: plain PR (bug fix). No new governance — ADR-0023 (Accepted) already mandates the invariant; the code just didn't honour it on unwind.
How
impl Drop for Drivercalls the existingemit_finished()as a backstop:finished_emittedlatch already guarantees emit-exactly-once.ChildIo's ownDroptriggers (the child was already correctly killed on unwind — only the log record was missing).Verification
Three unit tests with a scoped thread-local
tracingsubscriber capturing event messages:drop_emits_owed_exec_finished_on_unwind— panic afterexec.started→ exactly oneexec.finished.drop_after_normal_emission_does_not_duplicate— explicit emission + drop → still one.drop_without_exec_emits_nothing— no exec → no event.Dependency note: the
tracingdev-dependency gains thestdfeature (gatestracing::subscriber::with_default) — no new crate enters the tree.cargo denywas not run locally (not installed); the CI gate verifies it.Local validation: fmt, clippy
-D warnings, full test suite (122 passed), release build — all clean.Refs #109 (runtime workstream), follows the #123 review.
https://claude.ai/code/session_01J2SZwLuDm1KjfYyPM8npTa