Salta al contenuto

Come si utilizza AES per crittografare una tabella Apache HBase in Amazon EMR?

5 minuti di lettura
0

Desidero utilizzare Advanced Encryption Standard (AES) per crittografare una tabella Apache HBase in Amazon EMR.

Risoluzione

Nota: se utilizzi Amazon Simple Storage Service (Amazon S3) come origine dati anziché Hadoop Distributed File System (HDFS), utilizza la crittografia lato server e lato client per proteggere i dati.

Crittografa una nuova tabella Apache HBase

Completa i seguenti passaggi:

  1. Apri la console Amazon EMR.

  2. Scegli un cluster che abbia già HBase. Oppure crea un nuovo cluster con HBase.

  3. Utilizza SSH per connetterti al nodo primario del cluster Amazon EMR.

  4. Esegui il comando keytool per creare una chiave segreta per la crittografia AES:

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

    Nota: sostituisci a example-alias il tuo alias.
    Esempio di output:

    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. Aggiungi le seguenti proprietà al file hbase-site.xml per ogni nodo del cluster Amazon EMR. Fornisci il percorso e la password hbase.jks per il parametro hbase.crypto.keyprovider. Inoltre, specifica il tuo alias nel parametro 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>

    Nota: invece dell'algoritmo MD5 predefinito, è possibile utilizzare un algoritmo hash della chiave di crittografia personalizzato, comeHBase-25181. Per ulteriori informazioni, consulta Add options for disabling column family encryption and choosing hash algorithm for wrapped encryption keys sul sito web di Apache. Per impostare l'hash, utilizza l'opzione di configurazione hbase.crypto.key.hash.algorithm. L'esempio seguente utilizza l'algoritmo SHA-512:

    <property>
      <name>hbase.crypto.key.hash.algorithm</name>
      <value>SHA-512</value></property>
  6. Copia il file hbase.jks in tutti i nodi del cluster nella posizione specificata nel parametro 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/

    Nota: sostituisci a example-host-to-copy e a example-to-host i nomi DNS pubblici dei tuoi nodi.

  7. Riavvia tutti i servizi HBase sui nodi primari e principali. Quindi ripeti i comandi di arresto e avvio hbase-regionserver su ogni nodo principale.
    Nota: quando arresti e avvii i server della regione AWS, potresti influire sulle letture e scritture in corso sulle tabelle HBase del tuo cluster. Arresta e avvia i daemon HBase solo durante i tempi di inattività. È consigliabile interrompere e avviare un cluster di test prima di arrestare e avviare un cluster di produzione.

    Amazon EMR 5.30.0 e versioni successive:

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

    Versioni da Amazon EMR 4x ad 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. Accedi alla shell HBase:

    # hbase shell
  9. Crea una tabella con crittografia AES:

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

    Nota: sostituisci a example-table il nome della tua tabella.
    Esempio di output:

    0 row(s) in 1.6760 seconds=> Hbase::Table - example-table1
  10. Verifica che la crittografia AES sia attiva:

describe 'example-table'

Nota: sostituisci a example-table il nome della tua tabella.
Esempio di output:

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

Crittografa una tabella Apache HBase esistente

Completa i seguenti passaggi:

  1. Descrivi la tabella non crittografata:

    describe 'example-table'

    Nota: sostituisci a example-table la tabella che desideri descrivere.
    Esempio di output:

    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. Attiva la crittografia AES:

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

    Nota: sostituisci a example-table la tua tabella.
    Esempio di output:

    Updating all regions with the new schema...
    1/1 regions updated.
    Done.0 row(s) in 1.9000 seconds3.
  3. Verifica che la tabella sia crittografata:

    describe 'example-table'

    Nota: sostituisci a example-table la tua tabella.
    Esempio di output:

    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

    Nota: se crei un indice secondario nella tabella, la crittografia WAL potrebbe non funzionare e riceverai una risposta java.lang.NullPointerException. Per risolvere questo problema, imposta hbase.regionserver.wal.encryption su false nel file hbase-site.xml:

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

Informazioni correlate

Usare la shell HBase

Crittografia trasparente in HDFS su Amazon EMR

AWS UFFICIALEAggiornata un anno fa