HIVE-29636: Add SSL keystore auto-reloading for HiveServer2 WebUI#6514
HIVE-29636: Add SSL keystore auto-reloading for HiveServer2 WebUI#6514magnuma3 wants to merge 3 commits into
Conversation
|
test failure is not related to this patch. |
|
@deniskuzZ thank you for review. addressed all the comments. |
There was a problem hiding this comment.
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(default60s) to control periodic keystore change checks. - Wire a
Timer+ HadoopFileMonitoringTimerTaskintoHttpServerwhen WebUI SSL is enabled, and cancel it duringHttpServer#stop(). - Add
TestHttpServercoverage 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.
| if (this.keystoreChangeMonitor != null) { | ||
| this.keystoreChangeMonitor.cancel(); | ||
| } |
| timer.schedule(new FileMonitoringTimerTask( | ||
| Paths.get(keyStorePath), | ||
| path -> { | ||
| LOG.info("Reloading certificates from store keystore " + keyStorePath); |
| 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."), |
| // 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 | ||
| } |
| /** | ||
| * 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() | ||
| } |
|



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