Skip to content

fix(auth): audit the failure that exhausts the attempt budget (ADR-0024) - #204

Merged
gonzafg2 merged 2 commits into
mainfrom
fix/auth-failed-at-limit
Oct 28, 2026
Merged

gonzafg2 merged 2 commits into
mainfrom
fix/auth-failed-at-limit

Conversation

@gonzafg2

Copy link
Copy Markdown
Owner

Summary

The authentication request that exhausts the attempt budget now emits auth.failed, like every other failure, before the disconnect. Before, the twelfth failure, which is the one that ends the connection, left no audit record. All it produced was the general-tier post-kex protocol violation diagnostic, which RUST_LOG can suppress.

claude-review found this while reviewing the audit-schema freeze (#203).

Motivation

This is a bug fix in the plain-PR lane: ADR-0024 audits every failed attempt (auth.failed, with failure_count per connection).

Expect::authenticate has four failure branches. Each one checked attempts >= MAX_AUTH_ATTEMPTS and disconnected before its warn!(target: "audit", …, "auth.failed"). The probe path checked the budget before it even looked the key up. A brute-force connection therefore logged at most eleven auth.failed records, and the attempt that triggered the lockout, the strongest signal, was missing.

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

  • transport.rs:
    • On every failure path, auth.failed is emitted before the budget check.
    • On the probe path, the key is looked up first. An unknown-key probe is counted and audited before the budget check, and a known-key probe still spends an attempt without being a failure.
    • The doc comment states the invariant.
  • tests/accept.rs: the max-attempts test is now a helper, exhaust_auth_attempts(signed), with two tests, one for signed requests and one for unsigned probes. A capturing subscriber records every auth.failed, and the tests expect failure_count 1 to 12 before the disconnect.
  • 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

  • No change to the wire. Replies, the attempt budget and the disconnect code are unchanged. Only the audit emission moves before the budget check.
  • No new oracle. The key lookup on the probe path now runs before the budget check, but it is local, and the reply sequence a peer sees is the same.
  • Threat model §2.7 and §5.3.1. The lockout attempt is now on the non-suppressible audit trail.

Tests

  • max_auth_attempts_disconnects (signed requests) and max_auth_attempts_by_unknown_key_probes_disconnects (unsigned probes): twelve failures, failure_count 1 to 12, then SSH_DISCONNECT_BY_APPLICATION. With main's transport.rs, both fail with left: [1, …, 11].
  • 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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 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-28T20:41:25.384188Z 445e354 Manual request
ℹ️ 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: b11f2979-806e-4af8-9b09-553ba5ae5682)

github run

gonzafg2 added a commit that referenced this pull request Oct 14, 2026
…ane 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]>
@claude

claude Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

PR Review: fix(auth): audit the failure that exhausts the attempt budget (ADR-0024) (#204)

Decision: 🟢 Approved
Iteration: First review (Codex completed with no findings; opencode did not run)
Lenses applied: Rust under crates/quantumssh-core/, CHANGELOG.md

Executive summary

This fix correctly moves the auth.failed audit emit before the MAX_AUTH_ATTEMPTS budget check on all five failure branches in Expect::authenticate, ensuring the lockout-triggering attempt is always recorded on the non-suppressible audit trail. The type-state machine is unchanged, no unsafe is introduced, no key material appears in log fields, and all auth.failed events carry exactly the auth_method + failure_count fields mandated by ADR-0024. The two new tests prove the fix with a custom tracing::Subscriber that asserts all 12 events (failure_count 1–12) arrive before the SSH_DISCONNECT_BY_APPLICATION.

No findings reached the reporting threshold (≥ 80).

@gonzafg2
gonzafg2 force-pushed the fix/auth-failed-at-limit branch from 9d87c46 to 445e354 Compare October 28, 2026 20:39
@opencode-agent

Copy link
Copy Markdown

APIError: Insufficient Balance (request_id: 1ba3a5a3-f3ff-499b-81ce-dc442466a591)

github run

@gonzafg2

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 445e35432d

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@opencode-agent

Copy link
Copy Markdown

APIError: Insufficient Balance (request_id: 55745b3e-c322-425c-b8af-de9eab390922)

github run

Every failure branch of Expect::authenticate checked
`attempts >= MAX_AUTH_ATTEMPTS` and disconnected before emitting
auth.failed, and the probe path checked the budget before looking the
key up. The twelfth failure — the one that ends the connection — left no
audit record, only the general-tier "post-kex protocol violation" line,
which RUST_LOG can suppress. ADR-0024 audits every failed attempt.

auth.failed is now emitted before the budget check on every failure
path, and an unknown-key probe is counted and audited before it.

Tests: the max-attempts test now captures the audit events and expects
failure_count 1..=12, for signed requests and for unsigned probes; both
fail on main (1..=11).

Found by claude-review on #203 (the audit-schema freeze).

Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW
Signed-off-by: Gonzalo Fleming <[email protected]>
@gonzafg2
gonzafg2 force-pushed the fix/auth-failed-at-limit branch from 8e4ef13 to 23b92b8 Compare October 28, 2026 22:55
@opencode-agent

Copy link
Copy Markdown

APIError: Insufficient Balance (request_id: 03ab284e-b0c8-442a-9b09-4538ce66a709)

github run

@gonzafg2
gonzafg2 merged commit 1fea031 into main Oct 28, 2026
10 of 11 checks passed
gonzafg2 added a commit that referenced this pull request Oct 29, 2026
…ane 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]>
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/auth-failed-at-limit 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