This topic describes how to create an encrypted tablespace to enable storage encryption for a new table.
Limitations
You cannot enable encryption for the
systenant.After you enable storage encryption for a tenant, the tenant cannot use other encryption methods. To use another encryption method, recreate a tenant.
Background information
OceanBase Database encrypts data in tablespaces. Tablespaces are designed to make OceanBase Database compatible with Oracle Database. You can consider a tablespace as a collection of tables.
The following sections describe how to enable data storage encryption for the t1 table in the encrypted sectest_ts1 tablespace.
Enable storage encryption 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 on to a MySQL tenant as an administrator.
Execute the following statement to enable storage encryption 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, andsm4-cbc. If you set thesectest_ts1 encryptionparameter toy, theaes-256algorithm is used.For example:
obclient> CREATE TABLESPACE sectest_ts1 encryption = 'y';
Check whether encryption is enabled as expected
To check whether encryption is enabled as expected, perform the following steps:
Log on to a MySQL tenant of the database as a regular user.
Log on to the database, 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 table t1 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 FROM oceanbase.v$encrypted_tables; +------------+---------------+ | table_name | encryptionalg | +------------+---------------+ | t1 | aes-256 | +------------+---------------+ 1 row in setIf the value of the
encryptionalgcolumn isaes-256or as specified, the table is encrypted.For more information about fields in the
v$encrypted_tablesview, see v$encrypted_tables.