From a2622cbbc42493e49fef0f9724b129ec49f64745 Mon Sep 17 00:00:00 2001 From: senmiaoliu Date: Mon, 15 Apr 2024 11:10:38 +0800 Subject: [PATCH 1/3] disable web ui --- docs/configuration/settings.md | 1 + .../org/apache/kyuubi/config/KyuubiConf.scala | 7 +++++ .../server/KyuubiRestFrontendService.scala | 7 +++++ .../apache/kyuubi/server/ui/JettyUtils.scala | 21 ++++++++++++++ kyuubi-server/web-ui/public/enable.html | 29 +++++++++++++++++++ 5 files changed, 65 insertions(+) create mode 100644 kyuubi-server/web-ui/public/enable.html diff --git a/docs/configuration/settings.md b/docs/configuration/settings.md index 9c8536c13c9..f48b986cd63 100644 --- a/docs/configuration/settings.md +++ b/docs/configuration/settings.md @@ -251,6 +251,7 @@ You can configure the Kyuubi properties in `$KYUUBI_HOME/conf/kyuubi-defaults.co | kyuubi.frontend.proxy.http.client.ip.header | X-Real-IP | The HTTP header to record the real client IP address. If your server is behind a load balancer or other proxy, the server will see this load balancer or proxy IP address as the client IP address, to get around this common issue, most load balancers or proxies offer the ability to record the real remote IP address in an HTTP header that will be added to the request for other devices to use. Note that, because the header value can be specified to any IP address, so it will not be used for authentication. | string | 1.6.0 | | kyuubi.frontend.rest.bind.host | <undefined> | Hostname or IP of the machine on which to run the REST frontend service. | string | 1.4.0 | | kyuubi.frontend.rest.bind.port | 10099 | Port of the machine on which to run the REST frontend service. | int | 1.4.0 | +| kyuubi.frontend.rest.enable.webui | true | If set to false then web ui will disabled when RESTful protocol is enabled | boolean | 1.10.0 | | kyuubi.frontend.rest.jetty.stopTimeout | PT5S | Stop timeout for Jetty server used by the RESTful frontend service. | duration | 1.8.1 | | kyuubi.frontend.rest.max.worker.threads | 999 | Maximum number of threads in the frontend worker thread pool for the rest frontend service | int | 1.6.2 | | kyuubi.frontend.rest.proxy.jetty.client.idleTimeout | PT30S | The idle timeout in milliseconds for Jetty server used by the RESTful frontend service. | duration | 1.10.0 | diff --git a/kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala b/kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala index 6de0af9155e..ba336a0216b 100644 --- a/kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala +++ b/kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala @@ -626,6 +626,13 @@ object KyuubiConf { .timeConf .createWithDefaultString("PT5S") + val FRONTEND_REST_ENABLE_WEBUI: ConfigEntry[Boolean] = + buildConf("kyuubi.frontend.rest.enable.webui") + .doc("If set to false then web ui will disabled when RESTful protocol is enabled") + .version("1.10.0") + .booleanConf + .createWithDefault(true) + val FRONTEND_WORKER_KEEPALIVE_TIME: ConfigEntry[Long] = buildConf("kyuubi.frontend.worker.keepalive.time") .doc("(deprecated) Keep-alive time (in milliseconds) for an idle worker thread") diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala index a3dd4038995..bf880612d32 100644 --- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala @@ -116,6 +116,13 @@ class KyuubiRestFrontendService(override val serverable: Serverable) } private def installWebUI(): Unit = { + if (!conf.get(FRONTEND_REST_ENABLE_WEBUI)) { + val filterHolder = new FilterHolder(JettyUtils.createFilter("/enable.html")) + val servletHandler = JettyUtils.createStaticHandler("dist", "/") + servletHandler.addFilter(filterHolder, "/*", null) + server.addHandler(servletHandler) + return + } // redirect root path to Web UI home page server.addRedirectHandler("/", "/ui") diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/ui/JettyUtils.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/ui/JettyUtils.scala index f93f89a9580..6844ee23114 100644 --- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/ui/JettyUtils.scala +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/ui/JettyUtils.scala @@ -18,6 +18,7 @@ package org.apache.kyuubi.server.ui import java.net.URL +import javax.servlet.{Filter, FilterChain, FilterConfig, ServletRequest, ServletResponse} import javax.servlet.http.{HttpServlet, HttpServletRequest, HttpServletResponse} import org.eclipse.jetty.servlet.{DefaultServlet, ServletContextHandler, ServletHolder} @@ -87,4 +88,24 @@ private[kyuubi] object JettyUtils { createServletHandler(src, redirectedServlet) } + + def createFilter(targetPage: String): Filter = new Filter { + override def init(filterConfig: FilterConfig): Unit = {} + + override def doFilter( + request: ServletRequest, + response: ServletResponse, + chain: FilterChain): Unit = { + val httpRequest = request.asInstanceOf[HttpServletRequest] + val httpResponse = response.asInstanceOf[HttpServletResponse] + val requestURI = httpRequest.getRequestURI + if (requestURI != targetPage) { + httpResponse.sendRedirect(httpRequest.getContextPath + targetPage) + } else { + chain.doFilter(request, response) + } + } + + override def destroy(): Unit = {} + } } diff --git a/kyuubi-server/web-ui/public/enable.html b/kyuubi-server/web-ui/public/enable.html new file mode 100644 index 00000000000..91083ae9390 --- /dev/null +++ b/kyuubi-server/web-ui/public/enable.html @@ -0,0 +1,29 @@ + + + + + + + Apache Kyuubi + + +

🙁 The Web UI is currently unavailable.

+

👉 To enable Web UI, set kyuubi.frontend.rest.enable.webui true.

+ + From 99850471046edd5fb0a3593572050ae9d51d5e2f Mon Sep 17 00:00:00 2001 From: senmiaoliu Date: Tue, 16 Apr 2024 11:29:39 +0800 Subject: [PATCH 2/3] fix style --- docs/configuration/settings.md | 2 +- .../org/apache/kyuubi/config/KyuubiConf.scala | 6 +++--- .../server/KyuubiRestFrontendService.scala | 19 +++++++++++-------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/docs/configuration/settings.md b/docs/configuration/settings.md index f48b986cd63..c02d4cee8fe 100644 --- a/docs/configuration/settings.md +++ b/docs/configuration/settings.md @@ -251,7 +251,6 @@ You can configure the Kyuubi properties in `$KYUUBI_HOME/conf/kyuubi-defaults.co | kyuubi.frontend.proxy.http.client.ip.header | X-Real-IP | The HTTP header to record the real client IP address. If your server is behind a load balancer or other proxy, the server will see this load balancer or proxy IP address as the client IP address, to get around this common issue, most load balancers or proxies offer the ability to record the real remote IP address in an HTTP header that will be added to the request for other devices to use. Note that, because the header value can be specified to any IP address, so it will not be used for authentication. | string | 1.6.0 | | kyuubi.frontend.rest.bind.host | <undefined> | Hostname or IP of the machine on which to run the REST frontend service. | string | 1.4.0 | | kyuubi.frontend.rest.bind.port | 10099 | Port of the machine on which to run the REST frontend service. | int | 1.4.0 | -| kyuubi.frontend.rest.enable.webui | true | If set to false then web ui will disabled when RESTful protocol is enabled | boolean | 1.10.0 | | kyuubi.frontend.rest.jetty.stopTimeout | PT5S | Stop timeout for Jetty server used by the RESTful frontend service. | duration | 1.8.1 | | kyuubi.frontend.rest.max.worker.threads | 999 | Maximum number of threads in the frontend worker thread pool for the rest frontend service | int | 1.6.2 | | kyuubi.frontend.rest.proxy.jetty.client.idleTimeout | PT30S | The idle timeout in milliseconds for Jetty server used by the RESTful frontend service. | duration | 1.10.0 | @@ -260,6 +259,7 @@ You can configure the Kyuubi properties in `$KYUUBI_HOME/conf/kyuubi-defaults.co | kyuubi.frontend.rest.proxy.jetty.client.requestBufferSize | 4096 | Size of the buffer in bytes used to write requests for Jetty server used by the RESTful frontend service. | int | 1.10.0 | | kyuubi.frontend.rest.proxy.jetty.client.responseBufferSize | 4096 | Size of the buffer in bytes used to read response for Jetty server used by the RESTful frontend service. | int | 1.10.0 | | kyuubi.frontend.rest.proxy.jetty.client.timeout | PT60S | The total timeout in milliseconds for Jetty server used by the RESTful frontend service. | duration | 1.10.0 | +| kyuubi.frontend.rest.ui.enabled | true | Whether to enable Web UI when RESTful protocol is enabled | boolean | 1.10.0 | | kyuubi.frontend.ssl.keystore.algorithm | <undefined> | SSL certificate keystore algorithm. | string | 1.7.0 | | kyuubi.frontend.ssl.keystore.password | <undefined> | SSL certificate keystore password. | string | 1.7.0 | | kyuubi.frontend.ssl.keystore.path | <undefined> | SSL certificate keystore location. | string | 1.7.0 | diff --git a/kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala b/kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala index ba336a0216b..f1451ccffe7 100644 --- a/kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala +++ b/kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala @@ -626,9 +626,9 @@ object KyuubiConf { .timeConf .createWithDefaultString("PT5S") - val FRONTEND_REST_ENABLE_WEBUI: ConfigEntry[Boolean] = - buildConf("kyuubi.frontend.rest.enable.webui") - .doc("If set to false then web ui will disabled when RESTful protocol is enabled") + val FRONTEND_REST_UI_ENABLED: ConfigEntry[Boolean] = + buildConf("kyuubi.frontend.rest.ui.enabled") + .doc("Whether to enable Web UI when RESTful protocol is enabled") .version("1.10.0") .booleanConf .createWithDefault(true) diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala index bf880612d32..c9a79cae38a 100644 --- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala @@ -111,18 +111,21 @@ class KyuubiRestFrontendService(override val serverable: Serverable) val proxyHandler = ApiRootResource.getEngineUIProxyHandler(this) server.addHandler(authenticationFactory.httpHandlerWrapperFactory.wrapHandler(proxyHandler)) + if (conf.get(FRONTEND_REST_UI_ENABLED)) { + installWebUI() + } else { + installDisableWebUI() + } + } - installWebUI() + private def installDisableWebUI(): Unit = { + val filterHolder = new FilterHolder(JettyUtils.createFilter("/enable.html")) + val servletHandler = JettyUtils.createStaticHandler("dist", "/") + servletHandler.addFilter(filterHolder, "/*", null) + server.addHandler(servletHandler) } private def installWebUI(): Unit = { - if (!conf.get(FRONTEND_REST_ENABLE_WEBUI)) { - val filterHolder = new FilterHolder(JettyUtils.createFilter("/enable.html")) - val servletHandler = JettyUtils.createStaticHandler("dist", "/") - servletHandler.addFilter(filterHolder, "/*", null) - server.addHandler(servletHandler) - return - } // redirect root path to Web UI home page server.addRedirectHandler("/", "/ui") From aa96c27376ab8563431946de1791c1c6ffee3c24 Mon Sep 17 00:00:00 2001 From: senmiaoliu Date: Tue, 16 Apr 2024 12:59:48 +0800 Subject: [PATCH 3/3] remove enable.html --- .../server/KyuubiRestFrontendService.scala | 9 ------ .../apache/kyuubi/server/ui/JettyUtils.scala | 21 -------------- kyuubi-server/web-ui/public/enable.html | 29 ------------------- 3 files changed, 59 deletions(-) delete mode 100644 kyuubi-server/web-ui/public/enable.html diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala index c9a79cae38a..06eb63feeb6 100644 --- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala @@ -113,18 +113,9 @@ class KyuubiRestFrontendService(override val serverable: Serverable) server.addHandler(authenticationFactory.httpHandlerWrapperFactory.wrapHandler(proxyHandler)) if (conf.get(FRONTEND_REST_UI_ENABLED)) { installWebUI() - } else { - installDisableWebUI() } } - private def installDisableWebUI(): Unit = { - val filterHolder = new FilterHolder(JettyUtils.createFilter("/enable.html")) - val servletHandler = JettyUtils.createStaticHandler("dist", "/") - servletHandler.addFilter(filterHolder, "/*", null) - server.addHandler(servletHandler) - } - private def installWebUI(): Unit = { // redirect root path to Web UI home page server.addRedirectHandler("/", "/ui") diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/ui/JettyUtils.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/ui/JettyUtils.scala index 6844ee23114..f93f89a9580 100644 --- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/ui/JettyUtils.scala +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/ui/JettyUtils.scala @@ -18,7 +18,6 @@ package org.apache.kyuubi.server.ui import java.net.URL -import javax.servlet.{Filter, FilterChain, FilterConfig, ServletRequest, ServletResponse} import javax.servlet.http.{HttpServlet, HttpServletRequest, HttpServletResponse} import org.eclipse.jetty.servlet.{DefaultServlet, ServletContextHandler, ServletHolder} @@ -88,24 +87,4 @@ private[kyuubi] object JettyUtils { createServletHandler(src, redirectedServlet) } - - def createFilter(targetPage: String): Filter = new Filter { - override def init(filterConfig: FilterConfig): Unit = {} - - override def doFilter( - request: ServletRequest, - response: ServletResponse, - chain: FilterChain): Unit = { - val httpRequest = request.asInstanceOf[HttpServletRequest] - val httpResponse = response.asInstanceOf[HttpServletResponse] - val requestURI = httpRequest.getRequestURI - if (requestURI != targetPage) { - httpResponse.sendRedirect(httpRequest.getContextPath + targetPage) - } else { - chain.doFilter(request, response) - } - } - - override def destroy(): Unit = {} - } } diff --git a/kyuubi-server/web-ui/public/enable.html b/kyuubi-server/web-ui/public/enable.html deleted file mode 100644 index 91083ae9390..00000000000 --- a/kyuubi-server/web-ui/public/enable.html +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - Apache Kyuubi - - -

🙁 The Web UI is currently unavailable.

-

👉 To enable Web UI, set kyuubi.frontend.rest.enable.webui true.

- -