Skip to content

Do not reject an unsigned interserver TablesStatusRequest - #113602

Open
tiandiwonder wants to merge 11 commits into
masterfrom
fix-interserver-tables-status-rolling-upgrade
Open

tiandiwonder wants to merge 11 commits into
masterfrom
fix-interserver-tables-status-rolling-upgrade

Conversation

@tiandiwonder

@tiandiwonder tiandiwonder commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A cluster configured with an interserver <secret> cannot be upgraded from before 26.7 in a rolling manner: Distributed queries initiated on the not-yet-upgraded nodes fail. Reported in #99854 (comment).

Root cause

#99854 made the server reject an interserver TablesStatusRequest that carries no cluster-secret hash. Only revision 54487 and above sends one, and the request is sent by ConnectionEstablisher while establishing the connection - before any Query has authenticated it - so a request from an older peer (26.6 is 54485) is always unsigned. The upgraded node answers AUTHENTICATION_FAILED, the replica counts as a failed connection, and the query fails. Merely flipping the default would not fix it: the peer declares its own revision, so an attacker advertises 54486 and takes the unauthenticated path anyway. The rejection is what closed the disclosure, not the hash.

Solution

Answer an unsigned request with a response that hides the table status: every requested table is reported present, not replicated and writable, independently of the actual state of the tables. Nothing is disclosed, because the response no longer depends on that state; and the old initiator sees a usable replica and proceeds to the Query, which does authenticate with the cluster secret. The boundary moves from connection establishment to the query rather than disappearing.

The cost, logged with a rate-limited warning: on such a connection replica staleness (max_replica_delay_for_distributed_queries), readonly filtering and table existence are not taken into account. interserver_tables_status_require_auth (now false by default) still rejects, for operators who prefer a hard error. This mirrors #47213, which kept the pre-54462 interserver protocol working behind a warning; that path is still in place three years later.

The request hash is now read based on the peer's revision rather than on whether this build has SSL. That is required, not cleanup: the no-SSL arm used to reject unconditionally, so without it a 54487 peer on a no-SSL build would take the unsigned branch and read the body without consuming the 32-byte hash. Such a peer now gets SUPPORT_IS_DISABLED.

Also restores the 54487 row and the TablesStatusRequest section of the Native protocol specification, dropped by the Mintlify migration. Bounding how much of a request an unauthenticated peer can make the server deserialize is split out into #123422.

Related: #99854
Related: #47213

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

An interserver TablesStatusRequest from a node too old to sign it with the cluster secret is now answered with a response that hides the table status, instead of being rejected. This restores rolling upgrades of clusters configured with an interserver <secret> from versions older than 26.7. The new server setting interserver_tables_status_require_auth rejects such requests instead, if a hard error is preferable.


Workflow [PR]
Sync PR [sync-upstream/pr/113602]

Authenticating `TablesStatusRequest` with a cluster-secret hash gated on protocol revision
54487 also made the server reject a request that carries no hash, which broke rolling
upgrades: a peer below 54487 sends no hash, and `ConnectionEstablisher` sends the request
while establishing the connection - before any `Query` has authenticated it - so on a fresh
connection the request is always unauthenticated. The upgraded node answered
`AUTHENTICATION_FAILED`, the replica was counted as a failed connection, and a
`Distributed` query initiated on a not-yet-upgraded node failed.

Flipping the default of `interserver_tables_status_require_auth` is not a fix: the peer
declares its own protocol revision, so an attacker would advertise 54486 and take the
unauthenticated path. The rejection, not the hash, is what closes the disclosure for such a
peer.

Answer an unsigned request with a placeholder response instead: every requested table is
reported as present, not replicated and writable, independently of the actual state of the
tables. Nothing is disclosed, because the response no longer depends on that state, and an
old initiator sees a usable, up-to-date replica and proceeds to the `Query`, which does
authenticate with the cluster secret. The degradation - replica staleness and readonly state
are not taken into account, so `max_replica_delay_for_distributed_queries` has no effect for
such a query - is logged with a rate-limited warning. This mirrors how the pre-54462
interserver protocol is handled: the weaker path keeps working and only logs that the client
is too old.

