Skip to content

Accept a server certificate that names --host when --tls-sni-override is set - #125407

Closed
groeneai wants to merge 3 commits into
ClickHouse:masterfrom
groeneai:fix-tls-sni-override-verify-host
Closed

groeneai wants to merge 3 commits into
ClickHouse:masterfrom
groeneai:fix-tls-sni-override-verify-host

Conversation

@groeneai

@groeneai groeneai commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #116724
Related: #119544

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):

Fixed clickhouse client --secure --tls-sni-override <name> failing with Unacceptable certificate from <name> when the server certificate names the host given in --host but not the override, as in the ClickHouse Cloud replica-aware routing example. Since server certificate hostnames are verified by default, the override was the only name checked; now a certificate that names either the override or the host is accepted.

Description

On 26.9.9.28 (also 26.8.18.2 and 26.3.42.3), clickhouse client --secure --host <service> --tls-sni-override <name> fails with Code: 210 ... Unacceptable certificate from <name>: application verification failure although the server certificate names <service>. This breaks the documented replica-aware routing example (--tls-sni-override my-workload-1.sticky.<host>, where the certificate covers only <host>). 26.8.2.7, from before the #116724 backport, connects.

Poco used one field, _peerHostName, both as the SNI value and as the name the certificate is verified against, so the override became the only verification name. #116724 turned the name check on for clients, which exposed it.

Poco now keeps the SNI name separately (setServerNameIndication, plus an attach overload for the socket the port probe hands over), and both secure Connection paths use it. With an override, the certificate is checked against it exactly as before; if that fails, it is accepted when it names the host connected to, by a plain name match without the loopback exemption (a --host localhost tunnel still needs a certificate that names the override or localhost).

Verifying only --host would break the other documented use: #116724's changelog tells users whose endpoint the certificate does not name (an IP address, for example) to pass --tls-sni-override with the name the certificate was issued for, and test_accept_invalid_certificate and test_ssl_cert_authentication pin that setup. Both setups now work, and nothing that master rejects for another reason is accepted.

05366_client_tls_sni_override_verifies_host fails on master and passes with the fix; it also checks that a certificate naming neither name is still rejected.


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

groeneai and others added 2 commits October 12, 2026 12:03
… is set

`clickhouse client --secure --host <service> --tls-sni-override <name>` failed with
`Unacceptable certificate from <name>: application verification failure` when the
server certificate names `<service>` but not `<name>`, which is the documented
replica-aware routing setup (the certificate covers `<host>`, the SNI carries
`<workload>.sticky.<host>`).

Poco kept one name per client socket, `_peerHostName`, and used it both as the SNI
value and as the name the certificate is verified against. `Connection` put the
override there to get it into SNI, so the override became the only verification name.
That was harmless while the client default was `extendedVerification = false`; ClickHouse#116724
turned the name check on for clients and exposed it.

Poco now keeps the SNI name separately (`setServerNameIndication`, and an `attach`
overload for the socket the port probe hands over), and both secure `Connection`
paths set the peer host name to `--host` and the SNI name to the override. With an
override, the certificate is first checked against it exactly as before, including
the loopback exemption; if that fails, it is accepted when it names the host connected
to. The accepted set is therefore master's plus "the certificate names the host that
was connected to", the invariant ClickHouse#116724 introduced; nothing master rejects for
another reason is accepted.

The host fallback is a plain name match without the loopback exemption: with
`--host localhost --tls-sni-override <svc>` (an SSH tunnel) master verifies the
certificate against `<svc>`, and an exempt fallback would accept any CA-signed
certificate on such an endpoint.

Sockets that never set a server name (server-accepted sockets, Keeper, HTTPS
sessions) run the old code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the new Poco SNI API docs to one line each, drop the duplicated accept-set note on verifyPeerCertificate() and the self-evident matchPeerCertificate() doc.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet labels Oct 12, 2026
@groeneai

This comment was marked as off-topic.

@groeneai

This comment was marked as off-topic.

@groeneai
groeneai requested review from azat and thevar1able October 12, 2026 12:29
@clickhouse-gh

clickhouse-gh Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [db4fd87]

Summary: ❌

job_name test_name status info comment
Integration tests (arm_binary, 1/4) FAIL
test_storage_delta/test.py::test_writes_timestamp_ntz_annotation_nested FAIL cidb
test_storage_delta/test_writes_interop.py::test_write_to_table_with_unsupported_writer_feature_is_rejected FAIL cidb

AI Review

Summary

This PR fixes a real client regression introduced when hostname verification was enabled by default: --tls-sni-override no longer replaces the verification target, so secure client connections now accept a certificate that names either the override or the actual --host. The implementation cleanly separates SNI from certificate verification in both secure connection entrypoints, preserves the existing override-only use case, and adds regression coverage for both the direct secure connect path and the adoptSocket handoff used by secure-port auto-detection.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Oct 12, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-cli clickhouse-client (interactive CLI) and client library. label Oct 12, 2026
@azat azat self-assigned this Oct 12, 2026

@azat azat 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.

I am not sure that this is a good idea

  • now certificate for --host will work, which open some "opportunities"
  • and it will work only in clickhouse-client

But honestly I don't understand why this is required sticky routing has wildcard certificates

Without `--port` and `--secure` the client probes both ports and the
`Connection` takes over the probed socket (`Connection::adoptSocket`), the
second secure path the fix changes. Plain port 0 always refuses, so the
probe picks the secure port. One case checks the certificate is accepted
for `--host` there (the trace line proves the socket was reused), the other
that the reused socket carries the override as its server name: without it
the loopback exemption would accept `127.0.0.1`. Reverting only the
`adoptSocket` change, or only the `setServerNameIndication` call in the new
`attach` overload, fails exactly one of them.

Also write `setServerNameIndication` without parentheses in its comment.

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

Copy link
Copy Markdown
Collaborator Author

Why it is needed: the Cloud certificates are one-label wildcards. In crt.sh, every unexpired certificate for us-east-1, us-west-2, eu-west-1 (aws) and us-central1 (gcp) names only *.<region>.<cloud>.clickhouse.cloud and the region apex. That covers <id>.us-east-1.aws.clickhouse.cloud, but not my-workload-1.sticky.<id>.us-east-1.aws.clickhouse.cloud. Since #116724 the client checks the certificate against the override, so the documented native routing example cannot pass that check on the releases that carry the backport (26.3, 26.7, 26.8, 26.9). The first revision of #119544 said the same: "The regular certificate doesn't cover the sticky hostname".

On your two points:

  • The only name added is --host, matched exactly without the loopback exemption, so it never accepts more than clickhouse client --host <host> already accepts without the override. Where it is weaker than master: an SNI passthrough proxy at --host that holds a certificate for its own name could terminate the connection instead of forwarding it to the override.
  • Yes, the flag exists only in clickhouse-client. Other drivers have to verify against the service host themselves (that first revision showed it for Go).

If that trade-off is not acceptable, the fix belongs in the certificate: cover the sticky names, which also fixes every other driver, and I close this PR. Which do you prefer?

@groeneai

This comment was marked as off-topic.

@rschu1ze

Copy link
Copy Markdown
Member

Looks like we fixed the problem in the meantime by reverting the culprit PR: #125569

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-cli clickhouse-client (interactive CLI) and client library. groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet pr-bugfix Pull request with bugfix, not backported by default v26.8-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants