diff --git a/common/src/java/org/apache/hive/http/HttpServer.java b/common/src/java/org/apache/hive/http/HttpServer.java index 9ceaf3f..0eb5fa9 100644 --- a/common/src/java/org/apache/hive/http/HttpServer.java +++ b/common/src/java/org/apache/hive/http/HttpServer.java @@ -130,9 +130,10 @@ public HttpServer build() throws IOException { return new HttpServer(this); } - public Builder setConf(HiveConf conf) { + public Builder setConf(HiveConf origConf) { + this.conf = new HiveConf(origConf); + origConf.stripHiddenConfigurations(conf); setContextAttribute(CONF_CONTEXT_ATTRIBUTE, conf); - this.conf = conf; return this; } diff --git a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/TestHiveServer2.java b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/TestHiveServer2.java index d8c6bea..50f96b5 100644 --- a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/TestHiveServer2.java +++ b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/miniHS2/TestHiveServer2.java @@ -20,9 +20,14 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertNotNull; +import java.lang.StringBuilder; import java.util.HashMap; import java.util.Map; +import java.io.BufferedReader; +import java.io.InputStreamReader; import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.conf.HiveConf.ConfVars; @@ -36,16 +41,30 @@ import org.junit.BeforeClass; import org.junit.Test; + +import org.apache.http.HttpEntity; +import org.apache.http.NameValuePair; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; + public class TestHiveServer2 { private static MiniHS2 miniHS2 = null; + private static HiveConf hiveConf = null; private static Map confOverlay; + private static String metastorePasswd = "61ecbc41cdae3e6b32712a06c73606fa"; //random md5 @BeforeClass public static void beforeTest() throws Exception { - miniHS2 = new MiniHS2(new HiveConf()); + hiveConf = new HiveConf(); + miniHS2 = new MiniHS2(hiveConf); confOverlay = new HashMap(); confOverlay.put(ConfVars.HIVE_SUPPORT_CONCURRENCY.varname, "false"); + confOverlay.put(ConfVars.METASTOREPWD.varname, metastorePasswd); miniHS2.start(confOverlay); } @@ -95,4 +114,46 @@ public void testGetVariableValue() throws Exception { serviceClient.closeSession(sessHandle); } + + @Test + public void testConfStrippedFromWebUI() throws Exception { + + int webUIPort = hiveConf.getIntVar(ConfVars.HIVE_SERVER2_WEBUI_PORT); + if (confOverlay.containsKey(ConfVars.HIVE_SERVER2_WEBUI_PORT.varname)){ + webUIPort = Integer.valueOf(confOverlay.get(ConfVars.HIVE_SERVER2_WEBUI_PORT.varname)); + } + String pwdValFound = null; + String pwdKeyFound = null; + CloseableHttpClient httpclient = null; + try { + httpclient = HttpClients.createDefault(); + HttpGet httpGet = new HttpGet("http://127.0.0.1:"+webUIPort+"/conf"); + CloseableHttpResponse response1 = httpclient.execute(httpGet); + + try { + HttpEntity entity1 = response1.getEntity(); + BufferedReader br = new BufferedReader(new InputStreamReader(entity1.getContent())); + String line; + while ((line = br.readLine())!= null) { + if (line.contains(metastorePasswd)){ + pwdValFound = line; + } + if (line.contains(ConfVars.METASTOREPWD.varname)){ + pwdKeyFound = line; + } + } + EntityUtils.consume(entity1); + } finally { + response1.close(); + } + } finally { + if (httpclient != null){ + httpclient.close(); + } + } + + assertNotNull(pwdKeyFound); + assertNull(pwdValFound); + } + } diff --git a/service/src/java/org/apache/hive/service/server/HiveServer2.java b/service/src/java/org/apache/hive/service/server/HiveServer2.java index 14e1e0d..6a44647 100644 --- a/service/src/java/org/apache/hive/service/server/HiveServer2.java +++ b/service/src/java/org/apache/hive/service/server/HiveServer2.java @@ -145,7 +145,12 @@ public void run() { } // Setup web UI try { - if (hiveConf.getBoolVar(ConfVars.HIVE_IN_TEST)) { + // FIXME : verify before removing altogether - is there a reason + // we didn't want to start the webui during testing? + + // boolean disabledInTest = hiveConf.getBoolVar(ConfVars.HIVE_IN_TEST); + boolean disabledInTest = false; + if (disabledInTest) { LOG.info("Web UI is disabled since in test mode"); } else { int webUIPort = @@ -153,6 +158,7 @@ public void run() { if (webUIPort <= 0) { LOG.info("Web UI is disabled since port is set to " + webUIPort); } else { + LOG.info("Starting Web UI on port "+ webUIPort); HttpServer.Builder builder = new HttpServer.Builder("hiveserver2"); builder.setPort(webUIPort).setConf(hiveConf); builder.setHost(hiveConf.getVar(ConfVars.HIVE_SERVER2_WEBUI_BIND_HOST));