`interserver_tables_status_require_auth` (now `false` by default) still rejects such
requests, for a cluster where every node is upgraded, or where a hard error is preferable.

Along the way:

* Bound the number of tables in an interserver `TablesStatusRequest`, since its body is
  deserialized before the peer is authenticated on both paths. A legitimate request asks
  about one table.
* Read the request hash based on the peer's revision instead of on whether this build has
  SSL: a build without SSL used to skip the hash a 54487 peer had put on the wire and
  desynchronize the connection. Such a peer now gets `SUPPORT_IS_DISABLED`.
* Restore the 54487 row and the `TablesStatusRequest` authentication section in the `Native`
  protocol specification; both were dropped by the docs migration to Mintlify.

Related: #99854
Related: #47213

Co-Authored-By: Claude Opus 5 <[email protected]>
@mintlify

mintlify Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
ClickHouse-docs 🟢 Ready View Preview Oct 5, 2026, 5:36 AM

@clickhouse-gh

clickhouse-gh Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e54e864]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_asan_ubsan, db disk, targeted) FAIL
test_cluster_discovery/test.py::test_cluster_discovery_startup_and_stop FAIL cidb
test_cluster_discovery/test.py::test_cluster_discovery_no_crash_on_empty_static_cluster FAIL cidb
test_cluster_discovery/test.py::test_cluster_discovery_macros FAIL cidb
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py FAIL
Fast test (arm_darwin) DROPPED
Build (amd_darwin) DROPPED
Build (arm_darwin) DROPPED
Build (arm_v80compat) DROPPED
Build (amd_freebsd) DROPPED
Build (ppc64le) DROPPED
Build (amd_compat) DROPPED
Build (amd_musl) DROPPED

AI Review

Summary

This PR restores rolling upgrades for clusters with an interserver <secret> by answering pre-54487 unsigned TablesStatusRequests with a state-independent response, and it adds a real 26.6 mixed-version integration test to cover that path. I do not think it is ready to merge yet: the unauthenticated request body is still effectively unbounded before the cluster secret is proved, and the generated settings docs still publish the opposite default from the code.

