Repository navigation
Fix/interserver mode before secret hash bug - #99675
tiandiwonder merged 23 commits into
Conversation
…er Mode prior to actually being authenticated which allows the return of real table metadata system.one, system.numbers, system.tables, system.databases, system.columns — all without credentials! I'm committing the fix, this bug is logged as ClickHouse#99512
|
|
|
Workflow [PR], commit [d68b6f2] Summary: ❌
AI ReviewSummaryThis PR closes the remaining Hello-phase gap for Final VerdictStatus: ✅ Approve |
|
Thank you I'll take a look tomorrow and update it... |
…e-before-secret-hash-bug
Replace `try { ... } catch (...) {}` with a direct check that lets
`getCluster` propagate `CLUSTER_DOESNT_EXIST`. The silent `catch (...)`
was both flagged as dangerous by review and rejected by the style check
(`catch (...) that silently swallows exceptions`).
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The reviewer (`clickhouse-gh`) and CI proved that gating
`receivePacketsExpectQuery` on `is_interserver_authenticated` rejects
packets that legitimate distributed/interserver protocol flows send
before the first authenticated `Query`:
- `IgnoredPartUUIDs` from `RemoteQueryExecutor::sendQueryUnlocked`
(`connections->sendIgnoredPartUUIDs` before `connections->sendQuery`).
- `TablesStatusRequest` from `ConnectionEstablisher::run` via
`Connection::getTablesStatus`.
Multiple integration and stateless tests confirmed the breakage:
`02590_interserver_mode_client_info_initial_query_start_time` and
`test_distributed_inter_server_secret` were failing with
`ATTEMPT_TO_READ_AFTER_EOF` because the server was closing connections
mid-flow with `AUTHENTICATION_FAILED`.
The remaining `receiveHello` check (rejecting `USER_INTERSERVER_MARKER`
when the cluster has no secret) already fixes the original bug for
single-node servers and clusters without secrets, which is the primary
attack surface reported in ClickHouse#99512.
CI report: ClickHouse#99675
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Confirms that `USER_INTERSERVER_MARKER` is rejected at the `receiveHello` phase when the named cluster either does not exist or has no `<secret>` configured. Without this rejection a client could enter interserver mode without proving knowledge of the cluster secret and exercise pre-auth protocol packets that rely on `fake_interserver_context`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The `processClusterNameAndSalt` method reads the salt as a length-prefixed string via `readStringBinary`, not as 32 raw bytes. Sending 32 raw `'A'` bytes made the server interpret the first byte (`0x41 = 65`) as the VarUInt length and then wait for 65 bytes that never came. The handshake-timeout closed the connection, so the test saw a `closed` socket and the first assertion (rejection happened) passed — but our new exception path was never reached, which is why the `contains_in_log` assertion failed in every CI shard. Encoding the salt as a length-prefixed string lets the server finish reading the `Hello` packet and reach the `receiveHello` check that rejects the interserver marker for clusters without a secret. CI report: ClickHouse#99675 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…e-before-secret-hash-bug
…e-before-secret-hash-bug
Workflow files in this branch were stale or had been deleted as a workaround for GitHub's workflow-scope check. Restoring them to match `master` so the PR diff no longer contains those unrelated changes.
…e-before-secret-hash-bug
|
Picked this up to keep it moving:
The only CI failure was |
…e-before-secret-hash-bug
|
Kept this moving:
The remaining unresolved thread (pre-auth |
…e-before-secret-hash-bug
|
Merged The CI reds were all unrelated flakes now addressed by the master merge or known issues:
The one remaining unresolved review thread is the design question about pre-auth |
|
@groeneai, the only red here is CH Inc sync → "Check public build", and it's a false positive in the sync tooling — not a defect in this PR. Public CI is fully green and the PR's actual change (an 11-line cluster-secret check in Root cause. @evillique's recent Suggested direction (your call): apply only the PR's own diff ( The remaining sync test-job reds are unrelated known flakes (none touch this PR's own tests, all reran-and-passed or were auto-classified flaky): |
|
@alexey-milovidov thanks for the precise root cause. I checked from the public side and your diagnosis holds: this PR's own change is the 11-line cluster-secret check in One blocker on the ask: I don't have access to Recommendation: Direction 1 (apply only the PR's own delta), and prefer it over Direction 2. The check's purpose is "does this PR's change break the public build", so the public clone should be The robust way to apply the delta is a 3-way merge rather than a naive # in the private checkout: BASE = PR merge-base, HEAD = PR head
git show "$BASE:$F" > /tmp/base
git show "$HEAD:$F" > /tmp/head
# 3-way merge the PR's delta (base..head) onto the public clone's own copy
git merge-file -p "$PUBLIC_CLONE/$F" /tmp/base /tmp/head > "$PUBLIC_CLONE/$F.merged" \
&& mv "$PUBLIC_CLONE/$F.merged" "$PUBLIC_CLONE/$F"
I'll link the clickhouse-private PR here if I open it; happy to if access is granted. |
|
@evillique (tooling owner), @groeneai — one refinement to the For sync PRs, if is_sync_pr:
# cloning upstream PR HEAD instead of master
clone_command = [git clone --no-checkout ...; fetch origin pull/{parent_pr_number}/head; checkout FETCH_HEAD]So for a sync PR the public clone's In other words: for sync PRs the wholesale copy is not just missing a header — it is purely harmful, replacing Concrete fix (two distinct cases):
This is in |
|
@alexey-milovidov agreed, the sync-PR refinement is correct and simpler. For a sync PR the public clone is checked out at the upstream PR head, so every shared file the PR touches is already The 3-way merge stands for the non-sync private PR case (clone at master, apply only the delta via On opening the PR: I still have no |
…e-before-secret-hash-bug
|
Kept this moving:
The remaining unresolved review thread (pre-auth |
…e-before-secret-hash-bug
|
Kept this moving:
Public CI is fully green (162 checks, 0 failed), the AI review verdict is Approve, and there are no unresolved review threads. The remaining out-of-scope item (pre-auth |
|
Kept this moving:
The remaining out-of-scope item (pre-auth |
|
Status update on
Public CI is fully green (149 / 0), the AI review verdict is Approve, and there are no unresolved review threads. |
|
@tiandiwonder Can you please check if this PR is a duplicate of #99854 ? |
|
@tiandiwonder Since you were working on related issue #99854, would you like to check this one as well (I assigned you)? Thanks! |
| /// Verify the cluster is configured with a secret before entering | ||
| /// interserver mode. Otherwise, the `USER_INTERSERVER_MARKER` would | ||
| /// let any client enter interserver mode and exercise pre-auth | ||
| /// protocol packets that rely on a `fake_interserver_context`. | ||
| /// `getCluster` throws `CLUSTER_DOESNT_EXIST` if the cluster is | ||
| /// unknown; we deliberately let it propagate. |
There was a problem hiding this comment.
optional: this comment is a bit long — 2-3 lines would do. the fake_interserver_context detail reads better in the PR/issue description; inline it's enough to say why we reject and that getCluster throws CLUSTER_DOESNT_EXIST for an unknown cluster, which we let propagate.
| /// Verify the cluster is configured with a secret before entering | |
| /// interserver mode. Otherwise, the `USER_INTERSERVER_MARKER` would | |
| /// let any client enter interserver mode and exercise pre-auth | |
| /// protocol packets that rely on a `fake_interserver_context`. | |
| /// `getCluster` throws `CLUSTER_DOESNT_EXIST` if the cluster is | |
| /// unknown; we deliberately let it propagate. | |
| /// Reject interserver mode unless the cluster has a `<secret>`; otherwise any client | |
| /// could enter interserver mode and exercise pre-auth protocol packets. `getCluster` | |
| /// throws `CLUSTER_DOESNT_EXIST` for an unknown cluster, which we deliberately let propagate. |
There was a problem hiding this comment.
Applied directly in 1260b249.
|
Kept this moving:
|
…e-before-secret-hash-bug
…ession_log - Do not serialize the exception back to an unauthenticated interserver peer when the `Hello`-phase cluster-secret check fails: the handshake catch block now closes the connection without a response for `AUTHENTICATION_FAILED` in interserver mode, so nothing (not even whether the named cluster exists) is disclosed. Previously the exception with a stack trace was sent back. - Wrap the `CLUSTER_DOESNT_EXIST` from `getCluster` into `AUTHENTICATION_FAILED` (mirroring `processQuery`) so both rejection paths are uniform. - Route the rejection through `Session::onAuthenticationFailure` so the blocked `USER_INTERSERVER_MARKER` handshakes appear in `system.session_log` as `LoginFailure` rows with the `TCP_Interserver` interface. - Tighten `test_interserver_marker_requires_cluster_secret` to require a silent close (no data) and assert the `session_log` row. - Fix `test_interserver_tables_status_auth::test_old_protocol_unauthenticated_request_is_rejected` (failed on 5 CI lanes: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=99675&sha=959beb1aabdd19bb6315e8ee519c441cf94da5e9&name_0=PR): the `Hello` must name the existing secreted cluster `mismatch`, otherwise the handshake itself is now rejected and the `TablesStatusRequest` stage that the test covers is never reached. ClickHouse#99675 Co-Authored-By: Claude Fable 5 <[email protected]>
|
Kept this moving:
Remaining: the CLA check still shows the |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 22/23 (95.65%) · Uncovered code |
1d4408f
26.7 lacks #99675, so the handshake still sends the `AUTHENTICATION_FAILED` exception back to an interserver peer, and `ClientInfo::getLastForwardedFor` throws on a non-IP forwarded address before `onAuthenticationFailure` is reached. The connection is rejected in both cases; only the assertions about a silent close and the `system.session_log` row for the malformed address are adjusted. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=127346&sha=latest&name_0=BackportPR&name_1=Integration%20tests%20(amd_tsan%2C%205%2F6) PR: #127346 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Changelog category (leave one):
Changelog entry
Reject native protocol handshakes that use the
USER_INTERSERVER_MARKERfor an unknown cluster, or for a cluster configured without a<secret>. Previously such a handshake would let an unauthenticated client enter interserver mode and exercise pre-auth protocol packets (e.g.TablesStatusRequest) backed by afake_interserver_context, learning information about local tables without proving knowledge of the cluster secret.Scope
This addresses the unknown-cluster and no-secret-cluster cases of the issue:
USER_INTERSERVER_MARKERis rejected because the cluster does not exist (CLUSTER_DOESNT_EXIST)<secret>USER_INTERSERVER_MARKERis rejected withAUTHENTICATION_FAILED<secret>processQueryFor clusters that do have a non-empty
<secret>, a client that knows the cluster name can still send pre-query packets such asTablesStatusRequestbefore the hash is verified. Closing that remaining surface requires either authenticating during the Hello phase (challenge/response over the salt + cluster secret) or reworkingConnectionEstablisherso the secret hash is sent beforeTablesStatusRequest. Both are protocol-level changes that warrant their own discussion and a protocol-revision bump, so they are tracked separately rather than folded into this fix.Documentation entry for user-facing changes
This fixes a bug so the expected behavior of ClickHouse is as documented.
I compiled this successfully and ran the POC from issue #99512 against it, confirming the fix works with no errors thrown. An integration test (
test_interserver_marker_requires_cluster_secret) sends a crafted native-protocol Hello packet and asserts the server rejects both an unknown cluster and a cluster configured without a secret, including verifying the expected log message.Related: #99512
Version info
26.8.1.184(included in26.8and later)