跳至内容

如何使用 AES 加密 Amazon EMR 中的 Apache HBase 表?

3 分钟阅读
0

我想使用高级加密标准 (AES) 加密 Amazon EMR 中的 Apache HBase 表。

解决方案

**注意:**如果您使用 Amazon Simple Storage Service (Amazon S3) 而不是 Hadoop Distributed File System (HDFS) 作为数据源,请使用服务器端和客户端加密来保护数据

加密新的 Apache HBase 表

完成以下步骤:

  1. 打开 Amazon EMR 控制台

  2. 选择已有 HBase 的集群。或者,使用 HBase 创建新集群

  3. 使用 SSH 连接到 Amazon EMR 集群主节点

  4. 运行 keytool 命令为 AES 加密创建密钥:

    sudo keytool -keystore /etc/hbase/conf/hbase.jks -storetype jceks -storepass:file mysecurefile -genseckey -keyalg AES -keysize 128 -alias example-alias

    **注意:**将 example-alias 替换为您的别名。
    输出示例:

    Output:Enter key password for example-key-store
        (RETURN if same as keystore password):
    Warning:The JCEKS keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standard format using "keytool -importkeystore -srckeystore /etc/hbase/conf/hbase.jks -destkeystore /etc/hbase/conf/hbase.jks -deststoretype pkcs12".
  5. 将以下属性添加到 Amazon EMR 集群中每个节点的 hbase-site.xml 文件中。为 hbase.crypto.keyprovider 参数提供 hbase.jks 路径和密码。另外,在 hbase.crypto.master.key.name 参数中指定您的别名:

    
      <property>
        <name>hbase.crypto.keyprovider.parameters</name>  
        <value>jceks:///etc/hbase/conf/hbase.jks?password=your_password</value>
      </property>
    
      <property>
        <name>hbase.crypto.master.key.name</name>
        <value>example-alias</value>
      </property>
    
      <property>
        <name>hbase.regionserver.hlog.reader.impl</name>
        <value>org.apache.hadoop.hbase.regionserver.wal.SecureProtobufLogReader</value>
      </property>
    
      <property>
        <name>hbase.regionserver.hlog.writer.impl</name>
        <value>org.apache.hadoop.hbase.regionserver.wal.SecureProtobufLogWriter</value>
      </property>
    
      <property>
        <name>hfile.format.version</name>
        <value>3</value>
      </property>
    
      <property>
        <name>hbase.regionserver.wal.encryption</name>
        <value>true</value>
      </property>
    
      <property>
        <name>hbase.crypto.keyprovider</name>
        <value>org.apache.hadoop.hbase.io.crypto.KeyStoreKeyProvider</value>
      </property>

    **注意:**您可以使用自定义加密密钥哈希算法(例如 HBase-25181)来代替默认 MD5 算法。有关详细信息,请参阅 Apache 网站上的 Add options for disabling column family encryption and choosing hash algorithm for wrapped encryption keys。要设置哈希,请使用 hbase.crypto.key.hash.algorithm 配置选项。以下示例使用了 SHA-512 算法:

    <property>
      <name>hbase.crypto.key.hash.algorithm</name>
      <value>SHA-512</value></property>
  6. hbase.jks 文件复制到 hbase.crypto.keyprovider 参数中指定的位置中的所有集群节点:

    cd /etc/hbase/conf
    scp hbase.jks example-host-to-copy:/tmp
    ssh example-to-hostsudo cp /tmp/hbase.jks /etc/hbase/conf/

    **注意:**将 example-host-to-copyexample-to-host 替换为您的节点的公共 DNS 名称。

  7. 在主节点和核心节点上重新启动所有 HBase 服务。然后,在每个核心节点上重复 hbase-regionserver 停止和启动命令。
    **注意:**当您停止和启动 AWS 区域服务器时,可能会影响对集群上 HBase 表的持续读取和写入。请仅在停机期间停止和启动 HBase 进程守护程序。最佳做法是在停止和启动生产集群之前停止和启动测试集群。

    Amazon EMR 5.30.0 及更高版本:

    sudo systemctl stop hbase-mastersudo
    systemctl stop hbase-regionserver
    
    sudo systemctl start hbase-mastersudo
    systemctl start hbase-regionserver

    Amazon EMR 4x 到 Amazon EMR 5.29.0 版本:

    sudo initctl stop hbase-master
    sudo initctl stop hbase-regionserver
    
    sudo initctl start hbase-master
    sudo initctl start hbase-regionserver
  8. 登录 HBase Shell:

    # hbase shell
  9. 使用 AES 加密创建表:

    create 'example-table',{NAME=>'columnfamily',ENCRYPTION=>'AES'}

    **注意:**将 example-table 替换为您的表名。
    输出示例:

    0 row(s) in 1.6760 seconds=> Hbase::Table - example-table1
  10. 确认 AES 加密已开启:

describe 'example-table'

**注意:**将 example-table 替换为您的表名。
输出示例:

Table example-table is ENABLED
table1
COLUMN FAMILIES DESCRIPTION
{NAME => 'columnfamily', BLOOMFILTER => 'ROW', ENCRYPTION => 'AES', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE',
DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
1 row(s) in 0.0320 seconds

加密现有的 Apache HBase 表

完成以下步骤:

  1. 描述未加密的表:

    describe 'example-table'

    **注意:**将 example-table 替换为要描述的表。
    输出示例:

    Table example-table is ENABLED
    table2
    COLUMN FAMILIES DESCRIPTION
    {NAME => 'cf2', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL =>
    'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '6
    5536', REPLICATION_SCOPE => '0'}1 row(s) in 0.0140 seconds2
  2. 开启 AES 加密:

    alter 'example-table',{NAME=>'columnfamily2',ENCRYPTION=>'AES'}

    **注意:**将 example-table 替换为您的表。
    输出示例:

    Updating all regions with the new schema...
    1/1 regions updated.
    Done.0 row(s) in 1.9000 seconds3.
  3. 确认该表已加密:

    describe 'example-table'

    **注意:**将 example-table 替换为您的表。
    输出示例:

    Table example-table is ENABLED
    table2
    COLUMN FAMILIES DESCRIPTION
    {NAME => 'columnfamily2', BLOOMFILTER => 'ROW', ENCRYPTION => 'AES', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE',
    DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}1 row(s) in 0.0120 seconds

    **注意:**如果您在表上创建二级索引,则 WAL 加密可能不起作用,并且会出现 java.lang.NullPointerException 响应。要解决此问题,请在 hbase-site.xml 文件中将 hbase.regionserver.wal.encryption 设置为 false

    <property>      
          <name>hbase.regionserver.wal.encryption</name>
          <value>false</value>
      </property>

相关信息

使用 HBase Shell

Amazon EMR 上 HDFS 中的透明加密

AWS 官方已更新 1 年前