You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2022/08/02 14:42:56 UTC

[GitHub] [accumulo] DomGarguilo commented on a diff in pull request #2197: Per table crypto + other crypto improvements

DomGarguilo commented on code in PR #2197:
URL: https://github.com/apache/accumulo/pull/2197#discussion_r935684965


##########
test/src/main/java/org/apache/accumulo/test/functional/PerTableCryptoIT.java:
##########
@@ -0,0 +1,213 @@
+/*
+ * 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
+ *
+ *   https://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.test.functional;
+
+import static org.apache.accumulo.core.conf.Property.INSTANCE_CRYPTO_FACTORY;
+import static org.apache.accumulo.core.spi.crypto.PerTableCryptoServiceFactory.GENERAL_SERVICE_NAME_PROP;
+import static org.apache.accumulo.core.spi.crypto.PerTableCryptoServiceFactory.TABLE_SERVICE_NAME_PROP;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.accumulo.cluster.standalone.StandaloneAccumuloCluster;
+import org.apache.accumulo.core.client.Accumulo;
+import org.apache.accumulo.core.client.AccumuloClient;
+import org.apache.accumulo.core.client.admin.CloneConfiguration;
+import org.apache.accumulo.core.client.admin.CompactionConfig;
+import org.apache.accumulo.core.client.admin.NewTableConfiguration;
+import org.apache.accumulo.core.clientImpl.ClientContext;
+import org.apache.accumulo.core.clientImpl.OfflineScanner;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.TableId;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.spi.crypto.AESCryptoService;
+import org.apache.accumulo.core.spi.crypto.GenericCryptoServiceFactory;
+import org.apache.accumulo.core.spi.crypto.PerTableCryptoServiceFactory;
+import org.apache.accumulo.harness.AccumuloClusterHarness;
+import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl;
+import org.apache.accumulo.test.TestIngest;
+import org.apache.accumulo.test.VerifyIngest;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PerTableCryptoIT extends AccumuloClusterHarness {
+  private final static Logger log = LoggerFactory.getLogger(PerTableCryptoIT.class);
+  private final String NO_ENCRYPT_STRING = "No on disk encryption detected";
+  private final String ENCRYPTED_STRING = "Encrypted with Params:";
+
+  @Override
+  public void configureMiniCluster(MiniAccumuloConfigImpl cfg, Configuration hadoopCoreSite) {
+    String keyPath =
+        System.getProperty("user.dir") + "/target/mini-tests/PerTableCrypto-testkeyfile";
+    cfg.setProperty(INSTANCE_CRYPTO_FACTORY, PerTableCryptoServiceFactory.class.getName());
+    cfg.setProperty(GENERAL_SERVICE_NAME_PROP, AESCryptoService.class.getName());
+    cfg.setProperty(AESCryptoService.KEY_URI_PROPERTY, keyPath);
+
+    // setup key file
+    try {
+      Path keyFile = new Path(keyPath);
+      FileSystem fs = FileSystem.getLocal(new Configuration());
+      fs.delete(keyFile, true);
+      if (fs.createNewFile(keyFile))
+        log.info("Created keyfile at {}", keyPath);
+      else
+        log.error("Failed to create key file at {}", keyPath);
+
+      try (FSDataOutputStream out = fs.create(keyFile)) {
+        out.writeUTF("sixteenbytekey"); // 14 + 2 from writeUTF
+      }
+    } catch (Exception e) {
+      log.error("Exception during configure", e);
+    }
+  }
+
+  @Test
+  public void testMultipleTablesAndWALs() throws Exception {
+    var tables = getUniqueNames(3);
+    Map<String,String> props = new HashMap<>();
+    NewTableConfiguration tableConfig = new NewTableConfiguration();
+    TableId tableId1;
+    TableId tableId2;
+
+    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
+      // maybe with more splits WAL will be easier to observe?
+      props.put(Property.TABLE_SPLIT_THRESHOLD.getKey(), "75K");
+
+      // table 0 plain text
+      c.tableOperations().create(tables[0]);
+      TableId tableId0 = TableId.of(c.tableOperations().tableIdMap().get(tables[0]));
+      VerifyIngest.VerifyParams params = new VerifyIngest.VerifyParams(getClientProps(), tables[0]);
+      TestIngest.ingest(c, params);
+      VerifyIngest.verifyIngest(c, params);
+
+      // verify data was not encrypted
+      System.out.println("-------------" + checkTableEncryption(tableId0, false));
+
+      // encrypt table 1
+      props.clear();

Review Comment:
   It looks like `props` is not used before it is cleared. Is this intended?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org