Skip to content

docs(adr): draft ADR-0024 — Phase 1 structured-log event schema - #50

Merged
gonzafg2 merged 16 commits into
mainfrom
docs/adr-0024-log-event-schema
Jun 12, 2026
Merged

gonzafg2 merged 16 commits into
mainfrom
docs/adr-0024-log-event-schema

Conversation

@gonzafg2

Copy link
Copy Markdown
Owner

Summary

Adds ADR-0024, the fourth and last pre-coding ADR. It fixes the tracing event schema before any code, so the two fields threat-model §2.7 mandates — authenticated_identity and executing_uid — are guaranteed present and structurally separate from the first crate, rather than bolted on as ad-hoc strings later.

The schema

Nine events under a per-connection span carrying peer_addr:

Event Key fields
connection.accepted / closed (reason on close)
kex.completed kex_algorithm, host_key_algorithm
auth.succeeded / failed authenticated_identity / failure_count
exec.started / finished authenticated_identity + executing_uid + command / exit_status
server.started / config_error host_key_fingerprint / message

The load-bearing decisions

  1. authenticated_identity and executing_uid are separate first-class fields on every exec.* event. In Phase 1 they differ (a key fingerprint vs the service-account UID, §8.12). Keeping them separate is what makes the per-user-UID gap machine-readable — collapsing them would hide exactly what §2.7 exists to surface.
  2. command is a structured field, not interpolated into a message string — closes the §5.4.3 terminal-escape log-injection path and keeps logs JSON-shippable (§5.5.1).
  3. failure_count is per-source, not per-user — avoids the §5.3.1 user-enumeration oracle on a pubkey-only server.
  4. Library emits via the tracing facade only; the binary is the sole subscriber owner — keeps quantumssh-core embeddable (Phase 4 client, tests, downstream). --log-format json for the one-way sink.

schema_version is deferred to the Phase 2 freeze (§6.2); this ADR is its reviewed starting point.

Type of change

  • Documentation only

Checklist

  • Commits signed off under the DCO.
  • Conventional Commits.
  • Documentation updated (this ADR is the change).

Security considerations

This ADR is the audit-record decision (§2.7). It guarantees attributability (authenticated_identity on every exec), makes the §8.12 UID gap visible (executing_uid), resists log-injection (structured command, §5.4.3), avoids the enumeration oracle (per-source failure_count, §5.3.1), and supports the one-way-sink posture (--log-format json, §5.5.1).

Notes for reviewers

Fixes the tracing event schema before code, so threat-model §2.7's
mandated fields are guaranteed present and structurally separate from
the first crate. Nine events under a per-connection span carrying
peer_addr; authenticated_identity (OpenSSH SHA256: fingerprint) and
executing_uid as distinct first-class fields on every exec.* event, so
the §8.12 UID gap is machine-readable. command is a structured field
(not interpolated), closing the §5.4.3 terminal-escape log-injection
path; failure_count is per-source not per-user, avoiding the §5.3.1
enumeration oracle.

Library emits via the tracing facade only; the binary is the sole place
a subscriber is built (EnvFilter + optional --log-format json for the
§5.5.1 one-way sink). schema_version is deferred to the Phase 2 freeze
per §6.2. This is the fourth and last pre-coding ADR.

Signed-off-by: Gonzalo Fleming <[email protected]>
@gonzafg2 gonzafg2 added documentation Improvements or additions to documentation security Security-sensitive issue or change labels Jun 11, 2026
gonzafg2 added a commit that referenced this pull request Jun 11, 2026
The first real run of the project-aware reviewer (PR #50, Sonnet 4.6,
no 401) analysed the PR but posted nothing: 14 permission denials and
"No buffered inline comments". Root cause: the prompt told Claude to
post the review with gh, but claude-code-action restricts shell tools
and posts inline comments through its own native buffer
(post-buffered-inline-comments.ts) — gh attempts are denied.

Fix the prompt to leave inline review comments through the action's
native mechanism (which it buffers and posts automatically) and to stop
invoking gh/git. Keeps the summary + inline structure; only the posting
path changes.

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).
…to JSON

Review findings from #50, applied:

- New kex.failed event (WARN, reason + disconnect_code): the central
  security enforcement point (no-hybrid, no-strict-kex, marker
  negotiation, hybrid-half failure per ADR-0021) previously fired
  with no audit record at all.
- The audit tier (auth.*, exec.*, kex.failed) is emitted under a
  dedicated audit target and the binary's filter pins that target at
  its declared levels beneath whatever RUST_LOG says — RUST_LOG=warn
  can quiet noise but cannot silently discard the 2.7-mandated trail.
- The terminal-escape-immunity claim is scoped to the JSON pipeline:
  the human-readable formatter writes field values verbatim and is
  the development format; production shipping is JSON.

Signed-off-by: Gonzalo Fleming <[email protected]>
gonzafg2 added 2 commits June 11, 2026 21:04
…ntrol bytes on-TTY

Review findings from #50, applied:

- The 'floor directive' design was bypassable: EnvFilter resolves by
  specificity, so RUST_LOG=audit=off beats any floor and silently
  drops the mandated trail. The audit tier now flows through its own
  subscriber layer with a compiled-in filter that never consults the
  environment; RUST_LOG governs only the general layer.
- The 5.4.3 defence was absent in the default configuration. Format
  selection is now TTY-aware: JSON whenever stdout is not a TTY (log
  files and pipelines never see raw control bytes), human-readable on
  a TTY with a custom field formatter that escapes control bytes in
  string values — stock fmt() writes them verbatim, which is why the
  formatter is part of the decision.

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

Review finding from #50: threat-model 2.7 names stderr as the audit
sink, but the TTY detection keyed on stdout — under
'quantumssh 2> file' with an attached terminal the selector would
pick human format and ship it into the log file, defeating the JSON
guarantee. Decision: all log output (audit tier included) goes to
stderr, stdout is reserved and unused by logging, and the format
selector examines the stream it actually writes to.

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

Review finding from #50: the verbatim 'public interface from Phase 2'
wording lives in threat-model 5.5.1; 6.2 restates it as a mitigation
(schema-versioned, stable from Phase 2) and back-references 5.5.1.
Both citations (Context and Links) corrected.

Signed-off-by: Gonzalo Fleming <[email protected]>
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]>
@gonzafg2
gonzafg2 merged commit b3bfa78 into main Jun 12, 2026
9 checks passed
@claude

claude Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Code review

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

@gonzafg2
gonzafg2 deleted the docs/adr-0024-log-event-schema branch July 18, 2026 04:15
gonzafg2 added a commit that referenced this pull request Sep 22, 2026
…each edit touched

Claude checked the Links lines against the milestone PRs' file
lists and found four wrong attributions: server.rs (ADR-0016) and
everything ADR-0022 names landed in M0 (#62), not M5/M3;
transport.rs (ADR-0021) landed in M3 (#65), not M2; and
log_fields.rs (ADR-0024) came with #101 on 2026-07-06, after the
ADR's acceptance. All four corrected, with the banners' milestone
references.

Each banner now says which section the edit touched (Context in
0018/0019, Related in 0021/0023/0024, both in 0022) instead of the
same sentence everywhere. ADR-0020's Links line no longer carries a
note about the unimplemented package pin — that is decision-level
content and lives in ADR-0034 (#161). ADR-0023 no longer points at
"PR #50 in review" for the event schema, and ADR-0021 drops a "(TBD)"
next to the kex module.

docs/adr/README.md step 5 distinguishes the governance state from the
file's Status line and lists what actually happened (ADR-0027 merged
Accepted; 0028/0029 flipped in their implementing PRs; 0030-0032 in
#158) instead of calling one instance the practice.
docs/infrastructure.md says first-party unsafe would need a
superseding ADR, as ADR-0018 states, not an RFC. Findings by Claude
and opencode on #159.

Claude-Session: https://claude.ai/code/session_018UmL9wcgKBGFjdjGSSLafa
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

documentation Improvements or additions to documentation security Security-sensitive issue or change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant