VastbaseG100

基于openGauss内核开发的企业级关系型数据库。

Menu

用户数据保护

带有安全属性的用户数据输出

功能描述

确保用户数据(表)输出到数据库之外时,数据库安全功能应执行DAC和MAC(如启用),且输出关联的行级敏感标记即隐藏的系统列ogmac_label(如果存在)。

语法格式

COPY { table_name [ ( column_name [, ...] ) ]  }
TO { 'filename' | PROGRAM 'command' | STDOUT }
[ [ WITH ] ( option [, ...] ) ]

新增option:MAC_LABEL,MAC_LABEL选项仅支持copy table (column, …) to … 形式。

copy (select * from ) to … 不支持with (MAC_LABEL) 选项,copy to … 不支持 FIXED FORMATTER … with (MAC_LABEL)。

示例

1.创建用户user1
create user user_select password 'Bigdata@123';
create user user_insert password 'Bigdata@123';
create table t1(a int,b varchar2(20));
2.创建敏感标记
create security label label1 'L6:G1';
create security label u_insert 'L3:G1';
create security label u_select 'L5:G1';
SECURITY LABEL ON TABLE t1 IS 'label1';
SECURITY LABEL ON ROLE user_select IS 'u_select';
SECURITY LABEL ON ROLE user_insert IS 'u_insert';
grant all on table t1 to user_select;
grant all on table t1 to user_insert;
3.切换到user_insert
SET SESSION AUTHORIZATION user_insert PASSWORD 'Bigdata@123';
insert into t1 values(1,'a');
insert into t1 values(2,'b');
4.切换到user_select,导出数据
SET SESSION AUTHORIZATION user_select PASSWORD 'Bigdata@123';
copy t1 to '/tmp/t1.txt' with (mac_label);

不带安全属性的用户数据输入

功能描述

确保用户数据(表)从数据库之外输入到数据库时,数据库安全功能应执行DAC和MAC(如果被启动),输入数据中包含行级敏感标记即隐藏的系统列ogmac_label时,如果指定了导入参数ignore_mac_label则删除第一列(隐藏的系统列ogmac_label)数据。不指定导入参数ignore_mac_label时,按照原有逻辑导入数据。

语法格式

COPY { table_name [ ( column_name [, ...] )  }
FROM { 'filename' | STDIN }
[ [ WITH ] ( option [, ...] ) ]

新增option:ignore_mac_label。

示例

1.创建用户user1
create user user_select sysadmin password 'Bigdata@123';
create user user_insert sysadmin password 'Bigdata@123';
create table t1(a int,b varchar2(20),c date,d clob);

2.创建敏感标记
create security label label1 'L6:G1';
create security label u_insert 'L3:G1';
create security label u_select 'L5:G1';
SECURITY LABEL ON TABLE t1 IS 'label1';
SECURITY LABEL ON ROLE user_select IS 'u_select';
SECURITY LABEL ON ROLE user_insert IS 'u_insert';
grant all on table t1 to user_select;
grant all on table t1 to user_insert;

3.切换到user_insert
SET SESSION AUTHORIZATION user_insert PASSWORD 'Bigdata@123';
insert into t1 values(1,'a','2021-02-01','一');
insert into t1 values(2,'b','2021-02-02','二');

4.切换到user_select
SET SESSION AUTHORIZATION user_select PASSWORD 'Bigdata@123';
copy t1 to STDOUT with (format 'text', delimiter ',',mac_label);

5.导入数据
create table t3(a int,b varchar2(20),c date,d clob);
copy t3 from STDIN with (format 'text', delimiter ',',ignore_mac_label);
输入第4步输出的结果
17179869185,1,a,2021-02-01 00:00:00,一
17179869185,1,b,2021-02-02 00:00:00,二
\.