Purpose
This statement is used to create a sensitive data protection rule.
Privilege requirements
To execute the CREATE SENSITIVE RULE statement, the current user must have the CREATE SENSITIVE RULE privilege. For more information about OceanBase AI Database privileges, see Permission classification.
Syntax
CREATE SENSITIVE RULE rule_name
ON sensitive_field_list
USING ENCRYPTION [ = { DEFAULT | encryption_method } ];
Parameters
The specific parameters are described as follows:
Parameter |
Data type |
Default Value |
Description |
|---|---|---|---|
| rule_name | Character | The name of the encryption rule, which must be unique within the tenant. | |
| sensitive_field_list | Character | Column to be encrypted, in the format of db.table(col1, col2), db2.table2(col3, col4), ..., where each sensitive item specifies one or more columns in the table, separated by commas. Multiple sensitive items are separated by commas to specify the columns protected by the sensitive rule. A single rule can specify multiple columns across multiple users and tables. Parameter description:
|
|
| encryption_method | Character | USING ENCRYPTION You can omit parameters to use the default encryption algorithm, which is aes-256, which actually refers to the AES-256-ECB encryption algorithm. It can also be written as USING ENCRYPTION = DEFAULT, which have the same meaning. |
The encryption_method parameter can take the following values:
Values (used in SQL syntax) |
Actual Encryption Algorithm Used |
Key Length |
schema |
Description |
|---|---|---|---|---|
| aes-256 | AES-256-ECB | 256-bit | ECB | Default Algorithm |
| aes-128 | AES-128-ECB | 128-bit | ECB | |
| aes-192 | AES-192-ECB | 192-bit | ECB | |
| aes-128-gcm | AES-128-GCM | 128-bit | GCM | High security level, supports Authenticated Encryption with Additional Data (AEAD) |
| aes-192-gcm | AES-192-GCM | 192-bit | GCM | High security level, supports Authenticated Encryption with Additional Data (AEAD) |
| aes-256-gcm | AES-256-GCM | 256-bit | GCM | High security level, supports Authenticated Encryption with Additional Data (AEAD) |
| sm4-cbc | SM4-CBC | CBC | High security level | |
| sm4-GCM | SM4-GCM | GCM | High security level, supports Authenticated Encryption with Additional Data (AEAD) |
When creating sensitive data rules, note the following considerations:
- Rules take effect immediately after creation.
- Rule names are globally unique at the tenant level, but only globally unique for sensitive rules, not globally unique at the object level. That is, a table named
R1and a sensitive rule namedR1can exist simultaneously, but two sensitive rules namedR1cannot exist simultaneously. - Data protection for sensitive rules is only at the column level and does not support table-level or database-level protection. Therefore, you cannot create a data protection rule that applies to an entire table or database. If you need to encrypt all columns in a table, you must explicitly list all column names.
- A rule can specify protection for one or more columns. Cross-database and cross-table access is allowed.
When creating sensitive rules, the following limitations apply:
- Data protection rules can only be applied to columns in user tables (including views). They cannot be applied to columns in system tables.
- A column can be protected by only one rule.
Examples
An example is as follows:
-- Create sensitive rule r1 to protect tbl1(a), tbl2(b, c), and db2.tbl3(e,f).
-- Use the default encryption algorithm AES-256-ECB
CREATE SENSITIVE RULE r1 ON tbl1(a), tbl2(b, c), db2.tbl3(e,f)
USING ENCRYPTION;
-- Create sensitive rule r2 to protect tbl4(x, y), tbl5(z);
-- Using the SM4-CBC Encryption Algorithm
CREATE SENSITIVE RULE r2 ON tbl4(x, y), tbl5(z)
USING ENCRYPTION = 'sm4-cbc';