Skip to content

Commit f27a12a

Browse files
frostruanhuiruan
authored andcommitted
HBASE-27320 hide some sensitive configuration information in the UI (#4723)
Co-authored-by: huiruan <huiruan@tencent.com> Signed-off-by: Tak Lon (Stephen) Wu <taklwu@apache.org> Signed-off-by: Duo Zhang <zhangduo@apache.org> (cherry picked from commit b4e5875)
1 parent c04edf7 commit f27a12a

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

hbase-http/src/main/java/org/apache/hadoop/hbase/http/conf/ConfServlet.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import java.io.IOException;
2121
import java.io.Writer;
22+
import java.util.List;
23+
import java.util.Map;
2224
import javax.servlet.ServletException;
2325
import javax.servlet.http.HttpServlet;
2426
import javax.servlet.http.HttpServletRequest;
@@ -28,6 +30,8 @@
2830
import org.apache.yetus.audience.InterfaceAudience;
2931
import org.apache.yetus.audience.InterfaceStability;
3032

33+
import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList;
34+
3135
/**
3236
* A servlet to print out the running configuration data.
3337
*/
@@ -39,6 +43,9 @@ public class ConfServlet extends HttpServlet {
3943
private static final String FORMAT_JSON = "json";
4044
private static final String FORMAT_XML = "xml";
4145
private static final String FORMAT_PARAM = "format";
46+
private static final List<String> MASK_PROPERTIES =
47+
ImmutableList.of("password", "secret", "superuser");
48+
static final String MASKED = "<masked>";
4249

4350
/**
4451
* Return the Configuration of the daemon hosting this servlet. This is populated when the
@@ -83,15 +90,30 @@ public void doGet(HttpServletRequest request, HttpServletResponse response)
8390
*/
8491
static void writeResponse(Configuration conf, Writer out, String format)
8592
throws IOException, BadFormatException {
93+
Configuration maskedConf = mask(conf);
8694
if (FORMAT_JSON.equals(format)) {
87-
Configuration.dumpConfiguration(conf, out);
95+
Configuration.dumpConfiguration(maskedConf, out);
8896
} else if (FORMAT_XML.equals(format)) {
89-
conf.writeXml(out);
97+
maskedConf.writeXml(out);
9098
} else {
9199
throw new BadFormatException("Bad format: " + format);
92100
}
93101
}
94102

103+
static Configuration mask(Configuration conf) {
104+
Configuration maskedConf = new Configuration(conf);
105+
for (Map.Entry<String, String> entry : maskedConf) {
106+
String key = entry.getKey();
107+
for (String maskProperty : MASK_PROPERTIES) {
108+
if (key.toLowerCase().contains(maskProperty)) {
109+
maskedConf.set(key, MASKED);
110+
break;
111+
}
112+
}
113+
}
114+
return maskedConf;
115+
}
116+
95117
public static class BadFormatException extends Exception {
96118
private static final long serialVersionUID = 1L;
97119

hbase-http/src/test/java/org/apache/hadoop/hbase/http/conf/TestConfServlet.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ public void testWriteXml() throws Exception {
113113
assertTrue(foundSetting);
114114
}
115115

116+
@Test
117+
public void testMask() {
118+
final String passwordKey = "hbase.rpc.tls.keystore.password";
119+
Configuration conf = getTestConf();
120+
conf.set(passwordKey, "MyPassword");
121+
Configuration maskedConf = ConfServlet.mask(conf);
122+
assertEquals(ConfServlet.MASKED, maskedConf.get(passwordKey));
123+
}
124+
116125
@Test
117126
public void testBadFormat() throws Exception {
118127
StringWriter sw = new StringWriter();

0 commit comments

Comments
 (0)