Applicability
OceanBase Database Community Edition does not support transparent data encryption (TDE).
This topic describes how to create an encrypted tablespace to enable TDE for new tables.
OceanBase Database encrypts data in tablespaces. OceanBase Database does not support multiple files, and the concept of tablespaces is designed for compatibility. A tablespace is a collection of tables.
This topic describes how to create a table named t1 in an encrypted tablespace named sectest_ts1 and enable TDE for the table. The procedure consists of two steps:
- Configure the encryption method. This topic provides configuration examples for internal mode and obcloud mode.
- Create a tablespace and specify the encryption algorithm. This topic uses AES-256 as an example.
Limitations
- You cannot enable encryption for the sys tenant.
- After you enable TDE for a tenant, the tenant cannot use other encryption methods. To use another encryption method, recreate a tenant.
Configure encryption
This topic 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 a MySQL tenant of a cluster as an administrator.
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';If yes, execute the following statement to generate the master key:
Note
The statement takes effect only when the value of the
tde_methodparameter isinternalon all OBServer nodes of the tenant.obclient> ALTER INSTANCE ROTATE INNODB MASTER KEY;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. If you set the parameter to'y', the aes-256 algorithm is used.Here is an example:
obclient> CREATE TABLESPACE sectest_ts1 encryption = 'y';
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 a MySQL tenant of the cluster as an administrator.
Note
Steps 2 through 5 prepare the encryption method, KMS configuration, and tenant master key for the
obcloudmethod. If this tenant has already completed the same configuration by referring to Generate a tenant master key (MySQL-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 data encryption by using the
obcloudmethod.The
tde_methodparameter specifies the transparent tablespace encryption method. The default value isnone, which disables transparent tablespace encryption.For more information about the
tde_methodparameter, see tde_method.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 confirmation, execute the following statement to generate the master key.
obclient> ALTER INSTANCE ROTATE INNODB MASTER KEY;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. If you set the parameter to'y', the aes-256 algorithm is used.obclient> CREATE TABLESPACE sectest_ts1 encryption = 'y';
Notice
The values above are examples. Replace them with your actual KMS endpoint and key information. For more information, see tde_method and external_kms_info.
Create a table in an encrypted tablespace
After configuring the encryption method, you can create a new table in an encrypted tablespace. The specific steps are as follows:
Log in to a MySQL tenant of the database as a regular user.
Create a table and specify the tablespace.
obclient> CREATE TABLE t1 (id1 int, id2 int) TABLESPACE sectest_ts1;After the table is created, all transactions related to the table are encrypted.
Check whether the table in the tablespace is marked as encrypted.
Execute the following statement to check whether the value of the
encryptionalgcolumn isaes-256or as specified:obclient> SELECT table_name,encryptionalg,encrypted FROM oceanbase.V$OB_ENCRYPTED_TABLES; +------------+---------------+-----------+ | table_name | encryptionalg | encrypted | +------------+---------------+-----------+ | t1 | aes-256 | YES | +------------+---------------+-----------+ 1 row in setIf the value of the
encryptionalgcolumn isaes-256or as specified, and that of theencryptedcolumn isYES, the table is encrypted.For more information about the fields in the
V$OB_ENCRYPTED_TABLESview, see V$OB_ENCRYPTED_TABLES.