You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ni...@apache.org on 2023/12/18 16:07:05 UTC
(hbase) branch master updated: HBASE-21500 "hbase.jetty.logs.serve.aliases" is broken with jetty 9 version (#5586)
This is an automated email from the ASF dual-hosted git repository.
nihaljain pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/master by this push:
new 53e01b23ece HBASE-21500 "hbase.jetty.logs.serve.aliases" is broken with jetty 9 version (#5586)
53e01b23ece is described below
commit 53e01b23ecec84368322f1e4d8eaaaae904b76c4
Author: Nihal Jain <ni...@apache.org>
AuthorDate: Mon Dec 18 21:36:59 2023 +0530
HBASE-21500 "hbase.jetty.logs.serve.aliases" is broken with jetty 9 version (#5586)
Signed-off-by: Duo Zhang <zh...@apache.org>
---
.../org/apache/hadoop/hbase/http/HttpServer.java | 43 ++++++++++++++++++----
1 file changed, 35 insertions(+), 8 deletions(-)
diff --git a/hbase-http/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java
index a2b8a8fb627..6bbbc5608a0 100644
--- a/hbase-http/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java
+++ b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java
@@ -81,6 +81,7 @@ import org.apache.hbase.thirdparty.org.eclipse.jetty.server.SecureRequestCustomi
import org.apache.hbase.thirdparty.org.eclipse.jetty.server.Server;
import org.apache.hbase.thirdparty.org.eclipse.jetty.server.ServerConnector;
import org.apache.hbase.thirdparty.org.eclipse.jetty.server.SslConnectionFactory;
+import org.apache.hbase.thirdparty.org.eclipse.jetty.server.SymlinkAllowedResourceAliasChecker;
import org.apache.hbase.thirdparty.org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.apache.hbase.thirdparty.org.eclipse.jetty.server.handler.ErrorHandler;
import org.apache.hbase.thirdparty.org.eclipse.jetty.server.handler.HandlerCollection;
@@ -756,15 +757,10 @@ public class HttpServer implements FilterContainer {
ServletContextHandler logContext = new ServletContextHandler(parent, "/logs");
logContext.addServlet(AdminAuthorizedServlet.class, "/*");
logContext.setResourceBase(logDir);
-
- if (
- conf.getBoolean(ServerConfigurationKeys.HBASE_JETTY_LOGS_SERVE_ALIASES,
- ServerConfigurationKeys.DEFAULT_HBASE_JETTY_LOGS_SERVE_ALIASES)
- ) {
- Map<String, String> params = logContext.getInitParams();
- params.put("org.mortbay.jetty.servlet.Default.aliases", "true");
- }
logContext.setDisplayName("logs");
+ configureAliasChecks(logContext,
+ conf.getBoolean(ServerConfigurationKeys.HBASE_JETTY_LOGS_SERVE_ALIASES,
+ ServerConfigurationKeys.DEFAULT_HBASE_JETTY_LOGS_SERVE_ALIASES));
setContextAttributes(logContext, conf);
addNoCacheFilter(logContext, conf);
defaultContexts.put(logContext, true);
@@ -778,6 +774,37 @@ public class HttpServer implements FilterContainer {
defaultContexts.put(staticContext, true);
}
+ /**
+ * This method configures the alias checks for the given ServletContextHandler based on the
+ * provided value of shouldServeAlias.<br>
+ * If shouldServeAlias is set to true, it checks if SymlinkAllowedResourceAliasChecker is already
+ * a part of the alias check list. If it is already a part of the list, no changes are made, else,
+ * it adds it to the list.<br>
+ * If shouldServeAlias is set to false, it clears all alias checks from the
+ * ServletContextHandler.<br>
+ * .
+ * @param context The ServletContextHandler whose alias checks are to be configured
+ * @param shouldServeAlias Whether aliases should be allowed or not
+ */
+ private void configureAliasChecks(ServletContextHandler context, boolean shouldServeAlias) {
+ if (shouldServeAlias) {
+ Class aliasCheckerClass = SymlinkAllowedResourceAliasChecker.class;
+ // check if SymlinkAllowedResourceAliasChecker is already part of alias check list
+ // NOTE: we are doing this because this is already present in the context (by default)
+ if (context.getAliasChecks().stream().anyMatch(aliasCheckerClass::isInstance)) {
+ LOG.debug("{} is already part of alias check list", aliasCheckerClass.getName());
+ } else {
+ context.addAliasCheck(new SymlinkAllowedResourceAliasChecker(context));
+ LOG.debug("{} added to the alias check list", aliasCheckerClass.getName());
+ }
+ LOG.info("Serving aliases allowed for /logs context");
+ } else {
+ // if aliasing is disabled, then we should clear the alias check list
+ context.clearAliasChecks();
+ LOG.info("Serving aliases disabled for /logs context");
+ }
+ }
+
private void setContextAttributes(ServletContextHandler context, Configuration conf) {
context.getServletContext().setAttribute(CONF_CONTEXT_ATTRIBUTE, conf);
context.getServletContext().setAttribute(ADMINS_ACL, adminsAcl);