Skip to content

Commit ea3a44e

Browse files
authored
HBASE-27811 Enable cache control for logs endpoint and set max age as 0 (#5204)
1 parent d7b2fb4 commit ea3a44e

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

hbase-http/src/main/java/org/apache/hadoop/hbase/http/HttpServer.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.apache.hadoop.hbase.http.log.LogLevel;
5757
import org.apache.hadoop.hbase.util.ReflectionUtils;
5858
import org.apache.hadoop.hbase.util.Threads;
59+
import org.apache.hadoop.security.AuthenticationFilterInitializer;
5960
import org.apache.hadoop.security.SecurityUtil;
6061
import org.apache.hadoop.security.UserGroupInformation;
6162
import org.apache.hadoop.security.authentication.server.AuthenticationFilter;
@@ -143,6 +144,7 @@ public class HttpServer implements FilterContainer {
143144
HTTP_SPNEGO_AUTHENTICATION_PREFIX + "admin.groups";
144145
public static final String HTTP_PRIVILEGED_CONF_KEY =
145146
"hbase.security.authentication.ui.config.protected";
147+
public static final String HTTP_UI_NO_CACHE_ENABLE_KEY = "hbase.http.filter.no-store.enable";
146148
public static final boolean HTTP_PRIVILEGED_CONF_DEFAULT = false;
147149

148150
// The ServletContext attribute where the daemon Configuration
@@ -679,7 +681,7 @@ private static WebAppContext createWebAppContext(String name, Configuration conf
679681
ctx.getServletContext().setAttribute(org.apache.hadoop.http.HttpServer2.CONF_CONTEXT_ATTRIBUTE,
680682
conf);
681683
ctx.getServletContext().setAttribute(ADMINS_ACL, adminsAcl);
682-
addNoCacheFilter(ctx);
684+
addNoCacheFilter(ctx, conf);
683685
return ctx;
684686
}
685687

@@ -701,9 +703,16 @@ public static GzipHandler buildGzipHandler(final Handler wrapped) {
701703
return gzipHandler;
702704
}
703705

704-
private static void addNoCacheFilter(WebAppContext ctxt) {
705-
defineFilter(ctxt, NO_CACHE_FILTER, NoCacheFilter.class.getName(),
706-
Collections.<String, String> emptyMap(), new String[] { "/*" });
706+
private static void addNoCacheFilter(ServletContextHandler ctxt, Configuration conf) {
707+
if (conf.getBoolean(HTTP_UI_NO_CACHE_ENABLE_KEY, false)) {
708+
Map<String, String> filterConfig =
709+
AuthenticationFilterInitializer.getFilterConfigMap(conf, "hbase.http.filter.");
710+
defineFilter(ctxt, NO_CACHE_FILTER, NoCacheFilter.class.getName(), filterConfig,
711+
new String[] { "/*" });
712+
} else {
713+
defineFilter(ctxt, NO_CACHE_FILTER, NoCacheFilter.class.getName(),
714+
Collections.<String, String> emptyMap(), new String[] { "/*" });
715+
}
707716
}
708717

709718
/** Get an array of FilterConfiguration specified in the conf */
@@ -749,6 +758,7 @@ protected void addDefaultApps(ContextHandlerCollection parent, final String appD
749758
}
750759
logContext.setDisplayName("logs");
751760
setContextAttributes(logContext, conf);
761+
addNoCacheFilter(logContext, conf);
752762
defaultContexts.put(logContext, true);
753763
}
754764
// set up the context for "/static/*"

hbase-http/src/main/java/org/apache/hadoop/hbase/http/NoCacheFilter.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,28 @@
3131

3232
@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
3333
public class NoCacheFilter implements Filter {
34+
35+
/**
36+
* Constant for the configuration property that indicates no-store cache control is enabled.
37+
*/
38+
public static final String NO_STORE = "no-store.enable";
39+
40+
private boolean noStoreEnabled = false;
41+
3442
@Override
3543
public void init(FilterConfig filterConfig) throws ServletException {
44+
this.noStoreEnabled = Boolean.valueOf(filterConfig.getInitParameter(NO_STORE));
3645
}
3746

3847
@Override
3948
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
4049
throws IOException, ServletException {
4150
HttpServletResponse httpRes = (HttpServletResponse) res;
42-
httpRes.setHeader("Cache-Control", "no-cache");
51+
StringBuilder header = new StringBuilder("no-cache");
52+
if (noStoreEnabled) {
53+
header.append(", no-store, max-age=0");
54+
}
55+
httpRes.setHeader("Cache-Control", header.toString());
4356
long now = EnvironmentEdgeManager.currentTime();
4457
httpRes.addDateHeader("Expires", now);
4558
httpRes.addDateHeader("Date", now);

src/main/asciidoc/_chapters/security.adoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ See Nick Dimiduk's contribution on this link:http://stackoverflow.com/questions/
7171
If you know how to fix this without opening a second port for HTTPS, patches are appreciated.
7272
====
7373

74+
[[hbase.ui.cache]]
75+
=== Disable cache in HBase UI
76+
77+
Set the following configuration in hbase-site to set max age to zero and disable cache for the web UI:
78+
79+
[source,xml]
80+
----
81+
<property>
82+
<name>hbase.http.filter.no-store.enable</name>
83+
<value>true</value>
84+
</property>
85+
----
86+
7487
[[hbase.secure.spnego.ui]]
7588
=== Using SPNEGO for Kerberos authentication with Web UIs
7689

0 commit comments

Comments
 (0)