Repository navigation
feat(keygen): quantumssh keygen <PATH> — RFC-0018 / ADR-0058 - #252
Conversation
…5519 host key RFC-0018 and ADR-0058. A server host no longer needs OpenSSH 10.6 to create its own host key. - Core: `host_key::generate_host_key()` makes one 68-byte draw from getrandom (the seeds, then the check word) and encodes the openssh-key-v1 container in OpenSSH's layout: empty comment, padding 1, 2, 3, ... to a multiple of 8, 70-column PEM. Every buffer that holds the seeds is Zeroizing and sized exactly, through the new `Writer::with_capacity`, so none reallocates. An RNG error returns `RngError` before any byte is used. - Binary: `keygen.rs` canonicalizes the parent, opens it O_DIRECTORY | O_NOFOLLOW, applies ADR-0029's ancestor predicate through the descriptor and to every directory above it, then creates both files with openat at 0600 and 0644 (O_EXCL | O_NOFOLLOW), runs fchmod, generates, writes and fsyncs. A failure removes only the files this run created, through the directory descriptor. - CLI: `keygen` is recognized only as the first argument, followed by exactly one non-flag path, and is dispatched before any configuration, logging or runtime setup. `--help` lists it. - Tests: core unit tests for the round trip, padding, comment, draw layout and RNG failure; binary integration tests for success, a bare file name, umask 077, every refusal and every usage error; an in-process test with a failing generator. - Interop gate: a new step stops the first server, checks that `ssh-keygen -y` reproduces the .pub byte for byte and `ssh-keygen -lf` the printed fingerprint, then starts a second server with the key and checks the client sees that fingerprint. - Docs: deployment.md step 3 uses `quantumssh keygen`, and ssh-keygen 10.6 stays documented as an alternative; CHANGELOG entry; ADR-0058 wording on the predicate's visibility matches the code (clippy's redundant_pub_crate requires `pub` inside the private module). No dependency is added. Refs #248 Claude-Session: https://claude.ai/code/session_01QpBZ4pLj7mjenN8SXpJehu Signed-off-by: Gonzalo Fleming <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Refs #248 Claude-Session: https://claude.ai/code/session_01QpBZ4pLj7mjenN8SXpJehu Signed-off-by: Gonzalo Fleming <[email protected]>
|
@codex review |
|
/oc |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
1 similar comment
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
PR Review: feat(keygen):
|
Answers opencode on #252. Both tree() helpers left target/ and the shared test base with the process umask. Under umask 002 they are 0775, and keygen's ancestor check refuses them, so the success-path tests failed on a fresh run. The helpers now drop the group and world write bits from those directories, as the interop script does for target/. Reproduced by making target/ and the bases group-writable: 6 of 10 integration tests failed before, all pass after. Refs #248 Claude-Session: https://claude.ai/code/session_01QpBZ4pLj7mjenN8SXpJehu Signed-off-by: Gonzalo Fleming <[email protected]>
|
Answer to the opencode review (🟡 Minor changes, first iteration):
The optional test of a success case under The older |
|
@codex review |
|
/oc |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
PR Review: feat(keygen):
|
| # | Issue | Status | Notes |
|---|---|---|---|
| 1 | Both tree() helpers left target/ and the shared test base at the process umask, so under umask 002 the ancestor check refused the success-path tests |
✅ | Fixed in 1d2197e: both helpers now clear group/world write bits on target/ and the base (tests/keygen.rs:19-31, src/keygen.rs:255-269). Verified statically against the current code. |
New findings
🟡 Important (should be resolved)
docs/deployment.md:81-82 — documentation / host-key rotation (confidence: 84)
Problem: The new rotation sentence says only "move the old one aside", but
keygenopens both<PATH>and<PATH>.pubwithO_EXCL(src/keygen.rs:141-142, :192-200). An operator who moves only the private key aside leaves the old.puband the next run fails withhk.pub: already exists— the exact case proven by tests/keygen.rs:153-159. The sentence also never says to destroy the old private key once the new fingerprint is published, which is the point of rotating after a suspected compromise.Fix:
- It never replaces a file, so rotation is manual: move **both** `<PATH>` and `<PATH>.pub` aside (or delete them), run `quantumssh keygen` again, `chown` the key, publish the new fingerprint, and restart. After clients have verified the new fingerprint, destroy the old private key; keep it only as an access-controlled rollback copy if you need one.Anchor: threat model §5.5.3 ("Operators must have a documented rotation procedure"); RFC-0018 §3/Guide ("If either file exists, it exits non-zero"); ADR-0058 §3 steps 4-5 (the
.pubisO_EXCLtoo and an operator's existing.pubis deliberately left alone).
💡 Suggestions
- tests/interop/run_openssh_client.sh:216:
KG_PORT=$((PORT + 1))does unvalidated bash arithmetic on the documentedQUANTUMSSH_PORToverride.QUANTUMSSH_PORT=08aborts the script as invalid octal, and65535yields65536, whichSocketAddrrejects, so the gate waits outwait_listeningand fails. Normalise once after line 19 (PORT=$((10#$PORT))after a^[0-9]+$check, bound1..65534) or let the second server bind port 0. Anchor: the script's line 15/19 env contract; ADR-0058 §4's$PORT + 1step.
opencode v2.2.3 · opencode-go/deepseek-v4.1-flash · github run
…port arithmetic in base 10 Answers opencode review #2 on #252. keygen refuses an existing .pub as well as an existing key, so the rotation step now moves both aside, repeats the chown, publishes the new fingerprint and destroys the old private key once clients have the new one. KG_PORT is computed in base 10, so a QUANTUMSSH_PORT with a leading zero is not read as octal. Refs #248 Claude-Session: https://claude.ai/code/session_01QpBZ4pLj7mjenN8SXpJehu Signed-off-by: Gonzalo Fleming <[email protected]>
|
Answer to opencode review #2 (🟡 Minor changes):
The gate passes again locally after the change ( |
|
@codex review |
|
/oc |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
PR Review: feat(keygen):
|
| # | Issue | Status | Notes |
|---|---|---|---|
| 1 | Both tree() helpers left target/ and the shared test bases at the process umask, so under umask 002 the ancestor check refused the success-path tests |
✅ | Fixed in 1d2197ee6125e4c7ce50cc931457167b5631088c; both helpers now clear group/world write bits on target/ and the base (tests/keygen.rs:19-31, src/keygen.rs:255-269). |
| 2 | Rotation guidance moved only the key aside, but keygen also refuses an existing .pub; it never said to destroy the old key |
✅ | Fixed in b1f39c06f8307b81ee67f1ed936582931cc82e16; the bullet now moves both files, repeats the chown, publishes the new fingerprint, and destroys the old private key (docs/deployment.md:81-84). |
| 3 | KG_PORT=$((PORT + 1)) read a leading-zero QUANTUMSSH_PORT as octal and aborted the script |
✅ | Fixed in b1f39c06f8307b81ee67f1ed936582931cc82e16 with $((10#$PORT + 1)) (run_openssh_client.sh:216); the 65535 edge remains, but it fails loudly and is not the reported defect. |
New findings
🟡 Important (should be resolved)
docs/deployment.md:81-84 — operational rotation guidance (confidence: 83)
Problem: The new rotation bullet tells the operator to move both key files aside, run
keygenand thechown, publish the new fingerprint and restart, then destroy the old private key. It never tells clients to remove the old host-key entry fromknown_hosts. With OpenSSH's default host-key checking, the client aborts withREMOTE HOST IDENTIFICATION HAS CHANGED/Host key verification failed; publishing the new fingerprint does not clear the stale same-type entry. An operator following the guide will strand existing clients, and the obvious workaround (StrictHostKeyChecking=no) weakens the check the guide relies on. The guide already documents the requiredssh-keygen -Rstep for the Ed25519 → composite cutover at lines 200-206, but that paragraph is scoped to the algorithm switch, not to a later same-algorithm rotation.Fix: Add the client-side step to the rotation bullet, e.g. after "publish the new fingerprint and restart": have clients run
ssh-keygen -R <host>— orssh-keygen -R '[<host>]:2222'for another port — and verify the published fingerprint on first connection before the old private key is destroyed. Cross-reference the existing client-side paragraph atdocs/deployment.md:200-206.Anchor:
docs/threat-model.md§5.5.3 ("Operators must have a documented rotation procedure"); RFC-0012 "What changes for an existing test deployment"; the guide's own client-side procedure atdocs/deployment.md:200-206.
opencode v2.2.3 · opencode-go/deepseek-v4.1-flash · github run
…entry Answers opencode review #3 on #252. After a rotation, OpenSSH's default host-key checking refuses the host until the client removes the old entry, so the rotation step now points at step 5's ssh-keygen -R and asks clients to check the new fingerprint. Refs #248 Signed-off-by: Gonzalo Fleming <[email protected]>
|
Answer to opencode review #3 (🟡 Minor changes):
|
|
@codex review |
|
/oc |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
PR Review: feat(keygen): quantumssh keygen <PATH> — RFC-0018 / ADR-0058 (#252)Decision: 🟢 Approved Executive summaryThis PR adds a The latest commit ( Previous issuesThe two prior Claude reviews raised no findings. New findingsNo findings at or above the 80-confidence threshold. No Decision: 🟢 Approved |
Summary
This implements RFC-0018 as ADR-0058 decides. It is milestone M3 of
docs/plans/alpha-distribution.md.quantumssh keygen <PATH>writes a newssh-mldsa44-ed25519host key and its.pub, so a server host no longer needs OpenSSH 10.6 to create its own host key.Core encoder (ADR-0058 §2).
host_key::generate_host_key()makes one 68-byte draw fromgetrandom: the seeds, then the check word. It encodes theopenssh-key-v1container in OpenSSH's layout: an empty comment, padding1, 2, 3, …to a multiple of 8, and 70-column PEM with padded base64.Zeroizingand sized exactly through a newWriter::with_capacity. None of them reallocates, so no unerased copy is left behind.debug_asserts check the sizes in tests.RngErrorbefore any byte is used.server.starteduses.File writer (ADR-0058 §3,
crates/quantumssh/src/keygen.rs).O_DIRECTORY|O_NOFOLLOW.openatat0600and0644(O_EXCL|O_NOFOLLOW), runsfchmod, generates the key, writes andfsyncs.CLI (ADR-0058 §1).
keygenis recognized only as the first argument, followed by exactly one path that is not a flag. Any other shape isusage: quantumssh keygen <PATH>. It is dispatched before any configuration, logging or runtime setup, and--helpgains aSUBCOMMANDS:section.Interop gate (ADR-0058 §4). A new step stops the first server and runs
keygen. It then checks:ssh-keygen -yreproduces the.pubbyte for byte;ssh-keygen -lfprints the fingerprintkeygenprinted;$PORT + 1is reached by the stock client, which sees that same fingerprint (Server host key: …).The rest of the gate keeps its
ssh-keygenhost key, so both directions stay covered.Docs (RFC-0018 §9). Step 3 of
docs/deployment.mdnow usesquantumssh keygen, andssh-keygen10.6 stays documented as an alternative. There is a CHANGELOGAddedentry, and the--host-keyhelp names both tools.ADR-0058. Its Status is now Accepted, with this PR. One wording change matches the code: the predicate and its
mode_ofhelper arepubinside the privateconfigmodule, because clippy'sredundant_pub_crate(nursery,-D warnings) rejectspub(crate)there. The visibility is the same.No dependency is added, and
Cargo.lockis unchanged.Refs #248
Test plan
cargo fmt --all --check,cargo clippy --workspace --all-targets -- -D warningscargo test --workspace: 331 tests, including the new ones:HostKey::from_openssh_pem,pad_to_blockfor every residue, the draw layout, the empty comment, the padding bytes, and a failing RNG;splitand a failing generator, which leaves no file and says no key was written;tests/keygen.rs): success with modes0600/0644, a bare file name,umask 077, an existing key, an existing.pubonly (the operator's file is left as it was), a symlink leaf, a parent symlinked to a0777directory, a group-writable ancestor, every usage-error shape, and the help text.cargo build --workspace --releasetests/interop/run_openssh_client.shon macOS arm64 with the OpenSSH 10.6p1 client from Homebrew:INTEROP PASS, includingkeygen_read_by_ssh_keygenandkeygen_host_key_servesopenssh-interopCI gate in the pinned Debian forky container (10.6p1)https://claude.ai/code/session_01QpBZ4pLj7mjenN8SXpJehu