Skip to content

docs(adr): ADR-0041 and ADR-0042 — SFTP v3 server details; exec.finished byte counts (Proposed) - #195

Merged
gonzafg2 merged 10 commits into
mainfrom
docs/adr-0041-0042-sftp
Oct 29, 2026
Merged

gonzafg2 merged 10 commits into
mainfrom
docs/adr-0041-0042-sftp

Conversation

@gonzafg2

@gonzafg2 gonzafg2 commented Oct 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

These are the implementing ADRs for RFC-0013 (SFTP). RFC-0013 was accepted with #194, and this PR targets main. Refs #109.

  • ADR-0041: the SFTP v3 server in the re-exec helper.
    • Request: subsystem "sftp" is honoured only in Idle, with no pending PTY, and with a helper configured. Other names are refused, and a malformed name disconnects.
    • Helper: --quantumssh-internal-sftp-server, dispatched in main right after the PTY helper. Config::pty_helper becomes Config::helper. The helper starts in $HOME, serves until EOF, exits 0 at EOF and 2 on a violation, and never writes to stderr.
    • Bounds: packets ≤ 256 KiB, READ ≤ 256 KiB − 1024, ≤ 100 names per READDIR, ≤ 256 open handles, and 4-byte handles. Malformed input ends the session. Every request gets exactly one response, and OP_UNSUPPORTED answers unknown requests.
    • Operations: std::fs, plus rustix::fs::utimensat for path times. OpenSSH's RENAME (no overwrite) and SYMLINK (reversed) semantics apply. Status messages are fixed, with no OS detail.
    • Extensions: posix-rename@, fsync@, limits@ (262144, 261120, 261120, 256) and expand-path@ (~ only).
    • Longname: numeric owners, UTC date.
    • Errata planned for the implementation PR: ADR-0038's "SFTP brings multiplexing", and ADR-0024's exec.finished row missing command.
  • ADR-0042: bytes_received and bytes_sent on exec.finished for every request type. The bytes are counted in the channel driver. This realises threat model §5.4.4's record.

Answers to RFC-0013's open questions

These are my proposed defaults; please push back:

  1. Extensions: only the four. statvfs@ and hardlink@ are left for later, because neither is needed by scp or by sftp's transfer and listing commands.
  2. Switch: no configuration key.
  3. Byte counts: on every exec.finished (ADR-0042).
  4. Handle cap: 256 (fixed, rather than RLIMIT_NOFILE).

Checklist

Notes for reviewers

  • Every protocol claim cites openssh-portable V_10_6_P1 or draft-ietf-secsh-filexfer-02, as in the RFC.
  • Both ADRs stay Proposed. They flip to Accepted in the implementation PR, after RFC-0013 is accepted (2026-10-26 at the earliest).

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

Update 2026-10-28: #194 merged, so RFC-0013 is accepted. The branch is rebuilt on main with signed commits, and it now targets main. It also carries the RFC-0013 Status flip to Accepted (2026-10-28), the follow-up step of docs/rfcs/README.md step 6, and updates ADR-0041/0042 Related lines from "Draft" to "Accepted". The ADRs stay Proposed until their implementing PR (#196).

@gonzafg2 gonzafg2 added the documentation Improvements or additions to documentation label Oct 13, 2026
@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-29T00:40:54.652161Z 2fb97f8 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

