CREATE REDACTION POLICY
Function
CREATE REDACTION POLICY creates a data redaction policy for a table.
Precautions
- The data masking feature is controlled by feature_support_options. If error information "REDACTION POLICY is not yet supported, please add enable_data_redaction into feature_support_options." or "Cannot use the feature of data redaction, please drop existed redaction policy or add enable_data_redaction into feature_support_options." is displayed, the data masking feature is not enabled. In this case, you need to contact technical support to set feature_support_options.
- Only the table object owner and users who have been granted the gs_redaction_policy preset role are authorized to create data masking policies.
- Data masking policies can be created for regular tables and non-EXTERNAL-SCHEMA foreign tables (such as OBS, HDFS, GDS, and foreign tables for coordinated analysis), but not for system catalogs, EXTERNAL SCHEMA foreign tables, temporary tables, UNLOGGED tables, views, or functions.
- Synonyms cannot be used to create redaction policies for ordinary table objects.
- Table objects and redaction policies have a one-to-one mapping relationship. A redaction policy is a collection of data redaction functions that can be applied to multiple columns in a table. You can set different redaction functions for different columns.
- A redaction policy is enabled by default upon its creation, that is, the enable parameter of the policy is true by default.
- Redaction policies do not take effect on users with the sysadmin permission. Data in the redacted columns is always visible to such users.
- Data redaction policies can be matched with specified roles.
Syntax
1 2 3 |
CREATE REDACTION POLICY [IF NOT EXISTS] policy_name ON table_name [ { BEFORE | AFTER } old_policy_name ] [ WHEN (when_expression) ] [ ADD COLUMN column_name WITH redaction_function_name ( [ argument [, ...] ] )] [, ... ]; |
Parameter Description
Parameter |
Description |
Value Range |
---|---|---|
policy_name |
Specifies the name of a redaction policy. |
- |
table_name |
Specifies the name of the table to which the redaction policy is applied. |
- |
BEFORE | AFTER |
Specifies the relative location where the current policy is created. Generally, one masking policy is used for one table. The default value indicates that the current policy is created after the last candidate policy of the target table recorded in the current system catalog. |
- |
WHEN ( when_expression ) |
Specifies the expression used for the redaction policy to take effect. The redaction policy takes effect only when this expression is true. |
When a query statement is querying a table where a redaction policy is enabled, the redacted data is invisible in the query only if the WHEN expression for the redaction policy is true. Generally, the WHEN clause is used to specify the users for which the redaction policy takes effect. The WHEN clause must comply with the following rules:
|
column_name |
Specifies the name of the table column to which the redaction policy is applied. |
- |
redaction_function_name |
Specifies the redaction function applied to the specified table column. |
- |
arguments |
Specifies the list of arguments of the redaction function. |
|
Examples
Create redaction policy for a specified user.
- Create users alice and matu:
1 2
CREATE ROLE alice PASSWORD '{password}'; CREATE ROLE matu PASSWORD '{password}';
- Create a table object emp as user alice, and insert data into the table.
1 2
CREATE TABLE emp(id int, name varchar(20), salary NUMERIC(10,2)); INSERT INTO emp VALUES(1, 'July', 1230.10), (2, 'David', 999.99);
- Create a redaction policy mask_emp for the emp table as user alice to make the salary column invisible to user matu.
1
CREATE REDACTION POLICY mask_emp ON emp WHEN(current_user = 'matu') ADD COLUMN salary WITH mask_full(salary);
- Grant the SELECT permission on the emp table to user matu as user alice.
1
GRANT SELECT ON emp TO matu;
- Switch to user matu.
1
SET ROLE matu PASSWORD '{password}';
- Query the emp table. Data in the salary column has been redacted.
1
SELECT * FROM emp;
Create redaction policy for the role.
- Create a role redact_role.
1
CREATE ROLE redact_role PASSWORD '{password}';
- Add users matu and alice to the role redact_role.
1
GRANT redact_role to matu,alice;
- Create a table object emp1 as the administrator and insert data.
1 2
CREATE TABLE emp1(id int, name varchar(20), salary NUMERIC(10,2)); INSERT INTO emp1 VALUES(3, 'Rose', 2230.20), (4, 'Jack', 899.88);
- Create a redaction policy mask_emp1 for the table object emp1 as the administrator to make the salary column invisible to role redact_role.
1
CREATE REDACTION POLICY mask_emp1 ON emp1 WHEN(pg_has_role(current_user, 'redact_role', 'member')) ADD COLUMN salary WITH mask_full(salary);
If no user is specified, the current user (current_user) is used by default.
1
CREATE REDACTION POLICY mask_emp1 ON emp1 WHEN (pg_has_role('redact_role', 'member')) ADD COLUMN salary WITH mask_full(salary);
- The administrator grants the SELECT permission on the table emp1 to the user matu.
1
GRANT SELECT ON emp1 TO matu;
- Switch to user matu.
1
SET ROLE matu PASSWORD '{password}';
- Query the emp table. Data in the salary column has been redacted.
1
SELECT * FROM emp1;
Helpful Links
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot