accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject [2/3] git commit: ACCUMULO-3043 Limit to valid and sensitive properties pulled from CredentialProviders
Date Tue, 05 Aug 2014 19:49:30 GMT
ACCUMULO-3043 Limit to valid and sensitive properties pulled from CredentialProviders

We only check CredentialProviders for Sensitive Property's, as such,
when we list out all Property's, we should also adhere to that same
practice.


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/0b892921
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/0b892921
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/0b892921

Branch: refs/heads/master
Commit: 0b892921b281a10690311ab5b08b1fa739b48835
Parents: 16f14bd
Author: Josh Elser <elserj@apache.org>
Authored: Tue Aug 5 15:45:21 2014 -0400
Committer: Josh Elser <elserj@apache.org>
Committed: Tue Aug 5 15:47:45 2014 -0400

----------------------------------------------------------------------
 .../accumulo/core/conf/SiteConfiguration.java   |  11 ++-
 .../core/conf/SiteConfigurationTest.java        |  74 +++++++++++++++++++
 .../accumulo-credentialprovider-site.xml        |  26 +++++++
 core/src/test/resources/site-cfg.jceks          | Bin 0 -> 1441 bytes
 4 files changed, 109 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/0b892921/core/src/main/java/org/apache/accumulo/core/conf/SiteConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/conf/SiteConfiguration.java b/core/src/main/java/org/apache/accumulo/core/conf/SiteConfiguration.java
index a5e14af..f5cfb2b 100644
--- a/core/src/main/java/org/apache/accumulo/core/conf/SiteConfiguration.java
+++ b/core/src/main/java/org/apache/accumulo/core/conf/SiteConfiguration.java
@@ -36,8 +36,11 @@ public class SiteConfiguration extends AccumuloConfiguration {
   private static SiteConfiguration instance = null;
   
   private static Configuration xmlConfig;
-  
-  private SiteConfiguration(AccumuloConfiguration parent) {
+
+  /**
+   * Not for consumers. Call {@link SiteConfiguration#getInstance(AccumuloConfiguration)}
instead
+   */
+  SiteConfiguration(AccumuloConfiguration parent) {
     SiteConfiguration.parent = parent;
   }
   
@@ -103,6 +106,10 @@ public class SiteConfiguration extends AccumuloConfiguration {
     if (null != hadoopConf) {
       try {
         for (String key : CredentialProviderFactoryShim.getKeys(hadoopConf)) {
+          if (!Property.isValidPropertyKey(key) || !Property.isSensitive(key)) { 
+            continue;
+          }
+
           if (filter.accept(key)) {
             char[] value = CredentialProviderFactoryShim.getValueFromCredentialProvider(hadoopConf,
key);
             if (null != value) {

http://git-wip-us.apache.org/repos/asf/accumulo/blob/0b892921/core/src/test/java/org/apache/accumulo/core/conf/SiteConfigurationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/conf/SiteConfigurationTest.java b/core/src/test/java/org/apache/accumulo/core/conf/SiteConfigurationTest.java
new file mode 100644
index 0000000..822e09a
--- /dev/null
+++ b/core/src/test/java/org/apache/accumulo/core/conf/SiteConfigurationTest.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.conf;
+
+import java.io.File;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.accumulo.core.conf.AccumuloConfiguration.AllFilter;
+import org.apache.hadoop.conf.Configuration;
+import org.easymock.EasyMock;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class SiteConfigurationTest {
+  private static boolean isCredentialProviderAvailable;
+
+
+  @BeforeClass
+  public static void checkCredentialProviderAvailable() {
+    try {
+      Class.forName(CredentialProviderFactoryShim.HADOOP_CRED_PROVIDER_CLASS_NAME);
+      isCredentialProviderAvailable = true;
+    } catch (Exception e) {
+      isCredentialProviderAvailable = false;
+    }
+  }
+
+  @Test
+  public void testOnlySensitivePropertiesExtractedFromCredetialProvider() throws SecurityException,
NoSuchMethodException {
+    if (!isCredentialProviderAvailable) {
+      return;
+    }
+
+    SiteConfiguration siteCfg = EasyMock.createMockBuilder(SiteConfiguration.class).addMockedMethod("getHadoopConfiguration")
+        .withConstructor(AccumuloConfiguration.class).withArgs(DefaultConfiguration.getInstance()).createMock();
+    
+    // site-cfg.jceks={'ignored.property'=>'ignored', 'instance.secret'=>'mysecret',
'general.rpc.timeout'=>'timeout'}
+    URL keystore = SiteConfigurationTest.class.getResource("/site-cfg.jceks");
+    Assert.assertNotNull(keystore);
+    String keystorePath = new File(keystore.getFile()).getAbsolutePath();
+    
+    Configuration hadoopConf = new Configuration();
+    hadoopConf.set(CredentialProviderFactoryShim.CREDENTIAL_PROVIDER_PATH, "jceks://file"
+ keystorePath);
+    
+    EasyMock.expect(siteCfg.getHadoopConfiguration()).andReturn(hadoopConf).once();
+
+    EasyMock.replay(siteCfg);
+    
+    Map<String,String> props = new HashMap<String,String>();
+    siteCfg.getProperties(props, new AllFilter());
+    
+    Assert.assertEquals("mysecret", props.get(Property.INSTANCE_SECRET.getKey()));
+    Assert.assertEquals(null, props.get("ignored.property"));
+    Assert.assertEquals(Property.GENERAL_RPC_TIMEOUT.getDefaultValue(), props.get(Property.GENERAL_RPC_TIMEOUT.getKey()));
+  }
+  
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/0b892921/core/src/test/resources/accumulo-credentialprovider-site.xml
----------------------------------------------------------------------
diff --git a/core/src/test/resources/accumulo-credentialprovider-site.xml b/core/src/test/resources/accumulo-credentialprovider-site.xml
new file mode 100644
index 0000000..a88ef27
--- /dev/null
+++ b/core/src/test/resources/accumulo-credentialprovider-site.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
+
+<configuration>
+  <property>
+    <name>general.security.credential.provider.paths</name>
+    <value>file:///</value>
+  </property>
+    
+</configuration>

http://git-wip-us.apache.org/repos/asf/accumulo/blob/0b892921/core/src/test/resources/site-cfg.jceks
----------------------------------------------------------------------
diff --git a/core/src/test/resources/site-cfg.jceks b/core/src/test/resources/site-cfg.jceks
new file mode 100755
index 0000000..ea56ed1
Binary files /dev/null and b/core/src/test/resources/site-cfg.jceks differ


Mime
View raw message