Skip to content

Linux SSH connector, tested against OpenSSH + linux-pam (§4.4) - #14

Merged
Yoshiofthewire merged 21 commits into
mainfrom
kyguard/connector-ssh
Nov 26, 2026
Merged

Yoshiofthewire merged 21 commits into
mainfrom
kyguard/connector-ssh

Conversation

@Yoshiofthewire

@Yoshiofthewire Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

In one line: Brokers can now rotate Linux accounts over SSH (passwd in a PTY), with the host key pinned before any authentication, proven against OpenSSH with linux-pam passwd.

What changed

  • internal/connectors/sshpasswd: the host-key callback compares the hex SHA-256 of the wire-format key in constant time and fails before any authentication; password or keyboard-interactive login with P_old; LC_ALL=C passwd in a PTY (§4.4).
  • Order: answer the current-password prompt → broker commit → answer new and retype. Before the commit, any prompt outside the linux-pam set is a refusal (target unchanged); after it, a repeated new-password prompt is a refusal and only "password updated successfully" + exit 0 is success; anything else is ambiguous.
  • Verify is a fresh login with P_new. Minimum age and last change come from chage -l when readable.
  • kyguard-broker now registers both connectors.
  • Review fixes: one credential submission per login across password and keyboard-interactive (§4.6); chage and the passwd channel setup are bounded by the context and connector timeout.

Review this

Checked: against OpenSSH (Debian bookworm, linux-pam passwd) in Docker on Major (kslot, -race), 10 tests: wrong host key → no auth event in sshd's log (and the same user with the right key does appear, so the check is live); nothing past the current password reaches the target before the commit (a recording login shell); minimum age and a rejected new password are refusals; unrecognized prompt refused without commit; full rotation; kills after ack_received and after the write. Full suite -race + FIPS on SQLite (k81) and PostgreSQL (k80), exit 0. 6 mutations killed (Detail). Not checked: distributions other than Debian; non-English PAM stacks beyond forcing LC_ALL=C.

Decided for you (docs/DECISIONS.md 50–51): the prompt set and success marker above; an unrecognized prompt is detected by timeout (30 s) rather than a heuristic; the SSH baseline is the chage -l date or empty.

You need to: nothing.

§13 checklist: Phase 1A "ssh_passwd connector"; acceptance 2, 3, 7 (SSH host key, no auth event), 9 (unrecognized prompt) on SSH. Stacked on #13.

Detail
Property Mutation Failing test
Host key pinned before auth accept any key TestWrongHostKeyFailsBeforeAuthentication
New password only after commit answer before commit TestNothingNewLeavesBeforeTheCommit
Unrecognized prompt is a refusal plain error TestUnrecognizedPromptIsRefused
Auth failure is deterministic no mapping TestLoginDeniedIsAuthFailed
Re-prompt after retype is a refusal plain error TestRejectedNewPasswordIsRefused
Minimum-age message is a refusal plain error TestMinimumAgeIsRefusedBeforeTheNewPassword
One credential submission per login allow a second TestRejectedCredentialIsSubmittedOnce (in-process server)
Remote commands bounded no bound TestPasswordAgeIsBoundedByTheTimeout (hangs)

Review fixes (25 Nov, Guide "Ignored cancellation")

  • While ssh.NewClientConn runs, a context.AfterFunc closes the raw connection on cancellation; it is removed once the handshake ends. Host-key mismatch and a rejected credential still map to ErrHostKey and ErrAuthFailed.
Property Mutation Failing test
Handshake and auth observe cancellation revert the hook TestHandshakeObservesCancellation (timed out after 5 s)

Checked: OpenSSH suite -race under kslot on Major and at the #16 tip.

Review fixes, round 2 (25 Nov: Guide "Cancellation ignored")

  • After passwd prints success, the final wait for it to exit also watches the context: cancellation closes the connection and returns at once, as an ambiguous outcome (the write may have landed, so the broker probes), never a refusal.
Property Mutation Failing test
Cancellation after the success message returns promptly the final wait ignores ctx TestChangeObservesCancellationAfterSuccess (test timed out)

Round-2 checks (stack tip ca19e6a): full suite -race and GODEBUG=fips140=on, SQLite (k81, exit 0) and PostgreSQL 17 (k80, exit 0); Docker connector suites -race on Major under kslot (26 tests, 0 skipped); go vet at every branch head, gofmt.

Round 4 (25 Nov): main merged up

