Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HBASE-27811 Enable cache control for logs endpoint and set max age as 0 #5204

Merged
merged 3 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.apache.hadoop.hbase.http.log.LogLevel;
import org.apache.hadoop.hbase.util.ReflectionUtils;
import org.apache.hadoop.hbase.util.Threads;
import org.apache.hadoop.security.AuthenticationFilterInitializer;
import org.apache.hadoop.security.SecurityUtil;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.security.authentication.server.AuthenticationFilter;
Expand Down Expand Up @@ -669,7 +670,7 @@ private static WebAppContext createWebAppContext(String name, Configuration conf
ctx.getServletContext().setAttribute(org.apache.hadoop.http.HttpServer2.CONF_CONTEXT_ATTRIBUTE,
conf);
ctx.getServletContext().setAttribute(ADMINS_ACL, adminsAcl);
addNoCacheFilter(ctx);
addNoCacheFilter(ctx, conf);
return ctx;
}

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

private static void addNoCacheFilter(WebAppContext ctxt) {
defineFilter(ctxt, NO_CACHE_FILTER, NoCacheFilter.class.getName(),
Collections.<String, String> emptyMap(), new String[] { "/*" });
private static void addNoCacheFilter(ServletContextHandler ctxt, Configuration conf) {
if (conf != null) {
ydodeja365 marked this conversation as resolved.
Show resolved Hide resolved
Map<String, String> filterConfig =
AuthenticationFilterInitializer.getFilterConfigMap(conf, "hbase.http.filter.");
defineFilter(ctxt, NO_CACHE_FILTER, NoCacheFilter.class.getName(), filterConfig,
new String[] { "/*" });
} else {
defineFilter(ctxt, NO_CACHE_FILTER, NoCacheFilter.class.getName(),
Collections.<String, String> emptyMap(), new String[] { "/*" });
}
}

/** Get an array of FilterConfiguration specified in the conf */
Expand Down Expand Up @@ -739,6 +747,7 @@ protected void addDefaultApps(ContextHandlerCollection parent, final String appD
}
logContext.setDisplayName("logs");
setContextAttributes(logContext, conf);
addNoCacheFilter(logContext, conf);
defaultContexts.put(logContext, true);
}
// set up the context for "/static/*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,28 @@

@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
public class NoCacheFilter implements Filter {

/**
* Constant for the configuration property that indicates no-store cache control is enabled.
*/
public static final String NO_STORE = "no-store.enable";

private boolean noStoreEnabled = false;

@Override
public void init(FilterConfig filterConfig) throws ServletException {
this.noStoreEnabled = Boolean.valueOf(filterConfig.getInitParameter(NO_STORE));
ydodeja365 marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException {
HttpServletResponse httpRes = (HttpServletResponse) res;
httpRes.setHeader("Cache-Control", "no-cache");
StringBuilder header = new StringBuilder("no-cache");
if (noStoreEnabled) {
header.append(", no-store, max-age=0");
}
httpRes.setHeader("Cache-Control", header.toString());
long now = EnvironmentEdgeManager.currentTime();
httpRes.addDateHeader("Expires", now);
httpRes.addDateHeader("Date", now);
Expand Down
13 changes: 13 additions & 0 deletions src/main/asciidoc/_chapters/security.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ See Nick Dimiduk's contribution on this link:http://stackoverflow.com/questions/
If you know how to fix this without opening a second port for HTTPS, patches are appreciated.
====

[[hbase.ui.cache]]
=== Disable cache in HBase UI

ydodeja365 marked this conversation as resolved.
Show resolved Hide resolved
Set the following configuration in hbase-site to set max age to zero and disable cache for the web UI:

[source,xml]
----
<property>
<name>hbase.http.filter.no-store.enable</name>
<value>true</value>
</property>
---

[[hbase.secure.spnego.ui]]
=== Using SPNEGO for Kerberos authentication with Web UIs

Expand Down