1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase;
19
20 import java.io.IOException;
21
22 import org.apache.hadoop.conf.Configuration;
23 import org.apache.hadoop.hbase.Waiter.Predicate;
24 import org.apache.hadoop.hbase.client.HBaseAdmin;
25 import org.apache.hadoop.hbase.io.crypto.KeyProviderForTesting;
26 import org.apache.hadoop.hbase.io.hfile.HFile;
27 import org.apache.hadoop.hbase.io.hfile.HFileReaderV3;
28 import org.apache.hadoop.hbase.io.hfile.HFileWriterV3;
29 import org.apache.hadoop.hbase.regionserver.wal.HLog;
30 import org.apache.hadoop.hbase.regionserver.wal.SecureProtobufLogReader;
31 import org.apache.hadoop.hbase.regionserver.wal.SecureProtobufLogWriter;
32 import org.apache.hadoop.hbase.util.Bytes;
33 import org.apache.hadoop.util.ToolRunner;
34 import org.apache.log4j.Level;
35 import org.apache.log4j.Logger;
36
37 import org.junit.Before;
38 import org.junit.experimental.categories.Category;
39
40 @Category(IntegrationTests.class)
41 public class IntegrationTestIngestWithEncryption extends IntegrationTestIngest {
42
43 static {
44
45
46 Logger.getLogger(HFileReaderV3.class).setLevel(Level.TRACE);
47 Logger.getLogger(HFileWriterV3.class).setLevel(Level.TRACE);
48 Logger.getLogger(SecureProtobufLogReader.class).setLevel(Level.TRACE);
49 Logger.getLogger(SecureProtobufLogWriter.class).setLevel(Level.TRACE);
50 }
51
52 @Override
53 public void setUpCluster() throws Exception {
54 util = getTestingUtil(null);
55 Configuration conf = util.getConfiguration();
56 conf.setInt(HFile.FORMAT_VERSION_KEY, 3);
57 if (!util.isDistributedCluster()) {
58
59
60
61 conf.set(HConstants.CRYPTO_KEYPROVIDER_CONF_KEY, KeyProviderForTesting.class.getName());
62 conf.set(HConstants.CRYPTO_MASTERKEY_NAME_CONF_KEY, "hbase");
63 conf.setClass("hbase.regionserver.hlog.reader.impl", SecureProtobufLogReader.class,
64 HLog.Reader.class);
65 conf.setClass("hbase.regionserver.hlog.writer.impl", SecureProtobufLogWriter.class,
66 HLog.Writer.class);
67 conf.setBoolean(HConstants.ENABLE_WAL_ENCRYPTION, true);
68 }
69 super.setUpCluster();
70 }
71
72 @Before
73 @Override
74 public void setUp() throws Exception {
75
76
77 super.setUp();
78
79
80
81 final HBaseAdmin admin = util.getHBaseAdmin();
82 HTableDescriptor tableDescriptor =
83 new HTableDescriptor(admin.getTableDescriptor(Bytes.toBytes(getTablename())));
84 for (HColumnDescriptor columnDescriptor: tableDescriptor.getColumnFamilies()) {
85 columnDescriptor.setEncryptionType("AES");
86 LOG.info("Updating CF schema for " + getTablename() + "." +
87 columnDescriptor.getNameAsString());
88 admin.disableTable(getTablename());
89 admin.modifyColumn(getTablename(), columnDescriptor);
90 admin.enableTable(getTablename());
91 util.waitFor(30000, 1000, true, new Predicate<IOException>() {
92 @Override
93 public boolean evaluate() throws IOException {
94 return admin.isTableAvailable(getTablename());
95 }
96 });
97 }
98 }
99
100 public static void main(String[] args) throws Exception {
101 Configuration conf = HBaseConfiguration.create();
102 IntegrationTestingUtility.setUseDistributedCluster(conf);
103 int ret = ToolRunner.run(conf, new IntegrationTestIngestWithEncryption(), args);
104 System.exit(ret);
105 }
106 }