RoanHeNaN opened a new pull request, #71290:
URL: https://github.com/apache/doris/pull/71290

   ### Background
   
   With `enable_https = true`, the FE web server serves https on `https_port` 
through Spring Boot's embedded Jetty, and the http port redirects `/metrics`, 
`/api/*`, `/rest/*` and a few other paths to https. Spring Boot builds the 
https connector with Jetty's `SecureRequestCustomizer`, whose `sniHostCheck` is 
on by default: it answers `400 Invalid SNI` when the request's Host does not 
match the server certificate. Since #57710 moved the FE from Jetty 9.4 to Jetty 
12, the check also runs when the client sends no SNI, which is what curl and Go 
clients do when the URL is an IP.
   
   ### What problem does this PR solve?
   
   Issue Number: None
   Related PR: #57710 (moved the FE to Jetty 12, where the Host check also runs 
without SNI)
   PR Type: Enhancement
   
   Problem Summary:
   
   A certificate usually names the cluster's host name, not each FE's IP, so a 
client that reaches an https FE by IP gets `400 Invalid SNI`, even with 
certificate verification skipped. A metrics agent on the FE host is the common 
case: `http://127.0.0.1:8030/metrics` redirects to 
`https://127.0.0.1:8050/metrics`, which answers 400, so the agent loses the FE 
metrics once https is on. This PR adds the FE config 
`enable_https_sni_host_check`, set in `fe.conf` and read at startup; `false` 
turns the Host check off on the https connector. The default is `true`, so an 
upgraded cluster behaves exactly as before.
   
   On an FE with https on and a certificate that names only its host name:
   
   ```
   $ curl -sk https://127.0.0.1:8050/metrics | head -5
   <html>
   <head>
   <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
   <title>Error 400 Invalid SNI</title>
   </head>
   ```
   
   | Request over https, by IP, no SNI | Default (`true`) | 
`enable_https_sni_host_check = false` |
   |---|---|---|
   | `Host: 127.0.0.1:<port>` | 400 | 200 |
   | `Host: <certificate host>:<port>` | 200 | 200 |
   
   ### Details
   
   - **Before and after:** Before, and after with the default: an https request 
whose Host is not in the server certificate, such as one sent by IP, gets `400 
Invalid SNI`. After, with `enable_https_sni_host_check = false`: the request is 
served as usual. TLS itself does not change: the FE still presents its 
certificate, so a client that connects by IP must trust it or skip verifying it 
(`curl -k`, or `skip_tls_verify` in a metrics agent).
   - **Configs and defaults:** New FE config `enable_https_sni_host_check`, 
boolean, default `true`. Set in `fe.conf`; not mutable at runtime, since the 
web server's connectors are configured once at startup.
   - **Impact on existing users:** None by default. A cluster that sets it to 
`false` accepts https requests whose Host is not in the certificate. That is 
how Jetty 9.4, before #57710, treated a client that sends no SNI.
   
   ### Testing
   
   - `./run-fe-ut.sh --run 
org.apache.doris.http.HttpsSniHostCheckTest,org.apache.doris.http.HttpServerCompatibilityTest`,
 locally on master (base 1e5b268a591): 7 tests, 0 failures. 
`HttpsSniHostCheckTest` (new) starts the FE web configuration over https with a 
certificate generated at run time that names only a host name, and connects by 
IP without SNI; it gives the results in the table above. 
`HttpServerCompatibilityTest` covers the plain http behavior and still passes.
   - With the `applySniHostCheck(...)` call removed, 
`HttpsSniHostCheckTest.acceptsHostNotInCertificateWhenCheckDisabled` fails with 
`expected: <200> but was: <400>`.
   - The 400 above was reproduced with curl on an FE of the branch-4.0 line 
(Jetty 12.0.38, Spring Boot 3.5.16); the patched build was not deployed there.
   
   ### Notes for Reviewers
   
   - The flag is set from the server customizer that already applies the header 
size limits to every connector. In Spring Boot 3.5 and 4.1 alike, 
`JettyServletWebServerFactory.getWebServer` runs `customizeSsl` (which creates 
the https connector with its `SecureRequestCustomizer`) before the factory's 
server customizers, so the customizer is there when https is on. A plain http 
connector has no `SecureRequestCustomizer`, hence the null check.
   - The test generates its key store with the JDK's `keytool` at run time, so 
no key material is committed, and uses a raw `SSLSocket` that trusts only that 
certificate and does not verify host names, so that the request by IP reaches 
the server-side check.
   
   ### Release note
   
   Add the FE config `enable_https_sni_host_check` (default `true`). Set it to 
`false` in `fe.conf` to allow https access to the FE by an address that is not 
in the server certificate, such as `https://127.0.0.1:8050/metrics` from a 
local metrics agent.
   
   ### Check List (For Author)
   
   - Behavior changed: No
   - Does this need documentation: Yes (the new config in the FE configuration 
docs; an apache/doris-website PR will follow)
   - Pre-submission status: Partially verified: not run on branch-4.0 or on a 
deployed FE; a comment-only edit in `WebServerFactoryCustomizerConfig` came 
after the test runs
   
   ### AI Disclosure
   
   - Tool: Claude Code (Claude Opus 5.5)
   - Generated: the code, the test, and this description
   - Human review: not stated
   - Prompts: The author reported that a metrics agent on an FE host stopped 
getting FE metrics after https was enabled and asked for the cause; after the 
analysis, asked for an FE config that keeps today's behavior by default and, 
when changed, skips the Host check.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to