SQL>createuser sec_admin identified by "Password123"; User created. SQL>grant SYSKM to sec_admin; Grant succeeded. SQL> exit
1 2 3 4 5 6
sqlplus sec_admin as syskm Enter password: password Connected. SQL> show user USER is "SYSKM" SQL>
ADMINISTER KEY MANAGEMENT CREATE KEYSTORE ‘keystore_location’ IDENTIFIED BY software_keystore_password;
1 2 3
SQL> ADMINISTER KEY MANAGEMENT CREATE KEYSTORE '/etc/ORACLE/WALLETS/nocdb' IDENTIFIED BY Password23;
keystore altered.
1.1.3、打开 Software Keystore
ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY software_keystore_password [CONTAINER = ALL | CURRENT];
1 2 3 4 5 6 7
SQL> ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY Password23;
keystore altered. SQL>! ls -l /etc/ORACLE/WALLETS/nocdb total 4 -rw-r--r-- 1 oracle oinstall 2408 Feb 18 10:09 ewallet.p12
1.1.4、设置 Master Encryption Key
ADMINISTER KEY MANAGEMENT SET KEY [USING TAG ‘tag’] IDENTIFIED BY keystore_password [WITH BACKUP [USING ‘backup_identifier’]] [CONTAINER = ALL | CURRENT];
1 2 3
SQL> ADMINISTER KEY MANAGEMENT SET KEY IDENTIFIED BY Password23 with backup USING'nocdb_tde_key_bak';
keystore altered.
select key_id,tag,KEYSTORE_TYPE,USER,CON_ID,BACKED_UP from v$encryption_keys
1 2 3 4 5 6
SQL>select key_id,tag,KEYSTORE_TYPE,USER,CON_ID,BACKED_UP from v$encryption_keys;
KEY_ID TAG KEYSTORE_TYPE USER CON_ID BACKED_UP ------------------------------------------------------------------------------ -------------------- ----------------- ------------------------------ ---------- --------- AZE+jaWrrk8ivxzQvU6S8VUAAAAAAAAAAAAAAAAAAAAAAAAAAAAA SOFTWARE KEYSTORE SYSKM 0NO
create pluggable database tdepdb admin user pdbadmin identified by "Password123"; alter pluggable database tdepdb open instances=all; alter pluggable database tdepdb save state instances=all;
SQL>showuser USERis "SYSKM" SQL> ADMINISTER KEY MANAGEMENT CREATE KEYSTORE '/etc/ORACLE/WALLETS/tdecdb' IDENTIFIED BY Password23; ADMINISTER KEY MANAGEMENT CREATE KEYSTORE '/etc/ORACLE/WALLETS/tdecdb' IDENTIFIED BY Password23 * ERROR at line 1: ORA-65040: operation not allowed fromwithin a pluggable database
CONTAINER is for use in a multitenant environment. Enter ALL to set the keystore in all of the PDBs in this CDB, or CURRENT for the current PDB.
1 2 3 4 5
SQL> ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY Password23; keystore altered. SQL>! ls -l /etc/ORACLE/WALLETS/tdecdb total 4 -rw-r--r-- 1 oracle oinstall 2408 Feb 17 09:32 ewallet.p12
可以添加 CONTAINER = ALL 参数,此cdb 所有的pdb生效,使用 CONTAINER=ALL, 必须在root 容器执行,CDB$ROOT ,并且有 ADMINISTERKEYMANAGEMENT or SYSKM 权限。
CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 4 TDEPDB2 READ WRITE NO SQL>select WRL_TYPE,WRL_PARAMETER,status from V$ENCRYPTION_WALLET;
WRL_TYPE WRL_PARAMETER STATUS -------------------- -------------------------------------------------- ------------------------------ FILE /etc/ORACLE/WALLETS/tdecdb/ CLOSED
SQL> ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY Password23;
keystore altered.
SQL> col WRL_PARAMETER for a30 SQL>select WRL_TYPE,WRL_PARAMETER,status from V$ENCRYPTION_WALLET;
WRL_TYPE WRL_PARAMETER STATUS -------------------- -------------------------------------------------- ------------------------------ FILE /etc/ORACLE/WALLETS/tdecdb/ OPEN_NO_MASTER_KEY
* ERROR at line 1: ORA-28365: wallet isnotopen 如果状态没有open 会提示 ORA-28365: wallet isnotopen。
关闭 的话使用如下命令
1
ADMINISTER KEY MANAGEMENT SET KEYSTORE CLOSE IDENTIFIED BY "Password23" CONTAINER=ALL;
1.2.4、设置 TDE Master Encryption Key
ADMINISTER KEY MANAGEMENT SET KEY [USING TAG ‘tag’] IDENTIFIED BY keystore_password [WITH BACKUP [USING ‘backup_identifier’]] [CONTAINER = ALL | CURRENT];
1 2
ADMINISTER KEY MANAGEMENT SET KEY IDENTIFIED BY Password23 with backup USING'tdetest01_key_bak'; ADMINISTER KEY MANAGEMENT SET KEY USING TAG 'masterkey' IDENTIFIED BY Password23 with backup USING'tdetest01_key_bak';
select key_id,tag,KEYSTORE_TYPE,USER,CON_ID,BACKED_UP from v$encryption_keys
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
SQL>set lines 200 SQL> col tag for a20 SQL> col KEY_ID for a60 SQL>select key_id,tag,KEYSTORE_TYPE,USER,CON_ID,BACKED_UP from v$encryption_keys;
KEY_ID TAG KEYSTORE_TYPE USER CON_ID BACKED_UP ------------------------------------------------------------ ---------- ----------------- ------------------------------ ---------- --------- AcBapz/5vk9Av29fJl/NzJwAAAAAAAAAAAAAAAAAAAAAAAAAAAAA SOFTWARE KEYSTORE SYSKM 0NO
SQL>select key_id,tag,KEYSTORE_TYPE,USER,CON_ID,BACKED_UP from v$encryption_keys;
select tablespace_name, encrypted from dba_tablespaces;
查看表空间是否加密
1.2.6、修改 Software Keystore Password
由于cdb和pdb统一使用一个钱包,修改cdb的密码之后pdb的密码也一并修改。
ADMINISTER KEY MANAGEMENT ALTER KEYSTORE PASSWORD IDENTIFIED BY old_password SET new_password [WITH BACKUP [USING ‘backup_identifier’]];
如果要修改密码需要保证其状态为 open 状态,否则会报
1 2
ERROR at line 1: ORA-46658: keystore not open in the container
以下是打开命令
1
ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY newPassword23;
修改密码具体测试如下:
1 2 3
ADMINISTER KEY MANAGEMENT ALTER KEYSTORE PASSWORD IDENTIFIED BY Password23 set newPassword23 WITH BACKUP; keystore altered. SQL>
修改成功。
1.2.7、TDE 检查状态的脚本
1 2 3 4 5 6 7 8 9 10 11
SELECT*FROM V$ENCRYPTION_WALLET; SELECT*FROM V$ENCRYPTION_KEYS; SELECT WRL_PARAMETER,STATUS,WALLET_TYPE FROM V$ENCRYPTION_WALLET; SELECT KEY_ID,KEYSTORE_TYPE FROM V$ENCRYPTION_KEYS; SELECT KEY_ID FROM V$ENCRYPTION_KEYS; SELECT KEYSTORE_TYPE FROM V$ENCRYPTION_KEYS; SELECT WRL_PARAMETER FROM V$ENCRYPTION_WALLET; SELECT STATUS FROM V$ENCRYPTION_WALLET; SELECT*FROM V$ENCRYPTED_TABLESPACES; SELECT TABLESPACE_NAME, ENCRYPTED FROM DBA_TABLESPACES; SELECT*FROM DBA_ENCRYPTED_COLUMNS;
1.3 在Oracle PDB中进行TDE配置
测试信息: 版本:12.1.0.2 PDB
1 2 3
create pluggable database tdepdb admin user pdbadmin identified by "Password123"; alter pluggable database tdepdb open instances=all; alter pluggable database tdepdb save state instances=all;
SQL>! ls -l /etc/ORACLE/WALLETS/tdecdb total 4 -rw-r--r-- 1 oracle oinstall 2408 Feb 21 10:42 ewallet.p12
1.3.4、启用 Software Keystore
1 2 3 4 5
SQL> ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY Password23; keystore altered. SQL>! ls -l /etc/ORACLE/WALLETS/tdecdb total 4 -rw-r--r-- 1 oracle oinstall 2408 Feb 17 09:32 ewallet.p12
SQL>show con_name CON_NAME ------------------------------ CDB$ROOT SQL> ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY Password23; keystore altered.
SQL> ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY Password23;
keystore altered.
在没有创建 MASTER_KEY的时候,第一次启动其状态是 OPEN_NO_MASTER_KEY
1 2 3
WRL_TYPE WRL_PARAMETER STATUS -------------------- ---------------------------------------- ------------------------------ FILE /etc/ORACLE/WALLETS/tdecdb/ OPEN_NO_MASTER_KEY
如果之前测试过,创建过 MASTER_KEY,状态是 open
1 2 3 4
SQL>select WRL_TYPE,WRL_PARAMETER,status from V$ENCRYPTION_WALLET; WRL_TYPE WRL_PARAMETER STATUS -------------------- ------------------------------ ------------------------------ FILE /etc/ORACLE/WALLETS/tdecdb/OPEN
e.关闭KEYSTORE
关闭 的话使用如下命令
1
ADMINISTER KEY MANAGEMENT SET KEYSTORE CLOSE IDENTIFIED BY "Password23" CONTAINER=ALL;
1.3.5、 创建 Master Encryption Key
每个pdb 都需要创建 Encryption Key。可以通过CONTAINER = ALL 参数创建所有pdb都生效。如果不创建会提示如下ORA-28374: typed master key not found in wallet
1 2
ERROR at line 1: ORA-28374: typed master key not found in wallet
a.创建 Master Encryption Key
1 2
SQL> ADMINISTER KEY MANAGEMENT SET KEY IDENTIFIED BY Password23 with backup; keystore altered.
b.检查 Master Encryption Key
1
select key_id,tag,KEYSTORE_TYPE,USER,CON_ID,BACKED_UP from v$encryption_keys
1 2 3 4 5 6 7
SQL>set lines 200 SQL> col tag for a20 SQL> col KEY_ID for a60 SQL>select key_id,tag,KEYSTORE_TYPE,USER,CON_ID,BACKED_UP from v$encryption_keys KEY_ID TAG KEYSTORE_TYPE USER CON_ID BACKED_UP ------------------------------------------------------------ -------------------- ----------------- ------------------------------ ---------- --------- AWu5OW5+ME/0v1fb0UTWgLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAA SOFTWARE KEYSTORE SYS 0NO
WITH BACKUP创建密钥库的备份。对于基于密码的密钥库,您必须使用此选项。或者,您可以使用该USING子句添加备份的简要说明。将此说明用单引号 (‘ ‘) 括起来。此标识符附加到命名的密钥库文件(例如,作为备份标识符)。