Repository navigation
Verify the server certificate hostname on outbound TLS connections - #116724
alexey-milovidov merged 2 commits into
Conversation
Outbound TLS validated the certificate chain but never checked that the certificate identified the host being connected to, so any CA-signed certificate for any name was accepted for any host. Reproduced against a server presenting a certificate for `not-localhost` and reached at a non-loopback address under a default client configuration: `SELECT 1` returned `1` before this change and now fails with `Code: 210 ... Unacceptable certificate from <host>: application verification failure`. `SSLManager::initDefaultContext(bool server)` picks its prefix at `SSLManager.cpp:241` and runs once per default context, so the single `false` default at `:345` reached the default client context as well as the server one. With extended verification off, `SecureSocketImpl::verifyPeerCertificateImpl` returns `X509_V_OK` at `SecureSocketImpl.cpp:465-467` before reaching `X509_check_host` or `X509_check_ip_asc`, and nothing calls `SSL_set1_host`. That `false` was the only place in the layer turning the check off: all three `Context` constructors default `_extendedCertificateVerification(true)`. The default is now `!server`. It must not flip for the server context. On an accepted socket `_peerHostName` is empty, so the check runs against the client's address, while a client certificate names a user. Measured: with `openSSL.server.extendedVerification` set to `true`, which produces the same context state a bare `true` would, a client presenting a `CN=client1` certificate is rejected with `Unacceptable certificate from 10.33.45.204` under `relaxed` and additionally from `127.0.0.1` under `strict`. That is `ssl_certificate` authentication broken. With `!server` and the key absent, the same client connects in both modes. Correcting the boundary covers every caller of the default client context: pooled HTTPS, the native secure protocol, JWT, and the Silk socket factory all set a peer host name already. One carrier could not benefit, so it is fixed here too. `ZooKeeper::connect` built a bare `SecureStreamSocket` and never called `setPeerHostName`, then connected to a pre-resolved address, so `verifyPeerCertificate()` fell back to `peerAddress().host().toString()` and verified the resolved IP. Measured against a local Keeper over TLS whose certificate names the host by DNS name only: the same configuration failed with `Unacceptable certificate from 127.0.1.1` and now succeeds. Carrying the name is also what puts the host into the SNI extension, which that path did not send. `node.host` is `"<host>:<port>"`, so the name has to be extracted. `DB::parseAddress` is not used: it requires a numeric port, and its IPv6 branch keeps the brackets, which `X509_check_host` would never match. The helper mirrors Poco's own lexical split and never inspects the port, so no host:port shape that resolves today changes. Verified against `Poco::Net::SocketAddress` for IPv4, bracketed IPv6, a DNS name and a port spelled as a service name by reconstructing the input from the helper's answer and requiring Poco's `port()` to equal an independent resolution of the remaining suffix. `SocketAddress::host()` is not a valid oracle here because it returns the resolved address. `openssl_client_extended_verification` in `ServerSettings.cpp` moves with the literal. Nothing reads it, but it is the source of the default shown in `system.server_settings` and in the generated reference page, so leaving it would publish `false` for behaviour that is `true`. `SettingsChangesHistory.cpp` holds query settings only and contains no server settings, so no entry there is possible. Four CI sites verify a certificate that does not name the address they dial, out of 71 `openSSL/client` blocks in the tree, 56 of which are immune because they set `verificationMode` to `none`. Note that `AcceptCertificateHandler` is not an off switch: it is consulted from OpenSSL's chain-verify callback, while extended verification throws directly from `SecureSocketImpl`. `test_ssl_cert_authentication` sets `tls-sni-override` to the host it already declares in `SSL_HOST`, which makes its native path agree with the hostname checking it already forces on its Python path. `test_bind_host` and both `test_acme_tls` configs opt out, the latter because Pebble's serving certificate names `localhost`, `pebble` and `127.0.0.1` while the test dials a pinned `10.5.11.2`. New coverage: three arms in `test_accept_invalid_certificate` using the existing CA-signed `client-cert.pem`, for a name mismatch being rejected, `tls-sni-override` being accepted, and `extendedVerification=false` still being honoured; and one arm in `test_keeper_secure_client` whose client actually verifies. That suite's `server.crt` had to be regenerated because it was `CN=localhost` with no SAN while the test connects to `node1`; the new pair keeps `CN=localhost`, self-signed, `CA:TRUE` and RSA-2048, adds `subjectAltName = DNS:localhost, DNS:node1`, and `generate_certs.sh` records how. Closes: ClickHouse#35504
The shared "Keys for server/client settings" table is a hand-maintained generator input (`autogenerate_docs.py:185-187` lists it under `deps` and `global-server-settings.sql:11` reads it with `file(..., RawBLOB)`), so it carries no autogenerated region and nothing rewrites this cell. Left at `false` it would contradict the generated per-setting page, which the nightly derives from the `DECLARE` and will render as `true` for the client setting, and it would misinform the operators the backward incompatible changelog entry is aimed at. The server default is unchanged, so the cell names both.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 4 findings over 1 full pass and
Two corrections to the commit message of No integration suite could be executed on the machine that prepared this PR, because docker Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20260827-125900 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20260827-110200 |
|
Workflow [PR], commit [3c90c93] Summary: ✅
AI ReviewSummaryThis PR enables hostname verification by default for the default outbound TLS client context, carries the configured host name into secure Keeper connections so verification checks the configured host instead of the resolved address, and updates the affected tests and docs. I did not find a correctness, safety, or compatibility issue in the current diff after tracing the default client-context callers, the Keeper path, the new regression coverage, and the current green CI reports. Final Verdict✅ No blocking findings. LLVM Coverage ReportMeasured on commit 3c90c93.
Changed lines: Changed C/C++ lines covered: 16/19 (84.21%) · Uncovered code |
|
cc @santrancisco @michael-anastasakis @Michicosun, could you review this? It turns hostname verification on for the default client context only ( |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units11 translation units recompiled, 39 s compile time in total, 11 of them have a recent master baseline. |
CI finish ledger - 3c90c93CI is fully finished at this head and no check failed, so no ledger row is owed. Evidence: 175 unique check runs on the PR workflow run ( Session id: cron:our-pr-ci-monitor:20260827-190000 |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
c67f0b1
…utbound TLS connections
Backport #116724 to 26.9: Verify the server certificate hostname on outbound TLS connections
Backport #116724 to 26.7: Verify the server certificate hostname on outbound TLS connections
Backport #116724 to 26.8: Verify the server certificate hostname on outbound TLS connections
Resolved the single conflict, in `src/Common/ZooKeeper/ZooKeeperImpl.cpp`. Master adds the new `peerHostName` helper to an anonymous namespace that also holds `triggerWatchCallback`, a master-only function 26.3 does not have, so taking master's side wholesale would have imported it along with `ZooKeeperWatchCallbackDurationMicroseconds` and `ZooKeeperWatchCallbackErrors`, which the branch does not declare. Only `peerHostName` and its `setPeerHostName` call site were taken; the rest of the file is the branch's. Everything else applied cleanly. The docs row landed in 26.3's `docs/en/operations/server-configuration-parameters/_server_settings_outside_source.md`, which master has since renamed to an `.mdx` under `docs/reference`. Checked the branch's own test set for the flipped `openSSL.client.extendedVerification` default: the only integration configs that still verify and carry no opt-out are `test_config_xml_main`, `test_config_xml_yaml_mix`, `test_https_replication`, `test_ssl_cert_authentication` and `test_tlsv1_3`, and each one's client section is identical to master's, so none needs a 26.3-specific adjustment. The prerequisites the new tests rely on are present on the branch: `tls-sni-override` with `setPeerHostName` in `Connection.cpp`, `SSL_HOST` in `test_ssl_cert_authentication`, the CA-signed `CN=client` certificate with no SAN in `test_accept_invalid_certificate/certs`, and `<host>node1</host>` in `test_keeper_secure_client/configs/use_secure_keeper.xml`, which the regenerated certificate now names in its `subjectAltName`. Original pull-request #116724 Cherry-pick pull-request #121185 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…utbound TLS connections
Backport #116724 to 26.3: Verify the server certificate hostname on outbound TLS connections
…tname on outbound TLS connections
…tname on outbound TLS connections
`test_tls13_client_cipher_suites` connects between instances with
`remoteSecure('<instance>:9440', ...)`, while the module's `server-cert.pem`
names only `integration-tests.clickhouse.com`. Since ClickHouse#116724 the default
client context checks that the certificate names the host being dialed, so
with that change merged every connection in the arm fails before the cipher
suites matter:
Certificate validation error: Unacceptable certificate from
node_with_cipher_suites: application verification failure
The arm asserts which TLS 1.3 suites a client offers, not the identity of the
peer, so the module's `openSSL.client` section sets `extendedVerification` to
`false`, as ClickHouse#116724 did for `test_bind_host` and `test_acme_tls`. The chain is
still verified against the test CA.
Measured with the CI `amd_asan_ubsan` binary of this head (merge commit
5e6ee40): the arm fails with the error above without the change and
passes with it, 10 out of 10, and the whole module passes.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Edited by the nightly changelog CI job following .claude/skills/edit-changelog/SKILL.md. Changelog-revert: 125458 125455 Revert "Revert "Iceberg variant type"" Changelog-revert: 125463 110114 Revert "Push filters below WindowStep on PARTITION BY columns" Changelog-revert: 125569 116724 Revert "Verify the server certificate hostname on outbound TLS connections" Changelog-revert: 125652 123834 Revert "Look up both signed zeros in a bloom_filter index" Changelog-deleted-entry: 116724 [Backward Incompatible Change] [section] * Outbound TLS connections now verify that the server certificate names the host that was connected to. This affects `clickhouse-client --secure`, `remoteSecure`, `Distributed` over the secure native protocol, secure `Keeper` connections, and HTTPS clients such as `s3`, `url`, HTTP dictionaries, and JWT token endpoints. Connecting to an endpoint whose certificate does not name it, for example an IP address with no matching SAN, an S3-compatible gateway fronted by a different name, or an internal CA with missing SANs, now fails with `Unacceptable certificate`. Set `openSSL.client.extendedVerification` to `false` to restore the previous behavior, or pass `--tls-sni-override` to name the host the certificate was issued for. Loopback addresses stay exempt unless `verificationMode` is `strict`, and the default for `openSSL.server.extendedVerification` is unchanged. [#116724](#116724) ([Groene AI](https://github.com/groeneai)). Changelog-deleted-entry: 123834 [Bug Fix (user-visible misbehavior in an official stable release)] [section] * Fixed a `bloom_filter` index on a float column skipping rows with the other signed zero, for example `-0.0` for `WHERE f = 0`. It affected `equals`, `has`, `hasAny`, `hasAll`, `mapContainsKey`, `mapContainsValue`, and map element comparisons, including `m[k] IN (...)`. [#123834](#123834) ([Ashish Kumar Choubey](https://github.com/aschoube)).
|
@groeneai This change makes every outbound TLS handshake do a DNS lookup, and it slowed down the cold queries of the On
|
|
Acknowledged. I'm investigating the cold-query slowdown of |
|
I opened #132627 to fix it. The hostname check evaluated the loopback exemption ( Measured locally: cold ClickBench Q37 against a |
Since `openSSL.client.extendedVerification` is on by default (ClickHouse#116724, relanded by ClickHouse#126138), `SecureSocketImpl::verifyPeerCertificateImpl` evaluated the loopback exemption `isLocalHost(hostName)` before `X509_check_host`. `isLocalHost` builds `SocketAddress(hostName, 0)`, which for a host name calls an uncached `getaddrinfo`, so every outbound TLS handshake did one DNS lookup that the TCP connect (served by the cached `DNSResolver`) never needed. A cold query over a `web` or `s3` disk opens many new HTTPS connections, so the lookups add up. The exemption only matters when the certificate does not name the host; check it only then. The result is the same for every certificate: the same default, the same loopback exemption, and `strict` mode still never exempts. Reported in ClickHouse#116724 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Outbound TLS connections now verify that the server certificate names the host that was connected to. This affects
clickhouse-client --secure,remoteSecure(),Distributedover the secure native protocol, secure Keeper connections, and HTTPS clients such ass3(),url(), HTTP dictionaries and JWT token endpoints. Connecting to an endpoint whose certificate does not name it, for example an IP address with no matching SAN, an S3-compatible gateway fronted by a different name, or an internal CA with missing SANs, now fails withUnacceptable certificate. SetopenSSL.client.extendedVerificationtofalseto restore the previous behaviour, or pass--tls-sni-overrideto name the host the certificate was issued for. Loopback addresses stay exempt unlessverificationModeisstrict, and the default foropenSSL.server.extendedVerificationis unchanged.Description
Closes: #35504
Outbound TLS connections validated the certificate chain but never checked that the certificate identified the host being connected to, so any CA-signed certificate for any name was accepted for any host.
One literal caused it.
SSLManager.cpp:345defaultedextendedVerificationtofalse, which madeverifyPeerCertificateImplreturnX509_V_OKbefore reachingX509_check_host. It is the only place in the NetSSL layer that turns the check off: all threeContextconstructors default it totrue.The default now depends on the prefix,
!server. It must not flip for the server context: on an accepted socket there is no requested host name, so the check would run against the client's address, and a client certificate names a user. I measured that a baretruerejects aCN=client1certificate withUnacceptable certificate from <client IP>, which would breakssl_certificateauthentication; with!serverthe same mTLS client connects.Fixing the boundary covers every caller of the default client context. One of them could not benefit: the secure Keeper client never set a peer host name, so it verified the resolved IP rather than the configured host. It now carries the name, which also puts the host into SNI, something that path did not send before.
Four CI sites verify a certificate that does not name the address they dial. Three opt out where peer identity is not what the test is about;
test_ssl_cert_authenticationinstead setstls-sni-overrideto the host it already declares.@ alexey-milovidov asked for this default on #35504, raising it for
clickhouse-client, and judged the compatibility risk acceptable there. The issue is unassigned; @ kaijaytu offered to take it on 2026-08-03 and I am happy to hand over.Workflow [PR]
Sync PR [sync-upstream/pr/116724]
Version info
26.10.1.268-master(included in26.10and later)26.9.1.1621,26.8.10.6,26.7.14.2,26.3.33.122