Skip to content

HIVE-29636: Add SSL keystore auto-reloading for HiveServer2 WebUI#6514

Open
magnuma3 wants to merge 3 commits into
apache:masterfrom
magnuma3:ssl-auto-reload
Open

HIVE-29636: Add SSL keystore auto-reloading for HiveServer2 WebUI#6514
magnuma3 wants to merge 3 commits into
apache:masterfrom
magnuma3:ssl-auto-reload

Conversation

@magnuma3
Copy link
Copy Markdown

HIVE-29636

What changes were proposed in this pull request?

HiveServer2 WebUI's SslContextFactory is built once at startup, so renewing the SSL keystore requires restarting HS2

Watch the keystore file with Hadoop's FileMonitoringTimerTask and call SslContextFactory#reload(...) on mtime change. The daemon Timer is installed when SSL is on and is cancelled in HttpServer#stop(). Reload failures are logged and swallowed

Same pattern as HADOOP-16524, reusing its FileMonitoringTimerTask

Why are the changes needed?

Rotating WebUI SSL certificates currently requires an HS2 restart, which is increasingly painful as certificate lifetimes shorten. Hadoop's HttpServer2 already solved this via HADOOP-16524.

Does this PR introduce any user-facing change?

Yes — new opt-in ConfVar hive.server2.webui.keystore.reload.interval (default 60s, 0 disables). When the keystore file changes, the running HS2 picks up the new certificate within the interval; no restart needed. No API or schema changes.

How was this patch tested?

Added TestHttpServer

Comment thread common/src/java/org/apache/hive/http/HttpServer.java Outdated
@magnuma3
Copy link
Copy Markdown
Author

magnuma3 commented Jun 1, 2026

test failure is not related to this patch.

Comment thread common/src/java/org/apache/hive/http/HttpServer.java Outdated
Comment thread common/src/java/org/apache/hive/http/HttpServer.java Outdated
Comment thread common/src/java/org/apache/hive/http/HttpServer.java Outdated
Comment thread common/src/java/org/apache/hive/http/HttpServer.java Outdated
Comment thread common/src/java/org/apache/hive/http/HttpServer.java Outdated
@magnuma3
Copy link
Copy Markdown
Author

magnuma3 commented Jun 1, 2026

@deniskuzZ thank you for review. addressed all the comments.

Copy link
Copy Markdown
Member

@deniskuzZ deniskuzZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM +1
cc @dengzhhu653

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for automatically reloading the HiveServer2 WebUI SSL keystore at runtime (without restarting HS2) by scheduling a periodic file monitor and invoking Jetty’s SslContextFactory#reload(...) when the keystore changes. It also introduces a new configuration knob to control/disable the reload interval and adds unit tests covering the new monitoring and shutdown behavior.

Changes:

  • Add hive.server2.webui.keystore.reload.interval (default 60s) to control periodic keystore change checks.
  • Wire a Timer + Hadoop FileMonitoringTimerTask into HttpServer when WebUI SSL is enabled, and cancel it during HttpServer#stop().
  • Add TestHttpServer coverage for default interval, reload triggering, exception swallowing, and stop-time cleanup.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
common/src/java/org/apache/hive/http/HttpServer.java Starts a daemon Timer to monitor the keystore and triggers Jetty SSL context reload; cancels timer on stop.
common/src/java/org/apache/hadoop/hive/conf/HiveConf.java Adds a new ConfVar for the keystore reload interval.
common/src/test/org/apache/hive/http/TestHttpServer.java Adds tests validating monitoring behavior and shutdown cancellation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +369 to +371
if (this.keystoreChangeMonitor != null) {
this.keystoreChangeMonitor.cancel();
}
timer.schedule(new FileMonitoringTimerTask(
Paths.get(keyStorePath),
path -> {
LOG.info("Reloading certificates from store keystore " + keyStorePath);
Comment on lines +3859 to +3861
HIVE_SERVER2_WEBUI_SSL_KEYSTORE_RELOAD_INTERVAL("hive.server2.webui.keystore.reload.interval", "60s",
new TimeValidator(TimeUnit.MILLISECONDS),
"The refresh interval used to check if either of the keystore certificate file has changed."),
Comment on lines +151 to +157
// stop() also calls webServer.stop(); webServer is null on a mock, so we expect
// a NullPointerException after the cancel path runs.
try {
server.stop();
} catch (NullPointerException expected) {
// intentionally ignored — we only assert the monitor was cancelled
}
Comment on lines +161 to +176
/**
* No monitor installed → stop() must not blow up trying to cancel a missing Timer.
* (Mockito skips field initializers, so we re-establish the production default
* {@code Optional.empty()} on the mock before exercising stop().)
*/
@Test
public void testStopWithoutMonitorDoesNotThrowFromCancelPath() throws Exception {
HttpServer server = mock(HttpServer.class, withSettings().defaultAnswer(CALLS_REAL_METHODS));
server.setKeystoreChangeMonitor(null);
assertNull("keystoreChangeMonitor should be empty for this case", server.keystoreChangeMonitor);

try {
server.stop();
} catch (NullPointerException expectedFromWebServerStop) {
// ok — the monitor branch must not have thrown before reaching webServer.stop()
}
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 5, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants