Repository navigation
Record the forwarded client address for every interserver authentication failure - #125326
Conversation
…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]>
Internal second-model review: adjudication log (click to expand)Pre-publication review: my own cold review plus an independent model (engine: codex; 2 findings; 1 full pass).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261012-062600 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261012-055100 |
|
Workflow [PR], commit [196d9c7] Summary: ✅
AI ReviewSummaryThis PR factors the non-throwing forwarded-address resolution for interserver login-failure logging into a helper and applies it to the remaining interserver authentication-failure sites, with focused integration coverage for the reachable paths. I did not find a correctness, safety, compatibility, or evidence gap in the current diff. Final Verdict
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units9 translation units recompiled, 49 s compile time in total, 9 of them have a recent master baseline. |
Related: #123188
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Interserver authentication failures on a listener that uses the PROXY protocol now record the client address from the PROXY header in
system.session_logwhenauth_use_forwarded_addressis enabled, instead of the address of the proxy.Description
Follow-up to #123188, as requested in #123188 (comment).
On a PROXY listener with
auth_use_forwarded_address, six of the seven interserveronAuthenticationFailurecalls inTCPHandler.cpppassedsocket().peerAddress(), so theirLoginFailurerows insystem.session_lognamed the proxy instead of the client: the unknown-cluster / no-secret reject inreceiveHelloand the fiveprocessQueryfailures (cluster lookup, no salt, no nonce, hash mismatch, non-SSL build). Only the site added in #123188 resolved the forwarded address, inline.The change moves that resolution into
TCPHandler::getClientAddressNoThrowand calls it at all seven sites. It reads the connection's ownClientInfo(session->getClientInfo(), filled from the PROXY header or theprotocolsstack), never the one from the Query packet: at these sites the hash is not verified yet, so that packet'sforwarded_foris chosen by the peer. UnlikegetClientAddress, it does not throw on a malformed forwarded address, so the reject stays a silentAUTHENTICATION_FAILEDclose with asession_logrow. The non-interserver rejects keepgetClientAddress, which rejects a malformed forwarded address by design.Validation:
test_tcp_with_proxy_interserver_modegets a third instance that allows interserver mode on the proxy port, and three cases that send a PROXY header and a raw Hello (plus a Query at protocol revision 54449) to reach thereceiveHellounknown-cluster reject, the no-salt reject and the hash mismatch; the last one carries a decoyX-Forwarded-Forinside the Query packet. Without the change the three cases fail (the rows carry the runner's address); with it, the whole module passes 10 times in a row. Making the helper callgetClientAddress, or the hash-mismatch site read the packet'sClientInfo, fails the existing malformed-address test and the decoy case respectively.Workflow [PR]
Sync PR [sync-upstream/pr/125326]
Version info
26.10.1.2225-master(included in26.10and later)