Skip to content

add a setting to allow disabling interserver mode over tcp_with_proxy interface - #123188

Merged
tiandiwonder merged 6 commits into
ClickHouse:masterfrom
chhetripradeep:pchhetri/settings-to-disable-interserver-mode-over-tcp-with-proxy
Oct 12, 2026
Merged

tiandiwonder merged 6 commits into
ClickHouse:masterfrom
chhetripradeep:pchhetri/settings-to-disable-interserver-mode-over-tcp-with-proxy

Conversation

@chhetripradeep

@chhetripradeep chhetripradeep commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Improvement

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

Add the tcp_with_proxy_allow_interserver_mode server setting, which allows disabling the native protocol's interserver mode on tcp_with_proxy_port


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

Version info

  • Merged into: 26.10.1.2179-master (included in 26.10 and later)
  • Backported to: 26.9.25.14, 26.8.34.12, 26.7.38.9

@tiandiwonder tiandiwonder self-assigned this Oct 1, 2026
…o-disable-interserver-mode-over-tcp-with-proxy

# Conflicts:
#	src/Core/ServerSettings.cpp
@clickhouse-gh

clickhouse-gh Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ebe4de8]

Summary: ✅


AI Review

Summary

This PR adds the tcp_with_proxy_allow_interserver_mode server setting so operators can reject native interserver handshakes on tcp_with_proxy_port, logs the rejection through system.session_log, and covers the forwarded-address and malformed-PROXY cases in an integration test. I re-checked the current diff and every existing inline thread, and I do not see a remaining correctness, safety, or security issue in the current revision.

Missing context / blind spots
  • ⚠️ The fetched CI data on 2026-10-02 only contains the Build profile diff report, so I could not cross-check the new integration test against the usual build and integration jobs from CI.
Final Verdict

✅ No new blockers or majors found in the current revision.

LLVM Coverage Report

Measured on commit ebe4de8.

Metric Baseline Current Δ
Lines 88.30% 88.30% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.70% 79.80% +0.10%

Changed lines: Changed C/C++ lines covered: 23/23 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... labels Oct 1, 2026
@chhetripradeep chhetripradeep added the can be tested Allows running workflows for external contributors label Oct 1, 2026
Comment thread src/Server/TCPHandler.cpp Resolved
Comment thread src/Server/TCPHandler.cpp Resolved
Comment thread programs/server/config.xml Resolved
- Declare `ServerSetting::tcp_with_proxy_allow_interserver_mode` in `TCPHandler.cpp`.
- Add `/// NOLINT` to the `throw exception;` to satisfy `cert-err09-cpp`.
- Document the setting with `false` in `config.xml` and mirror it in `config.yaml.example`.
- Add an instance relying on the default value to check interserver mode
  stays allowed on `tcp_with_proxy_port`.
- Assert the `LoginFailure` row in `system.session_log` for the rejection.
Comment thread src/Server/TCPHandler.cpp Resolved
…tcp_with_proxy_port`

The reject path logged the `LoginFailure` against `socket().peerAddress()`, so with
`auth_use_forwarded_address` enabled `system.session_log` recorded the proxy instead
of the real client. Use `getClientAddress` like the empty default user reject path does,
and check `client_address` in the integration test.

Related: ClickHouse#123188

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/Server/TCPHandler.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing ebe4de8f9 with master 1ea026f43 (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

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

Job report

…LED`-only

With `auth_use_forwarded_address` enabled, `getClientAddress` throws `INCORRECT_DATA`
for a non-IP PROXY source address. That skipped the `LoginFailure` row and the silent
close for interserver peers in `runImpl`, sending a serialized error to an unauthenticated
peer. Resolve the forwarded address without throwing in this path, and add a test with a
malformed PROXY source address.

Related: ClickHouse#123188

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements and removed pr-not-for-changelog This PR should not be mentioned in the changelog labels Oct 2, 2026
Bartok9 pushed a commit to Bartok9/ClickHouse that referenced this pull request Oct 9, 2026
The benchmark looked each row's group up in a constant array,
`groups[number % 4096 + 1]`. About half of its CPU went to that lookup
(`arrayElement` over a constant array copies row by row through a virtual
`insertFrom`), not to the sampling-key code the test measures. On arm some
builds run that loop about twice as slow in every server process: in the
job profiles of the slow runs on ClickHouse#98708, ClickHouse#116376, ClickHouse#117754, ClickHouse#123545 and
ClickHouse#123188 only that frame grew (x1.4 to x2.2) while every other frame stayed
flat, so the query moved 20-27% and the confirmation restart reproduced it.

The per-query tags collector numbers groups 0, 1, 2, ... with 0 reserved for
the empty tag set (`ContextTimeSeriesTagsCollector.h`), so the 4096 groups
the subquery creates are 1..4096 and the query can pass
`number % length(groups) + 1` directly. `length(groups)` keeps the scalar
subquery referenced: without it the analyzer drops the subquery, no group is
registered and the function throws `Group 1 is out of bounds`.

