|
20 | 20 |
|
21 | 21 | import static org.apache.zookeeper.common.LogRedactor.redactSensitiveValues; |
22 | 22 | import io.prometheus.metrics.core.metrics.GaugeWithCallback; |
23 | | -import io.prometheus.metrics.exporter.servlet.javax.PrometheusMetricsServlet; |
| 23 | +import io.prometheus.metrics.exporter.servlet.jakarta.PrometheusMetricsServlet; |
24 | 24 | import io.prometheus.metrics.instrumentation.jvm.JvmMetrics; |
25 | 25 | import io.prometheus.metrics.model.registry.PrometheusRegistry; |
| 26 | +import jakarta.servlet.ServletException; |
| 27 | +import jakarta.servlet.http.HttpServletRequest; |
| 28 | +import jakarta.servlet.http.HttpServletResponse; |
26 | 29 | import java.io.IOException; |
27 | 30 | import java.security.GeneralSecurityException; |
28 | 31 | import java.security.KeyStore; |
|
37 | 40 | import java.util.concurrent.TimeUnit; |
38 | 41 | import java.util.concurrent.atomic.AtomicInteger; |
39 | 42 | import java.util.function.BiConsumer; |
40 | | -import javax.servlet.ServletException; |
41 | | -import javax.servlet.http.HttpServletRequest; |
42 | | -import javax.servlet.http.HttpServletResponse; |
43 | 43 | import org.apache.zookeeper.common.X509Util; |
44 | 44 | import org.apache.zookeeper.metrics.Counter; |
45 | 45 | import org.apache.zookeeper.metrics.CounterSet; |
|
51 | 51 | import org.apache.zookeeper.metrics.Summary; |
52 | 52 | import org.apache.zookeeper.metrics.SummarySet; |
53 | 53 | import org.apache.zookeeper.server.admin.UnifiedConnectionFactory; |
| 54 | +import org.eclipse.jetty.ee10.servlet.ServletContextHandler; |
| 55 | +import org.eclipse.jetty.ee10.servlet.ServletHolder; |
54 | 56 | import org.eclipse.jetty.http.HttpVersion; |
55 | 57 | import org.eclipse.jetty.server.HttpConfiguration; |
56 | 58 | import org.eclipse.jetty.server.HttpConnectionFactory; |
57 | 59 | import org.eclipse.jetty.server.SecureRequestCustomizer; |
58 | 60 | import org.eclipse.jetty.server.Server; |
59 | 61 | import org.eclipse.jetty.server.ServerConnector; |
60 | | -import org.eclipse.jetty.servlet.ServletContextHandler; |
61 | | -import org.eclipse.jetty.servlet.ServletHolder; |
62 | | -import org.eclipse.jetty.util.resource.Resource; |
| 62 | +import org.eclipse.jetty.server.SslConnectionFactory; |
| 63 | +import org.eclipse.jetty.util.resource.ResourceFactory; |
63 | 64 | import org.eclipse.jetty.util.ssl.KeyStoreScanner; |
64 | 65 | import org.eclipse.jetty.util.ssl.SslContextFactory; |
65 | 66 | import org.eclipse.jetty.util.thread.QueuedThreadPool; |
@@ -234,6 +235,10 @@ public void start() throws MetricsProviderLifeCycleException { |
234 | 235 | customizer.setStsMaxAge(DEFAULT_STS_MAX_AGE); |
235 | 236 | // Strict-Transport-Security HTTP header should apply to all subdomains of the host's domain as well. |
236 | 237 | customizer.setStsIncludeSubDomains(true); |
| 238 | + // The metrics port does not multiplex virtual hosts, so there is no |
| 239 | + // SNI name to match against. Jetty 10+ defaults this check to true, |
| 240 | + // which rejects connections made to a bare IP address or to localhost. |
| 241 | + customizer.setSniHostCheck(false); |
237 | 242 |
|
238 | 243 | HttpConfiguration config = new HttpConfiguration(); |
239 | 244 | config.setSecureScheme("https"); |
@@ -356,7 +361,7 @@ private SslContextFactory.Server createSslContextFactory() throws GeneralSecurit |
356 | 361 | sslContextFactory.setKeyStorePassword(this.keyStorePassword); |
357 | 362 |
|
358 | 363 | // This is needed for KeyStoreScanner to work. |
359 | | - sslContextFactory.setKeyStoreResource(Resource.newResource(this.keyStorePath)); |
| 364 | + sslContextFactory.setKeyStoreResource(ResourceFactory.of(this.server).newResource(this.keyStorePath)); |
360 | 365 |
|
361 | 366 | // Validate and set TrustStore properties (often needed for client auth) |
362 | 367 | if (this.needClientAuth && (this.trustStorePath == null || this.trustStorePath.isEmpty())) { |
@@ -406,7 +411,23 @@ private SslContextFactory.Server createSslContextFactory() throws GeneralSecurit |
406 | 411 | */ |
407 | 412 | private ServerConnector createSslConnector(Server server, int acceptors, int selectors, |
408 | 413 | SslContextFactory.Server sslContextFactory) { |
409 | | - ServerConnector sslConnector = new ServerConnector(server, acceptors, selectors, sslContextFactory); |
| 414 | + // Spelled out rather than left to the implicit HttpConfiguration, whose |
| 415 | + // SecureRequestCustomizer defaults to sniHostCheck=true and would reject |
| 416 | + // requests to a bare IP address or to localhost. Setting it up here also |
| 417 | + // gives this connector the same Strict-Transport-Security header as the |
| 418 | + // unified one. |
| 419 | + SecureRequestCustomizer customizer = new SecureRequestCustomizer(); |
| 420 | + customizer.setStsMaxAge(DEFAULT_STS_MAX_AGE); |
| 421 | + customizer.setStsIncludeSubDomains(true); |
| 422 | + customizer.setSniHostCheck(false); |
| 423 | + |
| 424 | + HttpConfiguration config = new HttpConfiguration(); |
| 425 | + config.setSecureScheme("https"); |
| 426 | + config.addCustomizer(customizer); |
| 427 | + |
| 428 | + ServerConnector sslConnector = new ServerConnector(server, acceptors, selectors, |
| 429 | + new SslConnectionFactory(sslContextFactory, HttpVersion.fromVersion(httpVersion).asString()), |
| 430 | + new HttpConnectionFactory(config)); |
410 | 431 | sslConnector.setPort(this.httpsPort); |
411 | 432 | sslConnector.setHost(this.host); |
412 | 433 | return sslConnector; |
|
0 commit comments