uxdb创建测试用户:
create user testuser1 password '1qaz!QAZ'; create user testuser2 password '1qaz!QAZ';
uxop创建策略并进行主体标记:
select mac_create_policy('p1','1,2,3,4','s1,s2,s3,s4');
该标记的等级依次为1,2,3,4。
该标记的范围为1~15(20+21+22+23)。
分别对两个用户设置最大读标记、最大写标记、最小写标记、默认会话标记和默认写标记:
select mac_set_user_label('testuser1', 'p1', '3:s1,s2,s3', '3:s1,s3', '2:s1','1:s1','3:s1,s3'); select mac_set_user_label('testuser2', 'p1', '4:s1,s2,s3', '4:s1,s2', '4:s1,s2','2:s1','4:s1,s2');
testuser1的最大读标记'3:s1,s2,s3'中冒号前面的3表示等级为3,冒号后面的s1,s2,s3表示范围为7(20+21+22);最大写标记'3:s1,s3'中冒号前面的3表示等级为3,冒号后面的's1,s3'表示范围为5(20+22)。其他标记和范围也如此计算。结果如下表:
表?5.2.?主体标记范围(行级)
测试用户 | 最大读 | 最大写 | 最小写 | 默认会话 | 默认写 |
---|---|---|---|---|---|
testuser1 | 3:7 | 3:5 | 2:1 | 1:1 | 3:5 |
testsuer2 | 4:7 | 4:3 | 4:3 | 2:1 | 4:3 |
uxop创建表并对表设置行标记:
create table public.table_super (i int, k text); grant all on table_super to public ;
对表设置行标记:
select mac_apply_row_policy('public','table_super','p1');
插入数据并查看标记:
testuser1执行:
insert into table_super values(1,'wang');
(根据行级标记规则,insert标记为默认写标记,testuser1插入的数据标记为3:5)
testuser2执行:
insert into table_super values(2,'zhang');
(根据行级标记规则,insert标记为默认写标记,testuser2插入的数据标记为4:3)
查看标记:
select plcol,plcol_level,plcol_scope,* from table_super;
testuser1用户对表进行读写操作:
select * from table_super; update table_super set k ='wang1' where i =1; select * from table_super;
estuser2用户对表进行读写操作:
select * from table_super; update table_super set k ='zhang1'; select * from table_super;
从上述5和6的结果澳门游戏平台注册网站可以看到testuser1只对自己插入的数据有读写权限,testuser2对两条数据都有读权限,只对自己插入的数据有写权限。分析:
表?5.3.?分析表
测试用户 | i | k | 标记(默认写) | 最大读 | 最大写 | 最小写 |
---|---|---|---|---|---|---|
testuser1 | 1 | wang | 3:5 | 3:7 | 3:5 | 2:1 |
testuser2 | 2 | zhang | 4:3 | 4:7 | 4:3 | 4:3 |
行级读规则,max_read >= row_label
行级写规则,update: max_write >= row_label >= min_write
testuser1插入的数据标记为3:5,testuser2插入的数据标记为4:3。
testuser1最大读(3:7)小于testuser2的标记(4:3),因此不能读取testuser2插入的数据。
testuser1最大写(3:5)小于testuser2的标记(4:3),因此不能写testuser2插入的数据。
testuser2最大读(4:7)大于testuser1的标记(3:5),因此可以读取testuser1插入的数据。
testuser2最大写(4:3)不满足大于等于testuser1的标记(3:5),且testuser2最小写(4:3)也不满足小于等于testuser1的标记(3:5),因此不能写testuser1插入的数据。
标记比较,等级和范围同时大于等于才为大于等于。
uxop创建策略和标记:
创建策略:
select mac_create_policy('p2','1,2,3,4','s1,s2,s3,s4');
创建主体标记:
select mac_set_user_label('uxop', 'p2', '3:s1,s2,s3', '3:s1,s3', '2:s1','1:s1','3:s1,s3');
表?5.4.?主体标记范围(列级)
测试用户 | 最大读 | 最大写 | 最小写 | 默认会话 | 默认写 |
---|---|---|---|---|---|
uxop | 3:7 | 3:5 | 2:1 | 1:1 | 3:5 |
uxop创建测试表并标记:
create table public.test_column(a int ,b int,c int); insert into test_column values(1,2,3); insert into test_column values(10,20,30); insert into test_column values(100,200,300);
列标记:
select mac_set_column_label('public','test_column','b','p2','3:s1,s2,s3');
标记列为b列,标记为3:7。
uxop分别查询未标记列a和标记列b:
select a from test_column; select b from test_column;
根据列级select: ?max_read >= column_label
主体标记最大读(3:7)等于列标记(3:7),可以访问标记列b。
uxop分别查询未标记列a和标记列和b:
update test_column set a = 1 where b=2; update test_column set b = 1 where c=3;
根据列级update: max_write >= column_label >= min_write
主体最大写标记(3:5)小于列标记(3:7),所以不能更新标记列b。
uxop分别插入未标记列c和标记列b:
insert into test_column values(1,2,3); insert into test_column(c) values(66);
根据列级insert: ?max_write >= column_label >= min_write
主体最大写标记(3:5)小于列标记(3:7),所以不能插入标记列b。
uxop分别删除数据:
delete from test_column where b=2;
根据列级delete: max_write >= column_label
主体最大写标记(3:5)小于列标记(3:7),所以不能删除标记列b。