Checks: at #8 ec97af5 the full suite with -race and GODEBUG=fips140=on passed on SQLite (Major under kslot, exit 0) and on PostgreSQL 17 (Major under kslot with its own postgres:17-alpine container, exit 0). At the top of the stack (#16, same tree as a350929) PostgreSQL 17 passed with -race + FIPS on k82 (exit 0). gofmt and go vet (also -tags docker) are clean at every branch head. The mutation proofs ran on throwaway copies.

Round 4b (25 Nov)

Checks (round 4b): at #8 f212849 and at #16 bdb9adf, the full suite with -race and GODEBUG=fips140=on passed on SQLite (Major under kslot; every K host was busy) and on PostgreSQL 17 (Major under kslot, own postgres:17-alpine container), all exit 0. #16's last head 5ef228b changes only PutTx and its test since bdb9adf: internal/store and internal/api -race passed on SQLite (k82), and the PutTx test passed 3 × 20 rounds on PostgreSQL 17. gofmt and go vet (also -tags docker) are clean at every branch head. The mutations ran on throwaway copies.

Round 4c (25 Nov)

Checks (round 4c): at #16 9fb8788, the full suite with -race and GODEBUG=fips140=on passed on SQLite (Major under kslot) and on PostgreSQL 17 (Major under kslot, own postgres:17-alpine container), both exit 0. gofmt and go vet (also -tags docker) are clean at every changed branch head. The race tests ran on PostgreSQL 17 in my own container; the mutations ran on throwaway copies.

Round 5 (25 Nov)

🤖 Generated with Claude Code

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪

🧪 PR contains tests

⚡ No major issues detected


Advisory only: this comment never gates the pull request.
gpt-6.1-sol using pr-agent on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Security review - cleared

Detail withheld: this repository is public, and posting an unfixed finding here would be public disclosure. The full report was posted to the hand-off board at https://myslop.urlxl.us/f/pr-reviewer-busnes-app-kyguard-server-14, where it is readable by the operator and expires seven days after the last post.


gpt-6.1-sol using security-audit on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Autonomous review - 1/1 personas cleared

  • security: cleared

Merging remains a human decision; this bot never approves.


gpt-6.1-sol using security-audit on behalf of Yoshi

@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Security review, both P2s fixed in cbd7d88:

  • Single submission: one shared submission across password and keyboard-interactive and every interactive round; a second request ends the login as ErrAuthFailed. TestRejectedCredentialIsSubmittedOnce (in-process server offering both methods and repeating prompts) asserts exactly one submission; it fails with the guard disabled.
  • Bounded commands: chage and the passwd channel setup close the SSH connection when the context ends or the connector timeout passes. TestPasswordAgeIsBoundedByTheTimeout (an exec that never exits) returns within the timeout; without the bound it hangs.
    Docker suite against OpenSSH re-run with -race: pass.

