ZOOKEEPER-5029: Port unification for PrometheusMetricsProvider#2362
ZOOKEEPER-5029: Port unification for PrometheusMetricsProvider#2362PDavid wants to merge 1 commit intoapache:masterfrom
Conversation
TestingTested this locally as follows: Created keystore: Created truststore: Added these to Started ZooKeeper: ZooKeeper log: Call PrometheusMetricsProvider using http: Call PrometheusMetricsProvider using https: |
9dcea19 to
a6c4741
Compare
a6c4741 to
1c3e4dd
Compare
|
Rebased the branch on latest master to resolve conflicts. |
|
|
||
| if (this.httpPort != -1 && this.httpsPort != -1 && this.httpPort == this.httpsPort) { | ||
| SecureRequestCustomizer customizer = new SecureRequestCustomizer(); | ||
| customizer.setStsMaxAge(DEFAULT_STS_MAX_AGE); |
There was a problem hiding this comment.
STS means the Strict-Transport-Security HTTP response header.
The HTTP Strict-Transport-Security response header (often abbreviated as HSTS) informs browsers that the host should only be accessed using HTTPS, and that any future attempts to access it using HTTP should automatically be upgraded to HTTPS. Additionally, on future connections to the host, the browser will not allow the user to bypass secure connection errors, such as an invalid certificate. HSTS identifies a host by its domain name only.
...
max-age=<expire-time>
The time, in seconds, that the browser should remember that a host is only to be accessed using HTTPS.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Strict-Transport-Security
This is implemented here the same way as we have it in JettyAdminServer:
https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/main/java/org/apache/zookeeper/server/admin/JettyAdminServer.java#L119
| if (this.httpPort != -1 && this.httpsPort != -1 && this.httpPort == this.httpsPort) { | ||
| SecureRequestCustomizer customizer = new SecureRequestCustomizer(); | ||
| customizer.setStsMaxAge(DEFAULT_STS_MAX_AGE); | ||
| customizer.setStsIncludeSubDomains(true); |
There was a problem hiding this comment.
We might need to add some comments to briefly explain what is this about.
There was a problem hiding this comment.
This sets a directive of the Strict-Transport-Security HTTP response header.
includeSubDomains Optional
If this directive is specified, the HSTS policy applies to all subdomains of the host's domain as well.
Same as we have in JettyAdminServer here:
| new HttpConnectionFactory(config)); | ||
| connector.setPort(this.httpPort); | ||
| connector.setHost(this.host); | ||
| LOG.debug("Created unified ServerConnector for host: {}, httpPort: {}", host, httpPort); |
There was a problem hiding this comment.
You can move these messages to INFO level. We should see clearly which type of server has been initialized.
JettyAdminServerhas a port unification feature, meaning both secure and insecure connections can be established on the same port. It can be enabled with theadmin.portUnification=trueconfiguration setting.In order to make it more consistent,
PrometheusMetricsProvidercan also provide such feature whenmetricsProvider.httpPortandmetricsProvider.httpsPortare configured to the same value.