Repository navigation
Cherry pick #116724 to 26.3: Verify the server certificate hostname on outbound TLS connections - #121185
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: #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.
…-hostname Verify the server certificate hostname on outbound TLS connections
|
The conflict is one file,
Everything else auto-merges, including the docs row, which lands on 26.3's I verified it on the 26.3 tree rather than just making it merge. It builds clean with clang-21, the toolset 26.3 pins, and the ported tests pass there: and on pristine 26.3 @alexey-milovidov, I hold
|
Original pull-request #116724
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job