文章目录
环境
系统平台:N/A
版本:9.0.5
文档用途
本文旨在介绍瀚高数据库V9.0.5数据脱敏功能的完整配置步骤。更详尽的数据脱敏功能内容可以参考官方手册相关章节。
详细信息
相关用户和表demo创建步骤如下:
创建相关测试用户
sql
highgo=> \c highgo highgo
用户 highgo 的口令:
hgdb-client-V9.0.5
您现在已经连接到数据库 "highgo",用户 "highgo".
highgo=# create user u1 password 'highgo';
CREATE ROLE
highgo=# create user u2 password 'highgo';
CREATE ROLE
highgo=# create user u3 password 'highgo';
在用户u3下创建测试表,并赋予u1和u2用户select权限
sql
highgo=# \c highgo u3
用户 u3 的口令:
hgdb-client-V9.0.5
您现在已经连接到数据库 "highgo",用户 "u3".
highgo=> create table test(id int, col1 varchar,info text);
CREATE TABLE
highgo=> insert into test values(1,'highgo','database');
INSERT 0 1
highgo=> insert into test values(2,'postgres','opensource');
INSERT 0 1
highgo=> grant select on test to u1,u2;
GRANT
一、启用数据脱敏功能
1.修改配置文件postgresql.conf,给shared_preload_libraries参数追加hg_redaction,并设置hg_redaction.enable=on。随后重新启动数据库。(重启涉及数据库服务中断,需要协调停机窗口进行)
修改前:
sql
highgo=# show shared_preload_libraries ;
shared_preload_libraries
----------------------------------------------------------------------------------------------------------------------
gb18030_2022, restricted_dba, pg_audit, credcheck, hg_sysmac, sqlite_fdw, ora_synonym, liboracle_parser, ivorysql_ora, pg_object
highgo=> show hg_redaction.enable;
hg_redaction.enable
---------------------
off
修改后:
sql
highgo=# show shared_preload_libraries ;
shared_preload_libraries
----------------------------------------------------------------------------------------------------------------------
gb18030_2022, restricted_dba, pg_audit, credcheck, hg_sysmac, sqlite_fdw, ora_synonym, liboracle_parser, ivorysql_ora, pg_object, hg_redaction
highgo=> show hg_redaction.enable;
hg_redaction.enable
---------------------
on
2.登录数据库管理员用户在待脱敏库创建扩展
sql
[highgo@node1 bin]$ ./psql highgo highgo
用户 highgo 的口令:
psql (14.20)
hgdb-client-V9.0.5
输入 "help" 来获取帮助信息.
highgo=# create extension hg_redaction;
CREATE EXTENSION
highgo=# \dx hg_redaction
已安装扩展列表
名称 | 版本 | 架构模式 | 描述
--------------+------+----------+------------------------
hg_redaction | 1.0 | public | support data redaction
(1 行记录)
二、创建一个完整脱敏策略
登录超级管理员/安全员用户创建完整脱敏策略,仅对u1用户生效
sql
highgo=> \c highgo highgo
hgdb-client-V9.0.5
您现在已经连接到数据库 "highgo",用户 "highgo".
highgo=> create redaction policy p1 on test for(user='u1') add column col1 using hg_security.redact_all;
CREATE REDACTION POLICY
登录u1用户查看test表中col1列数据已完全脱敏
sql
highgo=> \c highgo u1
用户 u1 的口令:
hgdb-client-V9.0.5
您现在已经连接到数据库 "highgo",用户 "u1".
highgo=> select * from test;
id | col1 | info
----+----------+------------
1 | xxxxxx | database
2 | xxxxxxxx | opensource
(2 行记录)
登录u2用户查看test表完整数据
sql
highgo=> \c highgo u2
用户 u2 的口令:
hgdb-client-V9.0.5
您现在已经连接到数据库 "highgo",用户 "u2".
highgo=> select * from test;
id | col1 | info
----+----------+------------
1 | highgo | database
2 | postgres | opensource
(2 行记录)