use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder in project hbase by apache.
the class TestEncryptionKeyRotation method testMasterKeyRotation.
@Test
public void testMasterKeyRotation() throws Exception {
// Create the table schema
TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(TableName.valueOf("default", name.getMethodName()));
ColumnFamilyDescriptorBuilder columnFamilyDescriptorBuilder = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf"));
String algorithm = conf.get(HConstants.CRYPTO_KEY_ALGORITHM_CONF_KEY, HConstants.CIPHER_AES);
columnFamilyDescriptorBuilder.setEncryptionType(algorithm);
columnFamilyDescriptorBuilder.setEncryptionKey(EncryptionUtil.wrapKey(conf, "hbase", initialCFKey));
tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptorBuilder.build());
TableDescriptor tableDescriptor = tableDescriptorBuilder.build();
// Create the table and some on disk files
createTableAndFlush(tableDescriptor);
// Verify we have store file(s) with the initial key
List<Path> storeFilePaths = findStorefilePaths(tableDescriptor.getTableName());
assertTrue(storeFilePaths.size() > 0);
for (Path path : storeFilePaths) {
assertTrue("Store file " + path + " has incorrect key", Bytes.equals(initialCFKey.getEncoded(), extractHFileKey(path)));
}
// Now shut down the HBase cluster
TEST_UTIL.shutdownMiniHBaseCluster();
// "Rotate" the master key
conf.set(HConstants.CRYPTO_MASTERKEY_NAME_CONF_KEY, "other");
conf.set(HConstants.CRYPTO_MASTERKEY_ALTERNATE_NAME_CONF_KEY, "hbase");
// Start the cluster back up
TEST_UTIL.startMiniHBaseCluster();
// Verify the table can still be loaded
TEST_UTIL.waitTableAvailable(tableDescriptor.getTableName(), 5000);
// Double check that the store file keys can be unwrapped
storeFilePaths = findStorefilePaths(tableDescriptor.getTableName());
assertTrue(storeFilePaths.size() > 0);
for (Path path : storeFilePaths) {
assertTrue("Store file " + path + " has incorrect key", Bytes.equals(initialCFKey.getEncoded(), extractHFileKey(path)));
}
}
Aggregations