Checked on x86 with an official master build: the same keys over the 20M
rows (`sum` and `groupBitXor` equal, 0 rows differ), 84 -> 52 ms, and the
per-process medians of 24 processes span 79-91 ms before and 52-53 ms after.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@tiandiwonder tiandiwonder left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All addressed, thanks.

@tiandiwonder
tiandiwonder added this pull request to the merge queue Oct 12, 2026
@tiandiwonder

Copy link
Copy Markdown
Contributor

@groeneai Follow-up for a separate PR: the six other interserver onAuthenticationFailure sites in TCPHandler.cpp (the no-secret reject in receiveHello and the five receiveQuery HMAC failures) still pass socket().peerAddress(), so on a PROXY listener with auth_use_forwarded_address they record the proxy instead of the client. Please move the non-throwing address resolution added here into a helper and use it at all seven sites; not getClientAddress, which throws on a malformed PROXY source and would break the silent reject.

Merged via the queue into ClickHouse:master with commit 62b7ea5 Oct 12, 2026
149 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 12, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

Acknowledged. I will open a separate PR that moves the non-throwing PROXY address resolution from this PR into a helper and uses it at all seven interserver onAuthenticationFailure sites (not getClientAddress, so the reject stays silent on a malformed PROXY source). I will follow up here with the PR link (or my findings).

@groeneai

Copy link
Copy Markdown
Collaborator

The follow-up is #125326. All seven interserver onAuthenticationFailure sites now call a non-throwing getClientAddressNoThrow(). It reads session->getClientInfo(), not the ClientInfo from the Query packet, because before the hash check that packet's forwarded_for is chosen by the peer. The three wire-reachable sites are covered in test_tcp_with_proxy_interserver_mode.

middas-0706 pushed a commit to middas-0706/ClickHouse that referenced this pull request Oct 12, 2026
…ion failure

On a PROXY listener with `auth_use_forwarded_address`, six of the seven
interserver `onAuthenticationFailure` calls in `TCPHandler` passed
`socket().peerAddress()`, so their `system.session_log` `LoginFailure` rows
named the proxy instead of the client. Only the site added in ClickHouse#123188
resolved the forwarded address, through an inline block that must not throw:
`getClientAddress` throws `INCORRECT_DATA` on a malformed forwarded value,
which would turn the silent `AUTHENTICATION_FAILED` close into a serialized
exception and drop the row.

Move that block into `getClientAddressNoThrow` and call it at all seven
sites (the `receiveHello` proxy-port and unknown-cluster / no-secret rejects,
and the five `processQuery` failures). The helper takes no `ClientInfo`
argument on purpose: in `processQuery` the local `client_info` has been
overwritten from the still unauthenticated peer's Query packet, whose
`forwarded_for` is chosen by that peer, so it must read the session's own
`ClientInfo`, which carries only the connection-level value from the PROXY
header or the `protocols` stack.

The non-interserver rejects keep `getClientAddress`, which rejects a
malformed forwarded address by design.

Test: a third instance in `test_tcp_with_proxy_interserver_mode` that allows
interserver mode on the proxy port, and three raw-protocol cases reaching the
`receiveHello` unknown-cluster reject, the no-salt reject and the hash
mismatch (the last with a decoy `X-Forwarded-For` in the Query packet, sent
at protocol revision 54449 so that no addendum or nonce is involved).

Requested in ClickHouse#123188 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 22, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 removed the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 22, 2026
robot-ch-test-poll2 added a commit that referenced this pull request Oct 22, 2026
Cherry pick #123188 to 26.7: add a setting to allow disabling interserver mode over tcp_with_proxy interface
robot-clickhouse added a commit that referenced this pull request Oct 22, 2026
robot-ch-test-poll2 added a commit that referenced this pull request Oct 22, 2026
Cherry pick #123188 to 26.8: add a setting to allow disabling interserver mode over tcp_with_proxy interface
robot-clickhouse added a commit that referenced this pull request Oct 22, 2026
robot-ch-test-poll2 added a commit that referenced this pull request Oct 22, 2026
Cherry pick #123188 to 26.9: add a setting to allow disabling interserver mode over tcp_with_proxy interface
robot-clickhouse added a commit that referenced this pull request Oct 22, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 22, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 22, 2026
Backport #123188 to 26.9: add a setting to allow disabling interserver mode over tcp_with_proxy interface
clickhouse-gh Bot added a commit that referenced this pull request Oct 22, 2026
Backport #123188 to 26.8: add a setting to allow disabling interserver mode over tcp_with_proxy interface
clickhouse-gh Bot added a commit that referenced this pull request Oct 22, 2026
Backport #123188 to 26.7: add a setting to allow disabling interserver mode over tcp_with_proxy interface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-improvement Pull request with some product improvements pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.4-must-backport v26.6-must-backport v26.8-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants