Skip to content

fix(logging): audit events carry the connection span's peer_addr (ADR-0024) - #202

Merged
gonzafg2 merged 1 commit into
mainfrom
fix/audit-events-peer-addr
Oct 28, 2026
Merged

gonzafg2 merged 1 commit into
mainfrom
fix/audit-events-peer-addr

Conversation

@gonzafg2

Copy link
Copy Markdown
Owner

Summary

Audit events now carry the connection's peer_addr, as ADR-0024 states ("every event below inherits peer_addr from its span"). Before, auth.failed, auth.succeeded, exec.*, kex.failed and rekey.completed were written with no span at all, so an authentication failure could not be tied to the address it came from.

I found this while inventorying the log schema for the 0.1.0 freeze (ADR-0044, next).

Motivation

This is a bug fix in the plain-PR lane, because ADR-0024 already decides the behaviour. The cause is a per-layer filter. The audit layer's filter_fn admitted only metadata whose target is audit. A filtered layer never sees what it filters out, and that included the connection span (target quantumssh_core::server), so the layer had no span context for its events.

Before, from a real ssh session:

{"timestamp":"…","level":"WARN","fields":{"message":"auth.failed","auth_method":"none","failure_count":1},"target":"audit"}

After:

{"timestamp":"…","level":"WARN","fields":{"message":"auth.failed","auth_method":"none","failure_count":1},"target":"audit","span":{"peer_addr":"127.0.0.1:56456","name":"connection"},"spans":[…]}

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that changes existing behaviour)
  • Documentation only
  • Refactor / chore / CI / build

Changes

  • crates/quantumssh/src/main.rs:
    • The audit layer's filter is now meta.is_span() || meta.target() == "audit". The layer sees every span and still prints only audit events. RUST_LOG still cannot reach it.
    • init_logging builds through subscriber(format, filter, writer), and fmt_layer takes the writer, so a test can capture the output. The binary passes std::io::stderr, as before.
  • CHANGELOG.md: a Fixed entry.

Checklist

  • My commits are signed off under the Developer Certificate of Origin (git commit -s).
  • My commit messages follow Conventional Commits.
  • I have run cargo fmt --all and cargo clippy --workspace --all-targets -- -D warnings locally.
  • I have added or updated tests where appropriate.
  • I have updated documentation (rustdoc, docs/, or README.md) where appropriate.
  • I have added a CHANGELOG.md entry under ## [Unreleased] if this change is user-visible.
  • If this change introduces a new dependency, I have justified it in the PR description and verified it passes cargo deny check. (No new dependency.)

Security considerations

  • Restores the source address on the audit trail. Threat model §2.7 says the audit record is how an operator attributes authentication outcomes and command execution, and §5.3.1 calls failure_count per-source, which means nothing without the source.
  • No new data is logged beyond peer_addr. The span carries only that field.

Tests

  • main.rs audit_events_carry_the_connection_span: an audit event inside a connection span, through the binary's real subscriber, under the RUST_LOG-style filters info and off. The JSON line must carry "peer_addr". With the old filter it fails: "audit line without peer_addr".
  • End to end with OpenSSH 10.3: the audit lines of a real session now carry peer_addr.
  • macOS: clippy is clean, and all workspace tests pass.

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) and build (macos-latest) — fmt, clippy, tests, release build —, cargo deny, openssh-interop; cargo audit runs weekly, not per PR) and manual review when needed.

https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW

…-0024)

ADR-0024: every event inherits peer_addr from its `connection` span. The
audit layer's per-layer filter admitted only `audit`-target metadata, so
it never saw the `connection` span (target quantumssh_core::server):
auth.*, exec.*, kex.failed and rekey.completed were written without
`span`/`peer_addr` — an auth.failed could not be tied to its source.

The audit filter now also admits spans; the layer still prints only
audit events. The subscriber is built by `subscriber(format, filter,
writer)` so a test can capture its output.

Test: audit_events_carry_the_connection_span, under RUST_LOG-style
"info" and "off"; it fails with the old filter. Checked end to end with
OpenSSH: the audit lines now carry "peer_addr".

Found while inventorying the schema for the 0.1.0 freeze.

Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW
Signed-off-by: Gonzalo Fleming <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T06:22:45.338995Z 9f75f86 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@opencode-agent

Copy link
Copy Markdown

APIError: Insufficient Balance (request_id: bc6f1175-b3f1-4ca3-8714-1f1dc103a9e8)

github run

@claude

claude Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Code review

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

@gonzafg2
gonzafg2 merged commit 13cc0ee into main Oct 28, 2026
10 of 11 checks passed
gonzafg2 added a commit that referenced this pull request Oct 29, 2026
…roject-owned JSON envelope (Proposed)

The first item of the 0.1.0 freeze checklist. The JSON log becomes a
project-owned, versioned contract:

- envelope: one flat object per line — schema_version (1), timestamp,
  level, event (catalogue) or message (diagnostics), peer_addr, then the
  event's fields; no target, span name or span list; a FormatEvent in
  the binary encoding with serde_json (already in the build);
- the version-1 catalogue: ADR-0024's events plus rekey.completed,
  connection.refused and ADR-0038's fields, all on the non-suppressible
  audit tier (six events move there);
- server.config_error's `message` field becomes `error` (today it
  duplicates the JSON key that holds the event name);
- compatibility: additive changes (new event, field or open-enumeration
  value) keep version 1; anything else bumps it with an ADR and a
  CHANGELOG migration note.

The inventory also found audit events without peer_addr — fixed in #202.

Refs #109

Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW
Signed-off-by: Gonzalo Fleming <[email protected]>
gonzafg2 added a commit that referenced this pull request Oct 29, 2026
… up to date

#196 landed the SFTP stack before the freeze, so request_type subsystem
and exec.finished's bytes_received and bytes_sent move from the planned
additive changes into the version-1 catalogue (§3, §4), with command
"sftp" for the subsystem. RFC-0012 is cited as accepted, the two audit
gaps as fixed (#202, #204), and ADR-0024's command erratum as landed
with #196.

Claude-Session: https://claude.ai/code/session_01QpBZ4qUr3ypV22CvmVwwHp
Signed-off-by: Gonzalo Fleming <[email protected]>
gonzafg2 added a commit that referenced this pull request Oct 29, 2026
…sioned JSON contract (#203)

* docs(adr): ADR-0044 — freeze the audit-log schema as version 1 in a project-owned JSON envelope (Proposed)

The first item of the 0.1.0 freeze checklist. The JSON log becomes a
project-owned, versioned contract:

- envelope: one flat object per line — schema_version (1), timestamp,
  level, event (catalogue) or message (diagnostics), peer_addr, then the
  event's fields; no target, span name or span list; a FormatEvent in
  the binary encoding with serde_json (already in the build);
- the version-1 catalogue: ADR-0024's events plus rekey.completed,
  connection.refused and ADR-0038's fields, all on the non-suppressible
  audit tier (six events move there);
- server.config_error's `message` field becomes `error` (today it
  duplicates the JSON key that holds the event name);
- compatibility: additive changes (new event, field or open-enumeration
  value) keep version 1; anything else bumps it with an ADR and a
  CHANGELOG migration note.

The inventory also found audit events without peer_addr — fixed in #202.

Refs #109

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

* docs(rfc): RFC-0014 — audit-log schema version 1 (was ADR-0044; RFC lane per review)

Codex on #203: the frozen audit log is a new public compatibility
contract, an RFC under CLAUDE.md; and the freeze refines two accepted
RFCs (RFC-0010's error classes, RFC-0008's authenticated_identity), which
an ADR cannot. ADR-0044 becomes RFC-0014 (Draft, 14-day window).

Review findings folded in:
- server.config_error splits into `class` (RFC-0010's four classes plus
  the startup ones) and `error`, keeping RFC-0010's stable classes
  machine-readable (Codex);
- successful configuration load is recorded: server.started gains
  config_file, server.config_override joins the catalogue (Codex, §2.7);
- connection.refused keeps `limit`, superseding ADR-0028's `reason`
  explicitly (Codex);
- RFC-0008: authenticated_identity stays the proven key's fingerprint;
  certificate fields arrive additively, conditional on certificate
  authentication (Codex);
- exec.finished's `command` listed as a change against ADR-0024
  (claude-review);
- every failed attempt, the budget-exhausting one included, emits
  auth.failed — fixed in #204 (claude-review);
- failure_count is per connection; aggregate by IP (claude-review);
- all enumerations are open; changing an event's level is breaking
  (claude-review);
- the SFTP additions cite #194/#195 as proposed, not as existing ADRs
  (both reviewers).

Refs #109

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

* docs(rfc): RFC-0014 — config_file on server.config_error too

Codex on #203: a startup failure after a successful config load (host
key, authorized_keys, runtime, bind) returns before server.started, so
the error record could not name the configuration that produced it.
config_file is now on every server.config_error as well (the canonical
path once resolved, the path as given if that failed, "" without
--config), so each error record stands on its own.

Refs #109

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

* docs(rfc): RFC-0014 — no edits to accepted RFCs; fingerprint and override-key formats

Codex on #203:
- accepted RFCs are not edited in place (docs/rfcs/README.md, "After
  acceptance"): only ADR-0024 and ADR-0028 gain Status pointers;
  RFC-0010 and RFC-0008 keep their text and this RFC states what it
  supersedes;
- host_key_fingerprint's representation is frozen: `SHA256:` + unpadded
  standard base64 of SHA-256 over the public-key blob (OpenSSH's format);
- server.config_override's `key` values are the TOML paths
  (server.listen, server.host_key, auth.authorized_keys,
  server.handshake_timeout, logging.format); new keys use the same form.

Refs #109

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

* docs(rfc): RFC-0014 — a superseding ADR, not Status pointers, changes ADR-0024/0028/0029

docs/adr/README.md allows an accepted ADR to change only through a
superseding ADR, so the implementing PR adds one that supersedes the
listed parts of ADR-0024, ADR-0028 and ADR-0029, as ADR-0031 does for
ADR-0008. ADR-0029's info-level override diagnostic and RFC-0010's
"no new audit event names" clause join §6, since server.config_override
changes both. RFC-0012 is cited as proposed (#172, TBD).

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

* docs(rfc): RFC-0014 — SFTP's fields are version 1; references brought up to date

#196 landed the SFTP stack before the freeze, so request_type subsystem
and exec.finished's bytes_received and bytes_sent move from the planned
additive changes into the version-1 catalogue (§3, §4), with command
"sftp" for the subsystem. RFC-0012 is cited as accepted, the two audit
gaps as fixed (#202, #204), and ADR-0024's command erratum as landed
with #196.

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

* docs(rfc): RFC-0014 — pin kex.failed's reason tokens; summary count; SFTP wording

kex.failed's reason was "no-hybrid-kex, no-strict-kex, …". §4 now lists
the eleven tokens the transport emits with disconnect code 3 and keeps
the enumeration open, as for the override keys. The Summary counts five
documents, not three decisions, and the SFTP note moves out of the
planned-change list.

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

* docs(rfc): RFC-0014 — exit_status sentinels, full control-character escape, threat-model qualifiers

From claude-review on 4a9b58f:
- §4 pins exit_status: the exit code, 128 + n for a signal (also with
  exit-signal on the wire), and 127 when the child could not be started
  or waited on or no status was recorded.
- §2 and §7: the JSON encoder escapes every char::is_control character
  (C0, DEL, C1) as \u00XX, the set the human formatter escapes;
  serde_json alone covers only C0.
- Three threat-model citations (§2.7, §8.12) carry the qualifier.

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

---------

Signed-off-by: Gonzalo Fleming <[email protected]>
@gonzafg2
gonzafg2 deleted the fix/audit-events-peer-addr branch December 1, 2026 20:13
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