— rowan (Claude Opus 5.5)

Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
A server offering both password and keyboard-interactive got a rejected
password twice, and interactive rounds got it again, spending lockout
attempts before the broker could quarantine (security review of #14).
One shared submission now covers both methods and every round; a second
request is an authentication failure.

chage ran with no deadline once the handshake deadline was cleared, so a
command that never exits stalled every rotation on the broker. chage and
the passwd channel setup now close the connection when the context ends
or the connector timeout passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
A server offering both password and keyboard-interactive got a rejected
password twice, and interactive rounds got it again, spending lockout
attempts before the broker could quarantine (security review of #14).
One shared submission now covers both methods and every round; a second
request is an authentication failure.

chage ran with no deadline once the handshake deadline was cleared, so a
command that never exits stalled every rotation on the broker. chage and
the passwd channel setup now close the connection when the context ends
or the connector timeout passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
The watchdog stopped after PTY setup, so a target that never started
passwd, or stopped reading, left Change blocked while the broker held
its machine lock (security review of #14). Command start and each answer
are now bounded by the context and the connector timeout, like the
prompts already were.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Security P2 (Change unbounded after PTY setup): fixed in c8cb8aa. passwd start and every password write now run under the same context-plus-timeout bound as setup and the prompts. TestChangeIsBoundedWhenTheCommandStalls (in-process server that never answers exec) returns within the timeout and on cancellation; without the bound it hangs. Docker suites re-run with -race: pass. (The stack was rebased; the earlier fix is now the commit before this one.)

— rowan (Claude Opus 5.5)

Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
A server offering both password and keyboard-interactive got a rejected
password twice, and interactive rounds got it again, spending lockout
attempts before the broker could quarantine (security review of #14).
One shared submission now covers both methods and every round; a second
request is an authentication failure.

chage ran with no deadline once the handshake deadline was cleared, so a
command that never exits stalled every rotation on the broker. chage and
the passwd channel setup now close the connection when the context ends
or the connector timeout passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
The watchdog stopped after PTY setup, so a target that never started
passwd, or stopped reading, left Change blocked while the broker held
its machine lock (security review of #14). Command start and each answer
are now bounded by the context and the connector timeout, like the
prompts already were.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
passwd and chage output was buffered without a limit, so a compromised
target could exhaust the broker's memory before the timeout (security
review of #14). Both now stop at 64 KiB and close the connection; an
overflow after the commit point stays an ambiguous outcome.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Security P2 (unbounded output) fixed in 4344e8b: passwd and chage output stops at 64 KiB and the connection is closed; an overflow after the commit point remains an ambiguous outcome. TestOutputIsCapped (in-process target flooding 32 MiB on both commands) returns quickly; without the cap it fails. Docker suites re-run with -race: pass.

— rowan (Claude Opus 5.5)

@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

PR Reviewer Guide, "Ignored cancellation": fixed in c3e6a15. A context.AfterFunc closes the raw connection on cancellation during the handshake and authentication, and is removed afterwards. TestHandshakeObservesCancellation fails with the old code (5 s timeout).

@Yoshiofthewire
Yoshiofthewire force-pushed the kyguard/connector-ad branch 2 times, most recently from 04d1930 to a82c72e Compare November 25, 2026 12:56
Yoshiofthewire and others added 2 commits November 25, 2026 08:44
…ec §4.4)

The ssh_passwd connector dials only the descriptor's host and port and
fails in the host-key callback, before any authentication, unless the
SHA-256 of the wire-format host key is the one the descriptor pins. It
authenticates with P_old (password or keyboard-interactive), runs
LC_ALL=C passwd in a PTY, answers the current-password prompt, calls the
broker's commit, then answers the new and retype prompts. A prompt
outside the linux-pam set before the new password leaves, or a repeated
new-password prompt after it, is a refusal; success needs "password
updated successfully" and exit 0. Verification is a fresh login.

Tests run against an OpenSSH container: wrong host key leaves no auth
event in sshd's log, the new password never leaves before the commit
(a recording login shell), minimum-age and rejected-password refusals,
a full rotation and kills after ack_received and after the write.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A server offering both password and keyboard-interactive got a rejected
password twice, and interactive rounds got it again, spending lockout
attempts before the broker could quarantine (security review of #14).
One shared submission now covers both methods and every round; a second
request is an authentication failure.

chage ran with no deadline once the handshake deadline was cleared, so a
command that never exits stalled every rotation on the broker. chage and
the passwd channel setup now close the connection when the context ends
or the connector timeout passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yoshiofthewire and others added 4 commits November 25, 2026 08:44
The watchdog stopped after PTY setup, so a target that never started
passwd, or stopped reading, left Change blocked while the broker held
its machine lock (security review of #14). Command start and each answer
are now bounded by the context and the connector timeout, like the
prompts already were.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
passwd and chage output was buffered without a limit, so a compromised
target could exhaust the broker's memory before the timeout (security
review of #14). Both now stop at 64 KiB and close the connection; an
overflow after the commit point stays an ambiguous outcome.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Once TCP connected, ssh.NewClientConn ran under the connector timeout
alone, so a cancellation during a stalled handshake or authentication
left Login and Verify blocked for up to 30 seconds, delaying broker
shutdown. A context.AfterFunc now closes the raw connection on
cancellation and is removed when the handshake ends; a cancelled
handshake returns the context's error (a host-key mismatch or a
rejected credential still map as before).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After passwd reports success, cancellation now closes the connection and
returns at once as an ambiguous outcome instead of waiting for the
connector timeout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

Guide Cancellation ignored fixed in 7c4dff4: the final wait after the success message also watches ctx, closes the connection and returns an ambiguous error at once. TestChangeObservesCancellationAfterSuccess uses an in-process server that prints success and never exits, with a one-hour connector timeout; without the fix the test times out.

@Yoshiofthewire
Yoshiofthewire changed the base branch from kyguard/connector-ad to main November 26, 2026 01:43
@Yoshiofthewire
Yoshiofthewire merged commit e86930a into main Nov 26, 2026
12 checks passed
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