This topic describes how to enable transparent data encryption (TDE) for existing tables.
OceanBase Database provides data encryption methods that are compatible with Oracle databases and encrypts data in tablespaces. OceanBase Database does not support multiple files, and tablespaces are designed for compatibility.
This topic describes how to enable TDE for the t1 table in an encrypted tablespace named sectest_ts1.
Configure encryption
This section provides configuration examples for internal mode and obcloud mode.
Configure TDE in internal mode
In internal mode, the encryption information of the master key is managed in internal tables, and clogs are not encrypted to avoid circular dependency during log replay.
Log in to an Oracle tenant of a cluster as an administrator.
Note (about the master key)
Steps 2 through 6 are used to set
tde_methodand verification parameters ininternalmode, and to establish a tenant master key by creating and opening a Keystore and executingADMINISTER KEY MANAGEMENT SET KEY. If the same configuration has already been completed for this tenant, skip these steps and directly create an encrypted tablespace. For details and examples, see Generate a tenant master key (Oracle-compatible mode).Execute the following statement to enable TDE in internal mode.
The
tde_methodparameter specifies the encryption method for a transparent tablespace. The default value isnone, which indicates that encryption is disabled for the transparent tablespace.For more information about the
tde_methodparameter, see tde_method.Notice
After the
tde_methodparameter is set, it cannot be modified.obclient> ALTER SYSTEM SET tde_method='internal';Execute the following statement to check whether the value of the
tde_methodparameter isinternalon all OBServer nodes of the tenant:obclient> SHOW PARAMETERS LIKE 'tde_method';Create a Keystore.
The SQL syntax is as follows:
obclient>ADMINISTER KEY MANAGEMENT CREATE KEYSTORE keystore_name IDENTIFIED BY password;Here is an example:
obclient> ADMINISTER KEY MANAGEMENT CREATE KEYSTORE sectest1 IDENTIFIED BY **3**;Enable the Keystore.
The SQL syntax is as follows:
obclient> ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY password;You must replace
passwordwith the key specified for the Keystore in the previous step.Here is an example:
obclient> ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY **3**;Execute the following statement to generate the master key:
obclient> ADMINISTER KEY MANAGEMENT SET KEY IDENTIFIED BY password;You must replace
passwordwith the key specified for the Keystore in the previous step.Here is an example:
obclient> ADMINISTER KEY MANAGEMENT SET KEY IDENTIFIED BY **3**;Create a tablespace and specify the encryption algorithm.
You can specify one of the following encryption algorithms:
aes-256,aes-128,aes-192,sm4-cbc,aes-128-gcm,aes-192-gcm,aes-256-gcm, andsm4-gcm.Here is an example:
obclient> CREATE TABLESPACE sectest_ts1 ENCRYPTION USING 'aes-256';
Configure TDE in obcloud mode
The obcloud method is suitable for scenarios where the master key is managed by a unified KMS proxy service.
Log in to the Oracle tenant of the cluster as an administrator.
Note
Steps 2 through 5 are for preparing the encryption method, KMS configuration, and tenant master key in
obcloudmode. If this tenant has already completed the same configuration by referring to Generate a tenant master key (Oracle-compatible mode), you can skip these steps. For ease of reading and operation, the entire process is listed in detail below.Execute the following statement to enable transparent encryption in
obcloudmode.The
tde_methodparameter sets the method for transparent tablespace encryption. The default value isnone, which means transparent tablespace encryption is disabled.For more information about the
tde_methodparameter, see tde_method.Notice
The
tde_methodparameter cannot be modified once set.obclient> ALTER SYSTEM SET tde_method = 'obcloud';Execute the following statement to confirm that the value of the
tde_methodparameter isobcloudon all OBServer nodes of the tenant.obclient> SHOW PARAMETERS LIKE 'tde_method';Execute the following statement to configure the KMS proxy service parameters.
obclient> ALTER SYSTEM SET external_kms_info = ' { "kms_host": "https://kms.example.oceanbase.com", "access_key_id": "******", "access_key_secret": "******", "cmk_id": "your_customer_master_key_id" }';After configuration, the tenant will obtain the master key from KMS. In
obcloudmode, the master key is generated and managed by OCP or OceanBase Cloud KMS, eliminating the need to executeADMINISTER KEY MANAGEMENT CREATE KEYSTORE,SET KEYSTORE OPEN, orSET KEYas required ininternalmode. For more information, see Generate a tenant master key (Oracle-compatible mode).Create a tablespace and specify the encryption algorithm.
You can specify the encryption algorithms
aes-256,aes-128,aes-192,sm4-cbc,aes-128-gcm,aes-192-gcm,aes-256-gcm, orsm4-gcm.Here is an example:
obclient> CREATE TABLESPACE sectest_ts1 ENCRYPTION USING 'aes-256';
Notice
The preceding are example values for external_kms_info. Replace them with your actual KMS endpoint and key information. If you use another KMS integration method, the field format may differ. For more information, see tde_method, external_kms_info, and Generate a tenant master key (Oracle-compatible mode).
Move an existing table into an encrypted tablespace
After configuring the encryption method, you can move existing tables into the encrypted tablespace. The specific steps are as follows:
Log in to an Oracle tenant of the database as a regular user.
Move the
t1table into thesectest_ts1tablespace.obclient> ALTER TABLE t1 TABLESPACE sectest_ts1;Modify the index table and add the indexes in the table to the
sectest_ts1tablespace.Here is an example:
obclient> ALTER INDEX idx1 TABLESPACE sectest_ts1;
Perform TDE on a table
Log in to an Oracle tenant of the database as a regular user.
Set the
progressive_merge_numparameter to configure a full compaction or progressive compaction task for the table.The
progressive_merge_numparameter specifies the number of rounds of progressive compactions on a table. The default value is0, which indicates incremental compaction. If you set the parameter to1, a full compaction is performed.In general, a full compaction is performed on a table. However, a full compaction of a table with a large amount of data may take a long time. In that case, we recommend that you perform a progressive compaction.
Perform a full compaction on the table
Set the
progressive_merge_numparameter to1.obclient> ALTER TABLE t1 set progressive_merge_num = 1;Manually initiate a major compaction.
For more information, see Manually trigger a major compaction.
Note
After a full compaction, all table data is encrypted. You can query the
V$OB_ENCRYPTED_TABLESview to check the encryption status.After the compaction is completed, set the
progressive_merge_numparameter to0.obclient> ALTER TABLE t1 set progressive_merge_num = 0;
Perform a progressive compaction on the table
Set the
progressive_merge_numparameter to a value greater than1, and perform theSHRINK SPACEoperation.Here is an example:
obclient> ALTER TABLE t1 set progressive_merge_num = 3; obclient> ALTER TABLE t1 SHRINK SPACE;Manually initiate multiple rounds of progressive compactions to encrypt all the macroblocks of the table and table indexes.
Execute the following statement to initiate a progressive compaction:
obclient> ALTER SYSTEM MAJOR FREEZE;Note
During a progressive compaction, you can query the
V$OB_ENCRYPTED_TABLESview to check the encryption status in real time.
After the compaction is completed, you can execute the following statement to check the view and verify whether all macroblocks are encrypted:
obclient> SELECT * FROM V$OB_ENCRYPTED_TABLES; +----------+------------+---------------+---------------+-----------+----------------------------------+-------------+------------------+------------------+--------+--------+ | TABLE_ID | TABLE_NAME | TABLESPACE_ID | ENCRYPTIONALG | ENCRYPTED | ENCRYPTEDKEY | MASTERKEYID | BLOCKS_ENCRYPTED | BLOCKS_DECRYPTED | STATUS | CON_ID | +----------+------------+---------------+---------------+-----------+----------------------------------+-------------+------------------+------------------+--------+--------+ | 500005 | T1 | 500004 | aes-256 | YES | xxxxxxxxxxxxxxxxxxxxxxxxxxxx66F3 | xxxx03 | 0 | 0 | NORMAL | 1010 | +----------+------------+---------------+---------------+-----------+----------------------------------+-------------+------------------+------------------+--------+--------+ 1 row in setCheck the query results. If the value of the
BLOCKS_DECRYPTEDfield is0, all macroblocks are encrypted.For more information about the fields in the
V$OB_ENCRYPTED_TABLESview, see V$OB_ENCRYPTED_TABLES.