Repository navigation
Stop the native SSH-key handshake from disclosing whether a user exists - #121704
tiandiwonder merged 11 commits into
Conversation
A native-protocol client asks for SSH-key authentication by prefixing the user name in its Hello with `EncodedUserInfo::SSH_KEY_AUTHENTICAION_MARKER`. `TCPHandler::receiveHello` then resolved that user before any credential was exchanged, so the first round trip separated three states for a client holding nothing at all: the user does not exist (`There is no user ... in user directories`), the user exists but authenticates some other way (`Expected authentication with SSH key`), and the user exists with an SSH key (a challenge). That is a user-existence and authentication-method oracle, and because the attempts never reached `AccessControl::authenticate` they also did not count against the user's `FAILED_SEQUENTIAL_AUTHENTICATIONS` quota. The password path has never behaved this way: it answers `Authentication failed: password is incorrect, or there is no user with such name` for a wrong password and for an unknown user alike. Issue the challenge unconditionally instead, and leave every outcome to the credential check that already followed. `checkSshAuthentication` returns false when the user's method is not `SSH_KEY`, and an unknown user throws inside the storage lookup, so both arrive at that one message - and both now consume the failed-authentication quota. The client-version check moves to the top of the branch: it depends only on the client's own version, so it discloses nothing, and it has to stay reachable before challenge packets are read. The challenge is a server-side random value and says nothing about the user. The cost is one extra round trip for a handshake that cannot succeed, and an unauthenticated connection held open while the server waits for a signature - neither is new, since a client can already hold a connection with a partial hello and an existing SSH user already reached this state. One behaviour change: a client that asks for SSH-key authentication as a user configured with a password used to be told `Expected authentication with SSH key`, and now completes the challenge and gets the ordinary authentication failure. The precise reason is still logged server-side. `test_ssh_handshake_does_not_disclose_user_existence` speaks the protocol on a raw socket - the only way to request the marker for an arbitrary user - and asserts that an SSH user, a password user and an unknown user are all challenged and then all fail with the same code and the same text. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [bd3f38c] Summary: ✅
AI ReviewSummaryThe PR removes the user lookup before the native SSH-key challenge, preventing the initial handshake from revealing user existence or authentication type. It adds a focused protocol regression test and updates the existing RSA test fixture for FIPS compatibility. The scoped fix is sound; no new actionable findings. Missing context / blind spots
Final VerdictStatus: ✅ Approve. No code changes requested; current CI must complete successfully. |
|
|
||
| /// Challenge the client without looking the user up first: whether a user exists and how | ||
| /// it authenticates must not be observable before a signature is checked. Reporting the | ||
| /// failure is left to the credential check below, which answers an unknown user and a |
There was a problem hiding this comment.
FAILED_SEQUENTIAL_AUTHENTICATIONS still leaves this path distinguishable after a few probes. session->authenticate calls AccessControl::authenticate, which only creates an authentication quota for existing users (getAuthenticationQuota returns nullptr for an unknown name) and then calls authentication_quota->used(...) before entering the generic AUTHENTICATION_FAILED rewrite. EnabledQuota::used throws QUOTA_EXCEEDED directly, so a real user with an authentication quota still returns a different public error than an unknown user once the limit trips.
That means the oracle is reduced from one attempt to N attempts, not removed. Please make quota exhaustion on an unauthenticated SSH-marker handshake collapse to the same public auth failure as the other bad-signature paths, and add a regression with a tiny FAILED_SEQUENTIAL_AUTHENTICATIONS quota.
There was a problem hiding this comment.
This is not specific to the SSH marker: AccessControl::authenticate consumes the failed-authentication quota outside its unifying catch, so a plain password attempt against the same user distinguishes it in exactly the same way, and collapsing QUOTA_EXCEEDED into the generic failure would change the public error on every authentication path — it is tracked separately rather than widened into this fix.
The claim here is scoped to the handshake: nothing distinguishes the three states before a signature is checked, and SSH-marker probes now consume that quota instead of bypassing it entirely, which is strictly better than the current behaviour.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 22 s compile time in total, 7 of them have a recent master baseline. |
The module header repeated what the test's own docstring says, the docstring narrated what the handshake used to answer before this change - which belongs in the pull request, not in a file that outlives it - and several comments restated the line below them. What stays is what a reader cannot recover from the code: the invariant that keeps someone from reintroducing the lookup, why the revision constant is that number, why `default` is not among the probed names, and the field labels on an otherwise opaque byte sequence. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The regression test is what keeps the lookup from coming back, and the comment said nothing the invariant it guards does not already say through that test. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
rschu1ze
left a comment
There was a problem hiding this comment.
Before I review this PR, kindly de-AI the test. It may do the right thing but it lacks a clear control flow, it needs better variable names, and it should have clear comments that readers are able to understand intuitively.
Name the wire helpers as encode/decode pairs, return a named `HandshakeResult` instead of a tuple whose first element had to be compared against a packet id, and record where every protocol constant comes from and which leak each assertion rules out. `read_varstring` is split into `read_binary_field` and `read_string`: the challenge is a nonce that must not be decoded, while the exception's name, message and stack trace must be. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: This PR removes a per-user SSH-key check from the server's login handshake and adds a test. Neither change runs during query execution, so none of the flagged deltas can be attributed to the diff. The six ClickBench slowdowns (Q16 +17.1%, Q17 +13.2%, Q31 +12.9%, Q32 +12.1%, Q33 +8.9%, Q34 +7.1%) are all high-cardinality GROUP BY queries with higher CPU time, and five fall inside master's current range. A shared environment cause fits better, since two of the PR's ClickBench runs shared one host. All rows stay inconclusive, TPC-H showed no flagged changes, and this PR needs no performance follow-up. clickbenchFlagged queries (6 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
The probe needs nothing but a TCP connection and two users, so it belongs in `tests/queries/0_stateless` next to the other native-protocol probes, where it runs across every functional-test configuration rather than only the integration matrix. Its two users are created with `CREATE USER`, so the `users.xml` change the integration test needed goes away with it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…-enumeration-oracle
The reviewer asked for a clear control flow, better names, and comments a reader can follow. The probe returns a plain tuple instead of a dataclass, the three user states are now checked in one loop as each handshake completes rather than in three passes over a dictionary, the one-line codec helpers lost their docstrings, and `CREATE USER` moved inside the block the cleanup covers. Tagged `no-openssl-fips`, as every other stateless test that touches an `ssh-ed25519` key is. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A test comment that names a C++ header or symbol goes stale the moment the code moves, and it makes the reader chase a file to understand a local constraint. The docstring now opens with what the test checks rather than the bug it came from, says it in fewer words, and no longer carries the pull request link. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Fixed. |
…ts do The test read `CLICKHOUSE_HOST` and `CLICKHOUSE_PORT_TCP` with `os.environ[...]`, and `clickhouse-test` does not set either: they come from the environment the suite was started in, and `shell_config.sh`, which supplies them, is only sourced by the `.sh` tests. So the test died on `KeyError: 'CLICKHOUSE_HOST'` before opening a single connection, on every sanitizer run. Read them with a default instead, as every other `.py` test in this directory does (`04078_native_protocol_input_validation`, `04092_tcp_settings_parse_error_closes_connection`, `05100_mysql_handshake_underflow`). `CLICKHOUSE_BINARY` and `CLICKHOUSE_DATABASE` are set by `clickhouse-test`, but are read the same way so the test can also be run by hand.
`clickhouse-test` runs a `.py` test by executing it through its shebang, so the file needs the executable bit, as every other `.py` test in `0_stateless` has. The previous commit dropped it, and the test failed with `return code: 126` / `Permission denied` before it ever opened a connection - which also means the environment fix in that commit has not actually been exercised by CI yet.
This test creates a user without an `ssh_key` authentication method and connects with `--ssh-key-file`, expecting `AUTHENTICATION_FAILED`. Until now the server rejected it before sending a challenge, so the client never signed anything and the key in the test was never used. Removing that early rejection is the point of this change, so the client now signs the challenge. The hardcoded key is a 1024-bit RSA key, which OpenSSL rejects in FIPS mode as it is below the approved minimum modulus. `libssh`'s `sshsig_sign` then takes its `sig == NULL` branch, which reaches `cleanup` without setting `rc`, so it returns `SSH_OK` while leaving the out parameter at `nullptr`; `SSHKey::signString` trusts the return code and constructs a `String` from it. The client segfaults before it can receive the error, and the test fails on the `amd_fips_release` build. Replace it with a freshly generated 4096-bit key. The test was written with `ssh-keygen -t rsa -b 4096`, which `819a654f5e5` replaced with a hardcoded key to avoid generating one under the five-second `expect` timeout; the drop to 1024 bits was incidental to that. Hardcoding keeps that benefit, and 4096 bits restores the original intent with room above the FIPS minimum. The test now covers the full challenge-sign-verify path on FIPS builds as well, rather than being excluded from them. The missing out-parameter check in `SSHKey::signString` is a separate pre-existing defect, reachable today on a FIPS build by any user authenticating with a key that FIPS rejects, and is fixed separately.
2908b8f
Backport #121704 to 26.8: Stop the native SSH-key handshake from disclosing whether a user exists
Backport #121704 to 26.9: Stop the native SSH-key handshake from disclosing whether a user exists
Backport #121704 to 26.7: Stop the native SSH-key handshake from disclosing whether a user exists
Backport #121704 to 26.3: Stop the native SSH-key handshake from disclosing whether a user exists
Backport #121704 to 26.10: Stop the native SSH-key handshake from disclosing whether a user exists
… from disclosing whether a user exists
Problem
A native-protocol client asks for SSH-key authentication by prefixing the user name in its Hello
with
EncodedUserInfo::SSH_KEY_AUTHENTICAION_MARKER(" SSH KEY AUTHENTICATION "). Holding nocredential of any kind, such a client could tell three states apart on the first round trip:
There is no user '<name>' in 'user directories';Expected authentication with SSH key;Protocol::Server::SSHChallengeand waits.So the handshake answered "does this user exist, and how does it authenticate?" for anyone who
could reach the native port. The probes also never reached
AccessControl::authenticate, so theydid not count against that user's
FAILED_SEQUENTIAL_AUTHENTICATIONSquota — a quota configuredto slow credential stuffing did not apply to them.
The password path has never behaved this way: it answers
Authentication failed: password is incorrect, or there is no user with such namefor a wrong password and for an unknown user alike.Root cause
TCPHandler::receiveHelloresolved the user before any credential was exchanged:The lookup's own exception text reached the wire for a name that does not exist, and the explicit
rejection above covered the name that exists but is configured for something else. Only the third
case got as far as the challenge.
Fix
The challenge is now issued unconditionally, and every outcome is left to the credential check
that already followed.
checkSshAuthenticationreturns false when the user's authenticationmethod is not
SSH_KEY, and an unknown user throws inside the storage lookup, so both reachAccessControl::authenticate's single message — and both now consume the failed-authenticationquota.
The client-version check moved to the top of the branch. It depends only on the client's own
version, so it discloses nothing about the user, and it must stay reachable before the server
starts expecting challenge packets.
The challenge is a server-side random value and carries nothing about the user. The cost is one
extra round trip for a handshake that cannot succeed, and an unauthenticated connection held open
while the server waits for a signature — neither is new: a client can already hold a connection
open with a partial hello, and an existing SSH user already produced that state.
One behaviour change worth noting for review: a client that asks for SSH-key authentication as a
user configured with a password used to be told
Expected authentication with SSH key; it nowcompletes the challenge and receives the ordinary authentication failure. The precise reason is
still logged server-side at information level.
Regression coverage:
test_ssh_handshake_does_not_disclose_user_existenceintests/integration/test_ssh_keys_authentication/speaks the native protocol on a raw socket — theonly way to request the marker for an arbitrary user — and asserts that an SSH user, a password
user and an unknown user are all challenged and then all fail with the same error code and the
same text. On the unfixed binary it reports both leaking messages at once. The module's existing
tests (
test_ecdsa,test_ed25519,test_rsa,test_wrong_key,test_key_with_passphrase,test_key_with_wrong_passphrase) are unchanged and still pass.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Requesting SSH-key authentication over the native protocol no longer reveals whether the named user exists, or how it authenticates, before its signature is checked.
Documentation entry for user-facing changes
Bug fix only, no user-facing documentation changes.
Workflow [PR]
Sync PR [sync-upstream/pr/121704]
Version info
26.11.1.69-master(included in26.11and later)26.10.2.12,26.9.20.26,26.8.29.11,26.7.33.3,26.3.56.2