Findings
  • ❌ Blocker — [dismissed by author -- https://github.com/Do not reject an unsigned interserver TablesStatusRequest #113602#discussion_r3725367306] [src/Interpreters/TablesStatus.cpp:95] TablesStatusRequest::read still caps only the table count; both readBinary(table_name.database, in) and readBinary(table_name.table, in) retain the default 1 GiB string cap. With the new default path at src/Server/TCPHandler.cpp:1792, an unauthenticated old peer can still force huge allocations before proving the cluster secret, so the pre-auth request is not actually bounded. Please add a per-name cap or a total byte budget before this fallback is enabled by default.
  • ⚠️ Major — [dismissed by author -- https://github.com/Do not reject an unsigned interserver TablesStatusRequest #113602#discussion_r3725367309] [src/Core/ServerSettings.cpp:1740] The source default flips interserver_tables_status_require_auth to false, but the generated settings outputs were not refreshed: docs/reference/settings/server-settings/settings/interserver.mdx:37 still says default_value="1" / Defaults to true, and generated explorer snippets like docs/snippets/zh/components/ServerSettingsExplorer/ServerSettingsExplorer.jsx:451 still publish default "1". That leaves the shipped default and the published docs in direct conflict; please regenerate the settings docs/snippets in the same PR.
Final Verdict
  • Status: ❌ Block
  • Minimum required actions: bound unauthenticated TablesStatusRequest deserialization before cluster-secret validation, and regenerate the settings docs/snippets so the published default matches the shipped behavior.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 6, 2026
Comment thread src/Interpreters/TablesStatus.cpp Resolved
Comment thread src/Core/ServerSettings.cpp Resolved
tiandiwonder and others added 2 commits August 6, 2026 03:07
The placeholder-response test used protocol revision 54449 over a raw socket, which proves
what the response contains but not that an actual old initiator gets through: it never
reaches `ConnectionEstablisher`, and 54449 avoids the nonce and the chunked framing a real
26.6 peer uses.

Add a mixed-version test: a 26.6 initiator (revision 54485, so its `TablesStatusRequest`
carries no cluster-secret hash) reads a `Distributed` table whose shard lives on the build
under test, and must get its rows. The initiator's version is asserted to be older than 26.7,
so the test cannot pass vacuously if the old image is not used. Its counterpart points the
same initiator at a node with `interserver_tables_status_require_auth` enabled - the previous
default - and requires that query to fail, which is what makes the first test load-bearing.

Also cover the interserver table-count bound: 1024 tables are answered, 1025 close the
connection, and an ordinary client can still ask about more than the interserver limit.

Co-Authored-By: Claude Opus 5 <[email protected]>
The new file was left out of the previous commit, so the rolling-upgrade test would fail to
start its cluster.

Co-Authored-By: Claude Opus 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing e54e86499 with master 98f3cad68 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

8 translation units recompiled, 40 s compile time in total, 8 of them have a recent master baseline.

Job report

Two problems with the previous commit, both found while reviewing the placeholder design.

Strict mode lost its early rejection. Before this branch, an unauthenticated old-protocol
`TablesStatusRequest` was refused *before* its body was read when
`interserver_tables_status_require_auth` was enabled. The restructure moved the setting check
after `request.read`, so an operator who had chosen strict mode could still be made to
deserialize a request. The check moves back ahead of the read; only a request that will be
answered - with the placeholder, or with the real status on a connection an earlier `Query`
already authenticated - is read at all.

A bound on the number of tables does not bound the request. `readStringBinary` resizes the
string to the declared length before reading the bytes, so a single name declared as 1 GiB is
an unauthenticated allocation regardless of how few tables the request asks about. The limits
become a pair - at most 1024 tables, each name at most 8 KiB, so the worst case per request is
16 MiB of memory-tracked allocation - and `read` takes them as `TablesStatusRequestLimits`
instead of a bare count.

Also state the cost of the placeholder path in the setting's description instead of
understating it: it is not only replica staleness and readonly state that stop being taken into
account, but also table existence, and with
`fallback_to_stale_replicas_for_distributed_queries = 0` no `ALL_REPLICAS_ARE_STALE` is raised,
so a caller that asked to fail rather than read stale data silently reads stale data. Data
access is unaffected - the query itself is still authenticated with the cluster secret.

Co-Authored-By: Claude Opus 5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... label Sep 4, 2026
pull Bot pushed a commit to admariner/ClickHouse that referenced this pull request Sep 12, 2026
TCPHandler::receivePacketsExpectQuery() handles the packets that arrive
before any Query has been received. Its Data/Scalar case called
processUnexpectedData() and only then threw UNEXPECTED_PACKET_FROM_CLIENT.
That call builds a headerless NativeReader and reads a block, so the
column type name comes off the wire and is handed to DataTypeFactory.

Entering interserver mode requires only the name of a cluster that has a
non-empty <secret>, never the secret itself, and the secret is verified
only inside processQuery(), which this loop never reaches. So an
unauthenticated peer decided which type the server constructed and which
deserializer ran.

The read had no consumer for any peer either: its return value was
discarded, and the exception thrown right after is caught where
"if (!query_state) return;" exits runImpl, so the exception is never
sent, the connection is closed, and no further byte is read from the
socket. runImpl's exception handler already documents that policy ("the
server should not try to skip (parse, decompress) the remaining packets
sent by the client, as it will lead to additional work and unneeded
exposure to unauthenticated connections"); the parse it forbids had
already happened one frame earlier. The adjacent case of the same
switch, processObsoleteIgnoredPartUUIDs(), was given exactly this shape
in ClickHouse#99398.

No setting gates the rejection, deliberately. The TablesStatusRequest
path needed an operator opt-out when it was hardened in ClickHouse#99854 because
it was a served path, and rejecting it broke rolling upgrades (ClickHouse#113602).
Data before Query has always thrown, so there is no working flow to
preserve, and nothing a client can observe changes: the connection
closes with nothing written back, before and after.

The regression test completes an accepted interserver handshake over a
raw socket and then sends a Data packet declaring a column type that
does not exist. Without this change the server logs "Unknown data type
family: NoSuchTypeGroeneAI", which is the proof that a wire-supplied
type name reached DataTypeFactory before authentication. It is extended
into the existing pre-authentication interserver test module rather than
added as a new one, because that module already provides the cluster
with a <secret> and a handshake pinned below the chunked-packets
revision, which is what makes a hand-built packet feasible.

Requested by @ nikitamikhaylov, relayed via OranjeAI.

Co-Authored-By: Claude Opus 5 <[email protected]>
The bounds on how much of a `TablesStatusRequest` an unauthenticated interserver peer
can make the server deserialize (`TablesStatusRequestLimits`) are independent of not
rejecting an unsigned request: they apply on every path, including the signed one and
the one this branch leaves unchanged. Keeping them here only grows the change that has
to land for a rolling upgrade to work, so they move to their own pull request.

The revision-based gating of the request hash stays, because it is what keeps this
change correct: once an unsigned request is no longer rejected, a `54487` peer talking
to a build without SSL would fall into the unsigned branch and read the body without
consuming the 32-byte hash, desynchronizing the connection.
…les-status-rolling-upgrade

The only conflict was in `tests/integration/test_interserver_tables_status_auth/test.py`:
master grew an `open_interserver_connection` helper (for the `Data`-before-`Query`
test) that is the same handshake this branch had added separately as
`connect_as_old_interserver_peer`. Resolved by dropping this branch's copy and using
master's helper, keeping both sides' tests.

The protocol specification moved to
`docs/resources/develop-contribute/native-protocol/protocol.mdx` on master; the rename
was followed automatically.
The restored specification said the client writes "a 32-byte hash immediately after
the packet type", which omits the framing: `Connection::sendTablesStatusRequest` uses
`writeStringBinary` and `TCPHandler` reads it with `readStringBinary(..., 32)`, where
the `32` is a maximum size, not a fixed length. The bytes on the wire are therefore
`[VarUInt 32][32 digest bytes]`.

The per-query `auth_hash` does not have this problem because the Query packet table
already declares its type as `String`; the `TablesStatusRequest` hash has no such table
entry, so the prose has to carry it. A third-party client following the old wording
would omit the length prefix and desynchronize the connection.
…les-status-rolling-upgrade

# Conflicts:
#	src/Server/TCPHandler.cpp
… diff

Rename `respond_with_placeholder` to `hide_table_status` and describe the response as one that
hides the table status everywhere (comments, the warning, the setting documentation, the protocol
specification and the tests), since "placeholder" did not say what it protects.

Create the interserver context unconditionally, as on `master`: it is unused when the status is
hidden, and the guard only grew the diff. Restore `processUnexpectedTablesStatusRequest` to its
`master` form: a no-SSL build never runs an interserver query, so it cannot reach that function in
interserver mode, and the connection is closed right after the skip anyway. Drop two comments
that repeated the code and the comment at the top of the function.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`Style check` fails on it: `src/Server/TCPHandler.cpp:1821: Trailing whitespaces.`
The blank line and the space before the colon were both introduced by this branch and
neither is needed, so the loop header and the line above it now read exactly as on master.

@tavplubix tavplubix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need this change in master, or only in old releases?

tavplubix pushed a commit that referenced this pull request Oct 13, 2026
…usRequest`

In interserver mode the connection is not authenticated until a `Query` carries a valid
cluster-secret hash, but `ConnectionEstablisher` sends `TablesStatusRequest` while establishing
the connection. Any peer that sends a Hello with the interserver user marker could therefore
learn, per table, whether it exists, whether it is replicated, its replication delay and whether
it is read-only.

Answer such a request with a response that does not depend on the state of the tables: every
requested table is reported present, not replicated and writable. The initiator still sees a
usable replica and goes on to the `Query`, which does authenticate. A connection that has already
authenticated a query still gets the real status.

This is the behaviour of #113602 for peers that cannot
sign the request, implemented without the protocol revision bump of
#99854, which `26.3` cannot take.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

This branch was successfully deployed

1 active (outdated) deployment
staging - docs — 9891a374 Deployed Oct 5, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... pr-bugfix Pull request with bugfix, not backported by default v26.7-must-backport v26.8-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants