Skip to content

Commit 2f5961f

Browse files
committed
HBASE-27811 Enable cache control for logs endpoint and set max age as 0
1 parent 3593288 commit 2f5961f

3 files changed

Lines changed: 41 additions & 5 deletions

File tree

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

Lines changed: 13 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;
@@ -669,7 +670,7 @@ private static WebAppContext createWebAppContext(String name, Configuration conf
669670
ctx.getServletContext().setAttribute(org.apache.hadoop.http.HttpServer2.CONF_CONTEXT_ATTRIBUTE,
670671
conf);
671672
ctx.getServletContext().setAttribute(ADMINS_ACL, adminsAcl);
672-
addNoCacheFilter(ctx);
673+
addNoCacheFilter(ctx, conf);
673674
return ctx;
674675
}
675676

@@ -691,9 +692,16 @@ public static GzipHandler buildGzipHandler(final Handler wrapped) {
691692
return gzipHandler;
692693
}
693694

694-
private static void addNoCacheFilter(WebAppContext ctxt) {
695-
defineFilter(ctxt, NO_CACHE_FILTER, NoCacheFilter.class.getName(),
696-
Collections.<String, String> emptyMap(), new String[] { "/*" });
695+
private static void addNoCacheFilter(ServletContextHandler ctxt, Configuration conf) {
696+
if (conf != null) {
697+
Map<String, String> filterConfig = AuthenticationFilterInitializer
698+
.getFilterConfigMap(conf, "hadoop.http.filter.");
699+
defineFilter(ctxt, NO_CACHE_FILTER, NoCacheFilter.class.getName(),
700+
filterConfig, new String[] { "/*" });
701+
} else {
702+
defineFilter(ctxt, NO_CACHE_FILTER, NoCacheFilter.class.getName(),
703+
Collections.<String, String> emptyMap(), new String[]{"/*"});
704+
}
697705
}
698706

699707
/** Get an array of FilterConfiguration specified in the conf */
@@ -739,6 +747,7 @@ protected void addDefaultApps(ContextHandlerCollection parent, final String appD
739747
}
740748
logContext.setDisplayName("logs");
741749
setContextAttributes(logContext, conf);
750+
addNoCacheFilter(logContext, conf);
742751
defaultContexts.put(logContext, true);
743752
}
744753
// set up the context for "/static/*"

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,29 @@
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
37+
* is enabled.
38+
*/
39+
public static final String NO_STORE = "no-store.enable";
40+
41+
private boolean noStoreEnabled = false;
42+
3443
@Override
3544
public void init(FilterConfig filterConfig) throws ServletException {
45+
this.noStoreEnabled = Boolean.valueOf(filterConfig.getInitParameter(NO_STORE));
3646
}
3747

3848
@Override
3949
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
4050
throws IOException, ServletException {
4151
HttpServletResponse httpRes = (HttpServletResponse) res;
42-
httpRes.setHeader("Cache-Control", "no-cache");
52+
StringBuilder header = new StringBuilder("no-cache");
53+
if (noStoreEnabled) {
54+
header.append(", no-store, max-age=0");
55+
}
56+
httpRes.setHeader("Cache-Control", header.toString());
4357
long now = EnvironmentEdgeManager.currentTime();
4458
httpRes.addDateHeader("Expires", now);
4559
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>hadoop.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)