From 89a209e46a02ad61ad41f1a624b29818c356c7be Mon Sep 17 00:00:00 2001 From: Anant Aneja <1797669+aaneja@users.noreply.github.com> Date: Mon, 23 Feb 2026 11:59:38 +0530 Subject: [PATCH] feat(server) : Add ability to disable the UI For controlled environments, users may want to disable the UI (enabled by default) --- .../facebook/presto/server/ServerConfig.java | 13 +++++++ .../presto/server/TestServerConfig.java | 3 ++ .../presto/server/CoordinatorModule.java | 18 ++++++++-- .../presto/server/ServerMainModule.java | 2 +- .../src/main/resources/nowebapp/index.html | 35 +++++++++++++++++++ 5 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 presto-main/src/main/resources/nowebapp/index.html diff --git a/presto-main-base/src/main/java/com/facebook/presto/server/ServerConfig.java b/presto-main-base/src/main/java/com/facebook/presto/server/ServerConfig.java index 7e7bcbbffd1d4..e629733d916a1 100644 --- a/presto-main-base/src/main/java/com/facebook/presto/server/ServerConfig.java +++ b/presto-main-base/src/main/java/com/facebook/presto/server/ServerConfig.java @@ -43,6 +43,7 @@ public class ServerConfig private boolean nestedDataSerializationEnabled = true; private Duration clusterResourceGroupStateInfoExpirationDuration = new Duration(0, MILLISECONDS); private String clusterTag; + private boolean webUIEnabled = true; public boolean isResourceManager() { @@ -116,6 +117,18 @@ public ServerConfig setCoordinator(boolean coordinator) return this; } + public boolean isWebUIEnabled() + { + return webUIEnabled; + } + + @Config("webui-enabled") + public ServerConfig setWebUIEnabled(boolean webUIEnabled) + { + this.webUIEnabled = webUIEnabled; + return this; + } + @NotNull(message = "presto.version must be provided when it cannot be automatically determined") public String getPrestoVersion() { diff --git a/presto-main-base/src/test/java/com/facebook/presto/server/TestServerConfig.java b/presto-main-base/src/test/java/com/facebook/presto/server/TestServerConfig.java index b570f157a36f4..d572a34c47e67 100644 --- a/presto-main-base/src/test/java/com/facebook/presto/server/TestServerConfig.java +++ b/presto-main-base/src/test/java/com/facebook/presto/server/TestServerConfig.java @@ -35,6 +35,7 @@ public void testDefaults() { assertRecordedDefaults(ConfigAssertions.recordDefaults(ServerConfig.class) .setCoordinator(true) + .setWebUIEnabled(true) .setPrestoVersion(null) .setDataSources(null) .setIncludeExceptionInResponse(true) @@ -58,6 +59,7 @@ public void testExplicitPropertyMappings() { Map properties = new ImmutableMap.Builder() .put("coordinator", "false") + .put("webui-enabled", "false") .put("presto.version", "test") .put("datasources", "jmx") .put("http.include-exception-in-response", "false") @@ -78,6 +80,7 @@ public void testExplicitPropertyMappings() ServerConfig expected = new ServerConfig() .setCoordinator(false) + .setWebUIEnabled(false) .setPrestoVersion("test") .setDataSources("jmx") .setIncludeExceptionInResponse(false) diff --git a/presto-main/src/main/java/com/facebook/presto/server/CoordinatorModule.java b/presto-main/src/main/java/com/facebook/presto/server/CoordinatorModule.java index c201aa36d7771..8109e34287b36 100644 --- a/presto-main/src/main/java/com/facebook/presto/server/CoordinatorModule.java +++ b/presto-main/src/main/java/com/facebook/presto/server/CoordinatorModule.java @@ -148,6 +148,13 @@ public class CoordinatorModule "default-src 'self'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; " + "font-src 'self' https://fonts.gstatic.com; frame-ancestors 'self'; img-src 'self' data:; form-action 'self'"; + private final boolean isWebUIEnabled; + + public CoordinatorModule(boolean webUIEnabled) + { + this.isWebUIEnabled = webUIEnabled; + } + public static HttpResourceBinding webUIBinder(Binder binder, String path, String classPathResourceBase) { return httpServerBinder(binder).bindResource(path, classPathResourceBase) @@ -158,9 +165,14 @@ public static HttpResourceBinding webUIBinder(Binder binder, String path, String @Override protected void setup(Binder binder) { - webUIBinder(binder, "/ui/dev", "webapp/dev").withWelcomeFile("index.html"); - webUIBinder(binder, "/ui", "webapp").withWelcomeFile("index.html"); - webUIBinder(binder, "/tableau", "webapp/tableau"); + if (isWebUIEnabled) { + webUIBinder(binder, "/ui/dev", "webapp/dev").withWelcomeFile("index.html"); + webUIBinder(binder, "/ui", "webapp").withWelcomeFile("index.html"); + webUIBinder(binder, "/tableau", "webapp/tableau"); + } + else { + webUIBinder(binder, "/ui", "nowebapp").withWelcomeFile("index.html"); + } // discovery server install(installModuleIf(EmbeddedDiscoveryConfig.class, EmbeddedDiscoveryConfig::isEnabled, new EmbeddedDiscoveryModule())); diff --git a/presto-main/src/main/java/com/facebook/presto/server/ServerMainModule.java b/presto-main/src/main/java/com/facebook/presto/server/ServerMainModule.java index 6bb3d8856c479..f54a113c0a917 100644 --- a/presto-main/src/main/java/com/facebook/presto/server/ServerMainModule.java +++ b/presto-main/src/main/java/com/facebook/presto/server/ServerMainModule.java @@ -336,7 +336,7 @@ else if (serverConfig.isCatalogServer()) { install(new CatalogServerModule()); } else if (serverConfig.isCoordinator()) { - install(new CoordinatorModule()); + install(new CoordinatorModule(serverConfig.isWebUIEnabled())); } else { install(new WorkerModule()); diff --git a/presto-main/src/main/resources/nowebapp/index.html b/presto-main/src/main/resources/nowebapp/index.html new file mode 100644 index 0000000000000..9a7920b784325 --- /dev/null +++ b/presto-main/src/main/resources/nowebapp/index.html @@ -0,0 +1,35 @@ + + + + + + Presto UI Disabled + + + +
+

The Presto UI has been disabled for this environment

+
+ +