PR Review: ADR-0041 and ADR-0042 — SFTP v3 server details; exec.finished byte counts (Proposed) (#195)

Decision: 🟡 Minor changes
Iteration: First review (only a Codex "running" summary is present; no prior findings to reconcile)
Lenses applied: Design decision (docs/adr/0041, docs/adr/0042)

Executive summary

Two Proposed ADRs lock the SFTP v3 details (request handling, bounds, file ops, extensions) and add bytes_received/bytes_sent to every exec.finished. The design is consistent with RFC-0013, the five commitments and the threat model: no new dependency (rustix's fs feature is already enabled), no first-party unsafe, and no protocol or bound contradiction with the parent RFC. The one substantive issue is that ADR-0041 plans to add a new threat-model attack-vector entry outside the RFC lane; the rest is record-keeping hygiene.

New findings

🟡 Important (should be resolved)

docs/adr/0041-sftp-v3-server-in-a-re-exec-helper.md:205-206 — governance (confidence: 85)

Problem: §7 plans "a §5.4 entry for SFTP request handling" as part of the implementation PR. The threat model's maintenance rule states that additions to in-scope attack vectors (which §5.4 "Session and channel layer" is) "go through the RFC process", with only "typographical and factual corrections" landing as ordinary docs PRs. A post-authentication SFTP parser/handler vector is new — §5.1.2 is explicitly pre-auth, and §5.4.4 is exfiltration, not request handling — and RFC-0013 nowhere authorises such an entry. Landing it as an implementation-PR side effect inverts the RFC-first order the project has followed before (RFC-0002).
Fix: Either have RFC-0013 (still Draft) carry the new §5.4 attack-vector entry before acceptance, or reword §7 so the addition is unambiguously a factual update to the existing §5.4.4 record rather than a new vector.
Anchor: docs/threat-model.md:9-15 (maintenance rule); CLAUDE.md RFC-vs-ADR lane.

💡 Suggestions (nice to have)

  • docs/adr/0041:234: request_type gains a third value, broadening ADR-0038 §9's recorded set ("exec"/"shell"), yet §7's erratum list only covers ADR-0038's "multiplexing" sentence and ADR-0024's command field — the companion ADR-0042 does record a partial-supersession pointer for its own field addition. Add the same pointer for this value-set extension on acceptance. Anchor: ADR-0038 §9 precedent; ADR-0015 (decision broadening is supersession, only Status is editable).

Limitations

  • No Rust or CI change is in scope, so the hard security rules are assessed at the design level only; the implementing PR is where the parser/fuzzability and byte-count plumbing must be verified.
  • Commit-signature verification is not observable on the runner (gpg.ssh.allowedSignersFile unset); not reported.

github run

gonzafg2 added a commit that referenced this pull request Oct 13, 2026
A new in-scope attack vector goes through the RFC process (threat
model, Maintenance), so the §5.4.5 "SFTP request handling" entry is
part of this RFC and the implementation PR adds it verbatim. From
opencode's review of #195.

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 13, 2026
…pointer for request_type

- The threat model's new §5.4.5 entry now comes from RFC-0013 (RFC
  lane), and the implementation PR adds it verbatim; §5.4.4 gets only a
  factual pointer to ADR-0042.
- The implementation PR also records on ADR-0038's Status that this ADR
  extends §9's request_type values with "subsystem".

From opencode's review of #195.

Refs #109

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

Copy link
Copy Markdown
Owner Author

I addressed opencode's review:

  • Important (threat-model lane): the new §5.4.5 "SFTP request handling" entry now lives in RFC-0013 §6 (c636898, merged here in 9dc57bb), so it goes through the RFC process as the threat model's Maintenance rule requires. ADR-0041 §7 now only applies that entry verbatim and points §5.4.4 at ADR-0042, which is a factual update (fb532bd).
  • Suggestion (request_type value set): the implementation PR will add a pointer on ADR-0038's Status recording that ADR-0041 extends §9's values with "subsystem" (fb532bd).

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c07ed68ecd

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

@claude

claude Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

PR Review: docs(adr): ADR-0041 and ADR-0042 — SFTP v3 server details; exec.finished byte counts (Proposed) (#195)

Decision: 🟢 Approved
Iteration: Review #2 (1 resolved, 1 partly resolved)
Lenses applied: Design decision (docs/adr/0041, docs/adr/0042)

Executive summary

Two Proposed ADRs that lock the SFTP v3 operative details (ADR-0041) and add bytes_received/bytes_sent to exec.finished (ADR-0042), implementing RFC-0013. The design is sound against all five MANIFIESTO commitments and the threat model: no first-party unsafe, no new dependency, all attacker-controlled lengths are fixed-bounded, command is a structured literal, and the RFC-process governance constraint for the §5.4.5 threat-model entry is properly honoured. No new findings above the confidence threshold.

Previous issues

# Issue Status Notes
1 ADR-0041 §7 planned to add a §5.4 threat-model attack-vector entry without going through the RFC process ✅ Resolved §5.4.5 entry now lives in RFC-0013 §6 (9dc57bb); ADR-0041 §7 applies it verbatim
2 ADR-0038 §9 request_type value set extended by "subsystem" with no pointer back to ADR-0038 Status field 🔄 Partly resolved ADR-0041 §7 records that the implementation PR will add the pointer (fb532bd)

Limitations

@opencode-agent

Copy link
Copy Markdown

PR Review: ADR-0041 and ADR-0042 — SFTP v3 server details; exec.finished byte counts (Proposed) (#195)

Decision: 🟡 Minor changes
Iteration: Review #2 (2 resolved, 0 open)
Lenses applied: Design decision (docs/adr/0041, docs/adr/0042)

Executive summary

Two Proposed ADRs lock the SFTP v3 profile (request handling, bounds, file operations, extensions) and add bytes_received/bytes_sent to every exec.finished. Both are consistent with RFC-0013, the five commitments and the threat model: no new dependency, no first-party unsafe, no scope creep, and the new attack-vector entry now travels the RFC lane. The remaining issues are protocol-fidelity gaps in ADR-0041's operation table and one incomplete supersession pointer.

Previous issues

# Issue Status Notes
1 ADR-0041 §7 planned a new §5.4 attack-vector entry in the implementation PR instead of the RFC lane ✅ docs/rfcs/0013-sftp-subsystem.md:220-255 now carries the §5.4.5 entry; 0041:208-211 applies it verbatim. Threat-model "Maintenance" rule satisfied.
2 request_type value-set extension needed a pointer on ADR-0038's Status ✅ Recorded at 0041:196-199 (extends §9's values with "subsystem").

New findings

🟡 Important (should be resolved)

docs/adr/0041-sftp-v3-server-in-a-re-exec-helper.md:142 — protocol fidelity (confidence: 85)

Problem: The WRITE row specifies write_all_at(offset) and adds "With APPEND, the kernel appends." FileExt::write_all_at is pwrite(2). POSIX gives O_APPEND no effect on pwrite; Linux and FreeBSD deviate and do append, but macOS's XNU ignores O_APPEND for a positional write. An APPEND handle would therefore write at the request offset and corrupt the file on macOS — a required build/test target (ADR-0031). OpenSSH's own sftp-server.c uses a plain write() for APPEND handles, so the ADR diverges from the semantics it adopts.
Fix: Specify that an APPEND handle is written sequentially (write_all), reserving write_all_at for non-append handles, as OpenSSH's process_write does.
Anchor: RFC-0013 §4 "Open flags and create mode" (0013-sftp-subsystem.md:189-195); ADR-0031.

docs/adr/0041-sftp-v3-server-in-a-re-exec-helper.md:140 — protocol fidelity (confidence: 82)

Problem: CLOSE is specified as "Drops the handle." std::fs::File's Drop discards close(2) errors, so a deferred write/flush failure (NFS, quota, deferred write-back) reaches the client as SSH_FX_OK. draft-ietf-secsh-filexfer-02 §6.3 — the version-3 base RFC-0013 §3 adopts — explicitly anticipates that a close can fail, and OpenSSH's process_close maps the errno through errno_to_portable. The ADR pins every other operation's error behaviour yet leaves this one silently successful.
Fix: Close explicitly through a call that returns the errno (OwnedFd + rustix::io::close, consistent with the ADR's own use of rustix) or sync_all before drop, and map the failure through the §4 status table.
Anchor: RFC-0013 §3 "Responses" / §4 error mapping (0013-sftp-subsystem.md:154-159); draft-ietf-secsh-filexfer-02 §6.3.

docs/adr/0041-sftp-v3-server-in-a-re-exec-helper.md:196-199 — governance (confidence: 80)

Problem: §7's planned pointer on ADR-0038's Status field names only the §9 request_type extension, but ADR-0041 also reverses ADR-0038 §1, which still lists subsystem under "Still refused" (0038:150-153). The repo's own convention enumerates the superseded clauses in Status (ADR-0024's Status names the exec.* rows; ADR-0038 §9 names ADR-0024's), so a reader of ADR-0038 §1 would see the refusal un-flagged after this ADR is accepted.
Fix: Extend the planned Status pointer to name §1 (the refused→honoured reversal) alongside §9.
Anchor: docs/adr/README.md:83-86 (supersession is recorded in Status); ADR-0015:36 (decision changes need a superseding record); ADR-0038 §9 precedent.

💡 Suggestions (nice to have)

  • docs/adr/0041:148: The RENAME summary claims "OpenSSH's semantics" but omits two branches in the cited sftp-server.c:1274-1314 — the link()-failure fallback (EOPNOTSUPP/ENOSYS/EXDEV → existence check + rename) and the cleanup unlink of the spare destination link when unlink(oldpath) fails. Faithful fidelity would include both, or soften the claim. Anchor: RFC-0013 §4 (0013-sftp-subsystem.md:200-201).

github run

gonzafg2 added a commit that referenced this pull request Oct 13, 2026
…AME, ADR-0038 §1 pointer

From the reviews of #195 (Codex, claude-review, opencode), checked
against openssh-portable V_10_6_P1 and rustix 1.1.5:

- WRITE on an APPEND handle uses write_all, as OpenSSH skips lseek for
  O_APPEND; positional writes never carry APPEND, since pwrite ignores
  O_APPEND on macOS (POSIX).
- CLOSE syncs a written file with sync_data before dropping it and maps
  a failure, the only safe way to see a deferred write error: File's
  Drop ignores close errors and rustix's close is unsafe and returns
  nothing. The fdatasync per written file is a recorded cost.
- RENAME follows OpenSSH fully: the EOPNOTSUPP/ENOSYS/EXDEV fallback to
  check-then-rename, and removing the spare link when unlink fails.
- The planned ADR-0038 Status pointer names §1 (subsystem now honoured)
  as well as §9.

Refs #109

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

Copy link
Copy Markdown
Owner Author

I addressed opencode's second review in 995cb56. The two protocol-fidelity items (APPEND writes and CLOSE errors) and the RENAME suggestion are answered in their inline threads. The governance item is fixed too: the planned ADR-0038 Status pointer now names §1 (subsystem moves from refused to honoured) as well as §9.

@opencode-agent

Copy link
Copy Markdown

APIError: Insufficient Balance (request_id: 277a9d52-c520-41c7-ad62-eee1753326a5)

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]>
@gonzafg2

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 995cb56a7a

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

gonzafg2 added a commit that referenced this pull request Oct 17, 2026
… EPERM link fallback; no sync on special files

Codex on #195, each checked against openssh-portable V_10_6_P1:
- OPEN builds OpenSSH's flags_from_portable flags with rustix::fs::open:
  READ|APPEND stays read-only and READ|CREAT is valid, which OpenOptions
  cannot express;
- REALPATH follows OpenSSH's sftp-realpath.c, the final symlink included
  (32 links), so a dangling final symlink resolves to its target;
- expand-path takes ~ from the working directory ($HOME or /), as
  process_extended_expand uses getcwd;
- RENAME's link fallback also covers Linux EPERM (LINK_OPNOTSUPP_ERRNO);
- CLOSE syncs written regular files only: fdatasync fails with EINVAL on
  FIFOs, sockets and devices.

Refs #109

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

claude Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Code review

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

Scope: ADR-0041 (SFTP v3 server as re-exec helper) and ADR-0042 (exec.finished byte counts), commit `995cb56`.

Checked:

  • Five MANIFIESTO commitments (memory safety, post-quantum-by-default, zero legacy, small surface, permanently open)
  • Hard security rules (no first-party unsafe, fail-closed, attacker-controlled bounds, type-state machine integrity)
  • Threat model compliance (§5.4.4 byte counts, §5.4.5 SFTP attack-vector maintenance)
  • ADR governance conventions (Proposed status, errata routing, supersession pointers)
  • Conventional Commits format

All earlier findings from the previous Claude Code Review round have been addressed in the current revision.

gonzafg2 added a commit that referenced this pull request Oct 17, 2026
…ME; INIT, CLOSE, READDIR and stdin credit fixes

Codex on #195 and #196, each checked against openssh-portable V_10_6_P1:
- OPEN uses rustix::fs::open with flags_from_portable's flags:
  READ|CREAT creates a read-only handle, READ|APPEND grants no write;
- REALPATH ports sftp-realpath.c: every symlink is followed, the final
  one included (32 links), and only a missing last component is
  accepted, so a dangling final symlink resolves to its target;
- expand-path takes ~ from the working directory ($HOME or /) that the
  helper passes in, as OpenSSH's getcwd; relative REALPATHs use it too;
- RENAME's existence checks use symlink_metadata (a dangling symlink at
  the destination is never replaced) and the link fallback covers Linux
  EPERM (LINK_OPNOTSUPP_ERRNO);
- CLOSE syncs only written regular files (fdatasync fails with EINVAL on
  devices, FIFOs and sockets);
- INIT must carry its version; a truncated INIT ends the session;
- READDIR reads each entry's metadata through the open directory
  (DirEntry::metadata), not a rebuilt path;
- the longname uses the year for a future mtime (sftp-common.c rule),
  via a pure ls_date;
- pump_stdin credits each successful partial write, so a child that
  reads a prefix and exits is counted in bytes_received (ADR-0042).

Tests: init_without_a_version_ends_the_session,
open_maps_flags_independently, close_of_a_written_device_succeeds,
realpath_follows_symlinks_the_final_one_included, the extended
realpath_resolves_a_missing_last_component,
rename_does_not_replace_a_dangling_symlink, ls_dates_follow_openssh,
pump_stdin_credits_partial_writes (fails with the old write_all).
macOS and Linux (rust:1.99.0-bookworm) suites pass; local interop with
OpenSSH 10.3 passes openssh_sftp and openssh_scp.

Refs #109

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

claude Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

PR Review: docs(adr): ADR-0041 and ADR-0042 — SFTP v3 server details; exec.finished byte counts (Proposed) (#195)

Decision: 🟡 Minor changes
Iteration: Review #3 (3 resolved, 0 open)
Lenses applied: Design decision (docs/adr/0041, docs/adr/0042)

Executive summary

Two Proposed ADRs lock the SFTP v3 operative details (ADR-0041) and add bytes_received/bytes_sent to every exec.finished (ADR-0042). The design holds against all five MANIFIESTO commitments and the hard security rules. One internal inconsistency was found in ADR-0041's Alternatives section — the rationale for rejecting Alternative 1 contradicts the decision in §4.

Previous issues

# Issue Status Notes
1 opencode R1 — §5.4.5 threat-model entry must go through RFC process, not land as ADR side-effect ✅ Resolved Entry now lives in RFC-0013 §6 (9dc57bb)
2 opencode R1 — request_type broadening of ADR-0038 §9 needs a Status pointer ✅ Resolved ADR-0041 §7 now names §1 and §9 pointers on ADR-0038 (9dc57bb)
3 Codex (995cb56) — OPEN flag semantics, REALPATH final symlink, expand-path getcwd, RENAME EPERM, CLOSE on special files ✅ Resolved Commits 4115a55 / 84c3ab4 / 3b959df address all items

New findings

🟡 Important (should be resolved)

docs/adr/0041-sftp-v3-server-in-a-re-exec-helper.md:255–258 — internal inconsistency (confidence: 95)

Problem: Alternative 1's rationale contradicts the decision recorded in §4. The alternative says "std already covers OPEN, READ, WRITE, STAT, DIR and the rest safely … rustix is used only where std has no equivalent: utimensat on a path." But §4's OPEN row explicitly routes through rustix::fs::open because OpenOptions cannot express the required flag combinations (READ|APPEND must open read-only, READ|CREAT must be valid). The phrase "only … utimensat" drops the OPEN case from the rustix footprint that the same document describes, leaving the decision record internally inconsistent.

Fix: Remove OPEN from the list that std "already covers" in Alternative 1, and extend the "only where std has no equivalent" clause to include open with OpenSSH's flag mapping (READ|APPEND, READ|CREAT) alongside utimensat.

Anchor: CLAUDE.md — "review the soundness and coherence of the design DECISION."

gonzafg2 added a commit that referenced this pull request Oct 17, 2026
claude-review on #195: the rationale said rustix is used only for
utimensat, but §4 now also uses it for OPEN's flag mapping and for
SETSTAT's non-blocking size change on a path.

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 17, 2026
@opencode-agent

Copy link
Copy Markdown

APIError: Insufficient Balance (request_id: e08f70e0-9d4f-4415-80bf-acb31444bee8)

github run

Copilot AI balanced review requested due to automatic review settings October 28, 2026 20:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 2fd3cad7e6

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

@gonzafg2
gonzafg2 force-pushed the docs/rfc-0013-sftp-subsystem branch from 1d70b67 to 67f61d9 Compare October 29, 2026 00:27
gonzafg2 added a commit that referenced this pull request Oct 29, 2026
A new in-scope attack vector goes through the RFC process (threat
model, Maintenance), so the §5.4.5 "SFTP request handling" entry is
part of this RFC and the implementation PR adds it verbatim. From
opencode's review of #195.

Refs #109

Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW
Signed-off-by: Gonzalo Fleming <[email protected]>
@gonzafg2
gonzafg2 force-pushed the docs/rfc-0013-sftp-subsystem branch from 67f61d9 to dde1532 Compare October 29, 2026 00:32
gonzafg2 added a commit that referenced this pull request Oct 29, 2026
A new in-scope attack vector goes through the RFC process (threat
model, Maintenance), so the §5.4.5 "SFTP request handling" entry is
part of this RFC and the implementation PR adds it verbatim. From
opencode's review of #195.

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
…R-0038 pointer

From Claude's review of the final head:
- Once authorized_keys options are enforced, a restriction that limits
  shell and exec limits subsystem too.
- An unknown request type's id is the uint32 after the type byte, and a
  packet too short for one takes the framing rule's fail-closed path.
- The §5.4.5 assets line says QuantumSSH does not protect the service
  account's files from that account in Phase 2 (§8.12).
- §1 points at ADR-0041 (#195, TBD) for superseding ADR-0038 §1's
  subsystem refusal.

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
… helper (#194)

* docs(rfc): RFC-0013 — SFTP subsystem in a first-party SFTP v3 re-exec helper

Proposes serving `subsystem "sftp"` with QuantumSSH's own SFTP v3 server,
a single-threaded helper mode of the quantumssh binary started as an
ordinary pipe child, so it inherits ADR-0038's process supervision and
is the place Phase 3 drops privileges. It sets the protocol profile
(version 3, OpenSSH's 256 KiB bound, limits/posix-rename/fsync/
expand-path), the filesystem semantics as the service account, and the
audit record (request_type "subsystem", bytes per direction). It also
notes that SFTP needs no channel multiplexing: sftp and scp use one
session channel.

Alternatives weighed: OpenSSH's sftp-server (C, host-dependent),
russh-sftp (trust base, russh ecosystem), an in-process async server
(Phase-3 incompatible), and waiting for Phase 3.

Refs #109

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

* docs(rfc): RFC-0013 — the ADR-0038 multiplexing correction becomes an erratum

The implementing PR records the corrected "SFTP brings multiplexing"
statement as a post-acceptance erratum on ADR-0038 (ADR-0015), the
corpus's discoverability path. From opencode's review of #194.

Refs #109

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

* docs(rfc): RFC-0013 carries the threat model's new §5.4.5 SFTP entry

A new in-scope attack vector goes through the RFC process (threat
model, Maintenance), so the §5.4.5 "SFTP request handling" entry is
part of this RFC and the implementation PR adds it verbatim. From
opencode's review of #195.

Refs #109

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

* docs(rfc): RFC-0013 — exit 0 only at EOF on a packet boundary; a root-relative link in the §5.4.5 block

Codex on #194:
- the helper exits 0 only at EOF on a packet boundary; EOF inside a
  packet is truncated input and takes the framing rule's fail-closed path;
- the §5.4.5 block links RFC-0013 by a repository-root path, which
  resolves both here and once copied into docs/threat-model.md.

Refs #109

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

* docs(rfc): RFC-0013 — extensions at version "1"; an empty path is the working directory

The OpenSSH 10.6 client enables each extension only when its version
string is exactly "1" (sftp-client.c:499-536), so the table now says so.
SFTP v3 §6.2 makes an empty path the user's default directory; the helper
reads it as ".", except SYMLINK's target, which is link content.

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

* docs(rfc): RFC-0013 — per-key gating, request ids, assets wording, ADR-0038 pointer

From Claude's review of the final head:
- Once authorized_keys options are enforced, a restriction that limits
  shell and exec limits subsystem too.
- An unknown request type's id is the uint32 after the type byte, and a
  packet too short for one takes the framing rule's fail-closed path.
- The §5.4.5 assets line says QuantumSSH does not protect the service
  account's files from that account in Phase 2 (§8.12).
- §1 points at ADR-0041 (#195, TBD) for superseding ADR-0038 §1's
  subsystem refusal.

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

---------

Signed-off-by: Gonzalo Fleming <[email protected]>
…hed byte counts (Proposed)

Implementing ADRs for RFC-0013 (Draft, #194):

- ADR-0041 locks the SFTP server: the subsystem request rules, the
  helper dispatch and the Config::helper rename, OpenSSH's 256 KiB and
  read bounds, a 256-handle cap, exactly one response per request, the
  operation mapping on std::fs/rustix, OpenSSH's RENAME and SYMLINK
  semantics, the four advertised extensions, fixed status messages, and
  a numeric, UTC longname. It answers the RFC's open questions 1, 2 and 4.
- ADR-0042 adds bytes_received and bytes_sent to exec.finished for every
  request type, counted at the channel driver, realising threat model
  §5.4.4's record (the RFC's question 3).

Both stay Proposed until RFC-0013 is accepted and the implementation
lands.

Refs #109

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

- The threat model's new §5.4.5 entry now comes from RFC-0013 (RFC
  lane), and the implementation PR adds it verbatim; §5.4.4 gets only a
  factual pointer to ADR-0042.
- The implementation PR also records on ADR-0038's Status that this ADR
  extends §9's request_type values with "subsystem".

From opencode's review of #195.

Refs #109

Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW
Signed-off-by: Gonzalo Fleming <[email protected]>
…AME, ADR-0038 §1 pointer

From the reviews of #195 (Codex, claude-review, opencode), checked
against openssh-portable V_10_6_P1 and rustix 1.1.5:

- WRITE on an APPEND handle uses write_all, as OpenSSH skips lseek for
  O_APPEND; positional writes never carry APPEND, since pwrite ignores
  O_APPEND on macOS (POSIX).
- CLOSE syncs a written file with sync_data before dropping it and maps
  a failure, the only safe way to see a deferred write error: File's
  Drop ignores close errors and rustix's close is unsafe and returns
  nothing. The fdatasync per written file is a recorded cost.
- RENAME follows OpenSSH fully: the EOPNOTSUPP/ENOSYS/EXDEV fallback to
  check-then-rename, and removing the spare link when unlink fails.
- The planned ADR-0038 Status pointer names §1 (subsystem now honoured)
  as well as §9.

Refs #109

Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW
Signed-off-by: Gonzalo Fleming <[email protected]>
… EPERM link fallback; no sync on special files

Codex on #195, each checked against openssh-portable V_10_6_P1:
- OPEN builds OpenSSH's flags_from_portable flags with rustix::fs::open:
  READ|APPEND stays read-only and READ|CREAT is valid, which OpenOptions
  cannot express;
- REALPATH follows OpenSSH's sftp-realpath.c, the final symlink included
  (32 links), so a dangling final symlink resolves to its target;
- expand-path takes ~ from the working directory ($HOME or /), as
  process_extended_expand uses getcwd;
- RENAME's link fallback also covers Linux EPERM (LINK_OPNOTSUPP_ERRNO);
- CLOSE syncs written regular files only: fdatasync fails with EINVAL on
  FIFOs, sockets and devices.

Refs #109

Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW
Signed-off-by: Gonzalo Fleming <[email protected]>
…ks; future mtimes show the year

Codex on #196:
- every RENAME existence check uses symlink_metadata, so a dangling
  symlink at the destination is never replaced (stricter than OpenSSH's
  stat, in the direction of the no-overwrite invariant);
- the longname uses the time form only for an mtime in the six months
  up to now; a future mtime gets the year (OpenSSH's sftp-common.c rule).

Refs #109

Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW
Signed-off-by: Gonzalo Fleming <[email protected]>
…ize; READDIR errors and metadata

Second review round on #196:
- the handle cap is checked before the open: a refused OPEN has no side
  effect;
- SETSTAT's size on a path uses a write-only, non-blocking open and
  ftruncate, so a FIFO with no reader fails at once (OpenSSH: truncate(2));
- READDIR's metadata comes through the open directory without following
  symlinks; unreadable entries are skipped (as OpenSSH's failed lstat);
  a failed directory read is the reply's status, EOF only when exhausted.

Refs #109

Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW
Signed-off-by: Gonzalo Fleming <[email protected]>
Follows RFC-0013's clarification from Codex on #194; the implementation
already returns 2 for EOF inside a packet (read_packet).

Refs #109

Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW
Signed-off-by: Gonzalo Fleming <[email protected]>
claude-review on #195: the rationale said rustix is used only for
utimensat, but §4 now also uses it for OPEN's flag mapping and for
SETSTAT's non-blocking size change on a path.

Refs #109

Claude-Session: https://claude.ai/code/session_01HxXXh6HEpJBs7tbuz3NmtW
Signed-off-by: Gonzalo Fleming <[email protected]>
OpenSSH's sftp-server normalizes the empty path only in REALPATH and
expand-path; the helper does it for every path argument, as SFTP v3
§6.2 defines, except SYMLINK's target.

Claude-Session: https://claude.ai/code/session_01QpBZ4qUr3ypV22CvmVwwHp
Signed-off-by: Gonzalo Fleming <[email protected]>
#194 merged on 2026-10-28 (f2ce221). Per docs/rfcs/README.md step 6,
the merge is the acceptance, and the Status flips in a follow-up, as
#214 did for RFC-0012. ADR-0041's and ADR-0042's Related lines no longer
call it a Draft.

Claude-Session: https://claude.ai/code/session_01QpBZ4qUr3ypV22CvmVwwHp
Signed-off-by: Gonzalo Fleming <[email protected]>
@gonzafg2
gonzafg2 changed the base branch from docs/rfc-0013-sftp-subsystem to main October 29, 2026 00:39
@gonzafg2
gonzafg2 force-pushed the docs/adr-0041-0042-sftp branch from 2fd3cad to 2fb97f8 Compare October 29, 2026 00:39
@gonzafg2

Copy link
Copy Markdown
Owner Author

@codex review

@gonzafg2

Copy link
Copy Markdown
Owner Author

@claude review the rebuilt head 2fb97f8 (ADR-0041 and ADR-0042, Proposed; plus the RFC-0013 Status flip now that #194 merged). Earlier review rounds are on this PR; the ADR text is unchanged by the rebuild except the two Related lines.

@claude

claude Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @gonzafg2's task in 30s —— View job


Review of rebuilt head 2fb97f8

Decision: 🟢 No blocking issues.

Scope checked

  • The three changed files: ADR-0041, ADR-0042 and the RFC-0013 Status line.
  • The diff against the earlier head. The ADR text matches what earlier rounds reviewed. The only differences I found are the two Related lines, which now read "Accepted" for RFC-0013.
  • Whether the new status text agrees with what the repo says about RFC-0013 elsewhere.

Findings

Non-blocking notes

  • RFC-0013's "Unresolved questions" section still lists the four questions as open. Leave it. Accepted RFCs are not edited in place beyond Status, and ADR-0041 §6 and ADR-0042 record the answers.
  • The PR body's Summary still says the PR is "stacked on docs(rfc): RFC-0013 — SFTP subsystem in a first-party SFTP v3 re-exec helper #194". The update note at the bottom corrects this, so it is only worth a tidy-up before merge.

I changed no files and ran no tests, since the PR touches documentation only.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 2fb97f81d1

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

@gonzafg2
gonzafg2 merged commit b218e08 into main Oct 29, 2026
11 checks passed
gonzafg2 added a commit that referenced this pull request Oct 29, 2026
…ME; INIT, CLOSE, READDIR and stdin credit fixes

Codex on #195 and #196, each checked against openssh-portable V_10_6_P1:
- OPEN uses rustix::fs::open with flags_from_portable's flags:
  READ|CREAT creates a read-only handle, READ|APPEND grants no write;
- REALPATH ports sftp-realpath.c: every symlink is followed, the final
  one included (32 links), and only a missing last component is
  accepted, so a dangling final symlink resolves to its target;
- expand-path takes ~ from the working directory ($HOME or /) that the
  helper passes in, as OpenSSH's getcwd; relative REALPATHs use it too;
- RENAME's existence checks use symlink_metadata (a dangling symlink at
  the destination is never replaced) and the link fallback covers Linux
  EPERM (LINK_OPNOTSUPP_ERRNO);
- CLOSE syncs only written regular files (fdatasync fails with EINVAL on
  devices, FIFOs and sockets);
- INIT must carry its version; a truncated INIT ends the session;
- READDIR reads each entry's metadata through the open directory
  (DirEntry::metadata), not a rebuilt path;
- the longname uses the year for a future mtime (sftp-common.c rule),
  via a pure ls_date;
- pump_stdin credits each successful partial write, so a child that
  reads a prefix and exits is counted in bytes_received (ADR-0042).

Tests: init_without_a_version_ends_the_session,
open_maps_flags_independently, close_of_a_written_device_succeeds,
realpath_follows_symlinks_the_final_one_included, the extended
realpath_resolves_a_missing_last_component,
rename_does_not_replace_a_dangling_symlink, ls_dates_follow_openssh,
pump_stdin_credits_partial_writes (fails with the old write_all).
macOS and Linux (rust:1.99.0-bookworm) suites pass; local interop with
OpenSSH 10.3 passes openssh_sftp and openssh_scp.

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
gonzafg2 added a commit that referenced this pull request Oct 29, 2026
… counts (ADR-0041, ADR-0042) (#196)

* feat(sftp): SFTP v3 subsystem in a re-exec helper; exec.finished byte counts (ADR-0041, ADR-0042)

Implements RFC-0013 through ADR-0041 and ADR-0042:

- sftp.rs: a first-party SFTP version 3 server, run by the binary's
  --quantumssh-internal-sftp-server helper mode (dispatched in main
  after the PTY helper). Single-threaded and synchronous over fds 0/1,
  starting in $HOME. OpenSSH's 256 KiB packet bound and read clamp, a
  256-handle cap, exactly one response per request, fail-closed on
  malformed input (exit 2), fixed STATUS messages. Operations on
  std::fs plus rustix::fs::utimensat; APPEND writes are sequential,
  CLOSE syncs written files to surface deferred errors, RENAME and
  SYMLINK follow OpenSSH. Extensions: posix-rename, fsync, limits,
  expand-path (~ only). Longnames carry numeric owners and UTC dates.
- channel.rs: `subsystem "sftp"` is honoured in Idle with no pending PTY
  and a helper configured; the child is the ordinary pipe child
  (exec::spawn_sftp). exec.* carry request_type "subsystem" and command
  "sftp". exec.finished gains bytes_received and bytes_sent for every
  request type, counted at the driver.
- server::Config::pty_helper is renamed Config::helper: one binary
  hosts both helpers.
- Tests: sftp.rs unit tests; a core test for the no-helper refusal;
  binary-crate tests that re-exec the real binary for a 100 KB
  round trip and the refusals; sftp -b and scp both ways in the OpenSSH
  interop gate.

Refs #109

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

* docs(adr): accept ADR-0041 and ADR-0042 with the SFTP implementation; errata and threat model §5.4.5

- ADR-0041 and ADR-0042 flip to Accepted with this implementing PR, on
  RFC-0013's acceptance (2026-10-26; adjust if merged another day).
- ADR-0038's Status records the partial supersession of §1 (subsystem
  now honoured) and §9 (request_type "subsystem"); an erratum corrects
  "SFTP brings multiplexing".
- ADR-0024's Status adds ADR-0042's fields; an erratum adds `command`
  to the exec.finished row, which the code emitted at acceptance
  (a3921d5).
- The threat model gains RFC-0013's §5.4.5 entry verbatim, and §5.4.4
  names the byte counts as its record.
- CHANGELOG, README and CLAUDE.md list SFTP as landed.

Refs #109

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

* fix(sftp): OpenSSH's OPEN flags, realpath and expand-path; safer RENAME; INIT, CLOSE, READDIR and stdin credit fixes

Codex on #195 and #196, each checked against openssh-portable V_10_6_P1:
- OPEN uses rustix::fs::open with flags_from_portable's flags:
  READ|CREAT creates a read-only handle, READ|APPEND grants no write;
- REALPATH ports sftp-realpath.c: every symlink is followed, the final
  one included (32 links), and only a missing last component is
  accepted, so a dangling final symlink resolves to its target;
- expand-path takes ~ from the working directory ($HOME or /) that the
  helper passes in, as OpenSSH's getcwd; relative REALPATHs use it too;
- RENAME's existence checks use symlink_metadata (a dangling symlink at
  the destination is never replaced) and the link fallback covers Linux
  EPERM (LINK_OPNOTSUPP_ERRNO);
- CLOSE syncs only written regular files (fdatasync fails with EINVAL on
  devices, FIFOs and sockets);
- INIT must carry its version; a truncated INIT ends the session;
- READDIR reads each entry's metadata through the open directory
  (DirEntry::metadata), not a rebuilt path;
- the longname uses the year for a future mtime (sftp-common.c rule),
  via a pure ls_date;
- pump_stdin credits each successful partial write, so a child that
  reads a prefix and exits is counted in bytes_received (ADR-0042).

Tests: init_without_a_version_ends_the_session,
open_maps_flags_independently, close_of_a_written_device_succeeds,
realpath_follows_symlinks_the_final_one_included, the extended
realpath_resolves_a_missing_last_component,
rename_does_not_replace_a_dangling_symlink, ls_dates_follow_openssh,
pump_stdin_credits_partial_writes (fails with the old write_all).
macOS and Linux (rust:1.99.0-bookworm) suites pass; local interop with
OpenSSH 10.3 passes openssh_sftp and openssh_scp.

Refs #109

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

* fix(sftp): no side effect from a refused OPEN; non-blocking SETSTAT size; partial-write latch; READDIR errors; drain stdin credits

Second review round on #196 (Codex and claude-review):
- the handle cap is checked before the open, so an OPEN refused at the
  cap has not created or truncated the file (claude-review);
- SETSTAT's size opens the path write-only and non-blocking, then
  ftruncate: a FIFO with no reader fails at once instead of hanging the
  single-threaded helper, matching OpenSSH's truncate(2) (claude-review);
- WRITE sets the handle's written latch as soon as any byte reaches the
  file, so CLOSE syncs after a write that failed part-way (Codex);
- a failed directory read is reported as the READDIR status, after any
  names already gathered, instead of looking like EOF (Codex);
- exec.finished drains the stdin credits still queued when the channel
  closes, so bytes the child received are counted (Codex, ADR-0042).

Tests: a_refused_open_leaves_the_file_untouched,
setstat_size_on_a_fifo_does_not_block. macOS and Linux suites pass;
local interop with OpenSSH 10.3 passes openssh_sftp and openssh_scp.

Refs #109

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

* docs(threat-model): §5.4.5 links RFC-0013 by its repository-root path, verbatim from the RFC

RFC-0013 now carries the root-relative link (Codex on #194); the entry
stays a verbatim copy.

Refs #109

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

* docs(sftp): the module doc names every rustix use

Matches ADR-0041 Alternative 1 (claude-review on #195).

Refs #109

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

* fix(sftp): an empty path names the working directory

SFTP v3 (draft-ietf-secsh-filexfer-02 §6.2) defines an empty path as the
user's default directory, but path arguments went to std::fs unchanged,
so STAT, OPENDIR and the other path requests answered NO_SUCH_FILE for
"". path_arg now reads it as ".". SYMLINK's target is link content and
stays as sent.

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

* fix(sftp): ~//x in expand-path stays under the working directory

PathBuf::join drops the base when the suffix is absolute, so ~//upload
resolved to /upload. The helper now concatenates the working directory,
a slash and the suffix, as OpenSSH's "%s/%s" does
(sftp-server.c:1569-1572), and REALPATH collapses the repeated slash.

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

* docs(threat-model): §5.4.5 assets line, verbatim from RFC-0013 7358c0f

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

* docs(adr): ADR-0041 and ADR-0042 dates follow RFC-0013's acceptance (2026-10-28)

#194 merged on 2026-10-28, not on the 2026-10-26 the drafts assumed.

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

* ci: re-run the required checks against the main base

The rebuilt branch was pushed while the PR still targeted the ADR
branch, so the main-only workflows did not run on 967a073.

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

* fix(sftp): REALPATH reads components through a cursor, not drain

left.drain(..=i) shifted the rest of the buffer for every component, so
a 256 KiB path of ./ cost quadratic time: about 280 ms against 8 ms with
the cursor on a debug build. A test pins a packet-sized path.

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

* docs(sftp): FIFO OPEN blocks as in OpenSSH; parsers vs handlers in §5.4.5

ADR-0041 §4 says that opening a FIFO with no peer blocks the helper, as
it blocks OpenSSH's sftp-server, and that closing the channel kills the
process group. Threat model §5.4.5 no longer calls the whole parser a
pure function: the framing and field parsers are, and the handlers act
on the filesystem, so the Phase-3 harness drives them in a scratch
directory. RFC-0013, now accepted, keeps its original wording.

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

---------

Signed-off-by: Gonzalo Fleming <[email protected]>
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
…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 docs/adr-0041-0042-sftp 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

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants