Hologres provides the data masking feature to allow you to mask data by column. After you enable this feature, sensitive information is masked in query results. This helps protect your sensitive and private data. This topic describes how to enable the data masking feature, and query and delete data masking configurations.
Background information
In the era of big data, new technologies such as big data, cloud computing, and artificial intelligence (AI) are widely applied. These technologies provide powerful support for in-depth data mining and analysis and help enterprises explore the potential value of big data. However, sensitive and private data is difficult to protect in the face of these technologies.
Hologres provides the data masking feature to protect and prevent your sensitive and private data from leaking during sharing, mining, and analysis.
Limits
- For security considerations, Hologres does not allow data to be imported from tables
and columns that have masking rules configured to those that do not have masking rules
configured. If you attempt to import data from a table or column that has masking
rules configured to a table or column that does not have masking rules configured,
the following error is returned:
ERROR: The insert table has not set SECURITY LABEL
- Data masking may affect query performance. The severity of the effect varies based on the masking method and data volume. The query performance may degrade by 10% to 20%, or even by several times in extreme circumstances.
Use the data masking feature
Hologres allows you to configure data masking for a specific column or a specific user. Before you can use this feature, you must log on to the database and enable data masking. Then, you can configure data masking for a specific column or a specific user.
Advanced settings
- Configure data masking for different users
By default, the data masking feature is enabled for all users. You can disable data masking for specific users.
- Syntax
SECURITY LABEL FOR hg_anon ON ROLE user_name IS 'all:unmasked';
Parameter Description user_name The ID of the account. You can obtain the account ID on the Basic Information page. - Example
Execute the following statement to disable data masking for a user whose account ID is 1365xxxxxxxxxxxx:
SECURITY LABEL FOR hg_anon ON ROLE "1365xxxxxxxxxxxx" IS 'all:unmasked';
- Related statements
- Query the data masking configuration for a user
select usename, label from pg_shseclabel s inner join pg_catalog.pg_user u on s.objoid = u.usesysid;
- Delete the data masking configuration for a user
SECURITY LABEL FOR hg_anon ON ROLE "1365xxxxxxxxxxxx" IS NULL;
- Query the data masking configuration for a user
- Syntax
- Create custom data masking rules
If the default label_name values do not meet your requirements, you can modify the hg_anon_labels Global User Configuration (GUC) parameter to create custom data masking rules.
- Syntax
ALTER DATABASE <db_name> SET hg_anon_labels = '[ {"label": <label_name1>, "method", <method1>}, {"label": <label_name2>, "method", <method2>}, ... ]'; -- Set label_name to specify a name for the data masking rule and set the method parameter to configure the rule.
Note After you execute the ALTER DATABASE statement, the new settings apply to subsequent sessions, but not the current session. You must reconnect to the database to check the new settings. You can execute the following statement to check whether the new settings have taken effect:show hg_anon_enable;
- Example
ALTER DATABASE test_db SET hg_anon_labels = '[ {"label":"ip", "method":{"desensType":"mask", "type":"ip"}}, {"label":"email", "method":{"desensType":"mask", "type":"email"}}, {"label":"name", "method":{"desensType":"mask", "type":"name"}}, {"label":"first_mask", "method":{"desensType":"mask", "type":"user_define", "before":1, "after":0}}, {"label":"hash", "method":{"desensType":"hash", "type":"md5", "salt":""}}]';
- Parameters
Data masking rule Description Sample result {"desensType":"mask", "type":"ip"} Masks the IP address. 192.*.*.* {"desensType":"mask", "type":"email"} Masks the email address. abc***@gmail.com {"desensType":"mask", "type":"name"} Masks the name. *Wu {"desensType":"hash", "type":"md5", "salt":""} Uses the MD5 algorithm for masking. e086aa137fa19f67d27b39d0eca186103228f322c9c98a125554a24f875f0f7e {"label":"first_mask", "method":{"desensType":"mask", "type":"user_define", "before":1, "after":0}}{"label":"last_mask", "method":{"desensType":"mask", "type":"user_define", "before":0, "after":1}} Performs custom data masking. N/A
- Syntax
Use examples
The following procedure provides an example on how to use the data masking feature.
FAQ
- Problem description: Data is not masked after the procedure described in the example is performed.
- Possible causes:
- Data masking is disabled for specific users.
- The label_name parameter is not configured.
- Solutions:
- Execute the following statement to check whether data masking is disabled for specific
users:
By default, the query result is empty, which indicates that data masking is enabled for all users. If the query result is not empty, data masking is disabled for specific users and you must enable data masking for these users. For more information, see the "Advanced settings" section of this topic.select usename , label from pg_shseclabel s inner join pg_catalog.pg_user u on s.objoid = u.usesysid;
- Execute the following statement to check the label_name values:
If the query result does not contain values such as ip, you must execute the following statement to configure the label_name values:show hg_anon_labels;
For more information about the rules corresponding to the label_name values, see the default label_name values table of this topic.ALTER DATABASE compress_test SET hg_anon_labels = '[ {"label":"ip", "method":{"desensType":"mask", "type":"ip"}}, {"label":"email", "method":{"desensType":"mask", "type":"email"}}, {"label":"name", "method":{"desensType":"mask", "type":"name"}}, {"label":"id", "method":{"desensType":"mask", "type":"id"}}, {"label":"phone", "method":{"desensType":"mask", "type":"phone"}}, {"label":"bank_id", "method":{"desensType":"mask", "type":"bank_id"}}, {"label":"hash", "method":{"desensType":"hash", "type":"md5", "salt":""}}, null ]';
- Execute the following statement to check whether data masking is disabled for specific
users: