您好,欢迎访问一九零五行业门户网

【Oracle Database 12c New Feature】Advanced Security

1. 什么是oracle data redaction 不确认正式的中文翻译是什么,我翻译为数据改写。这是一项在12c中出现的oracle高级安全新组件,其作用是限制sql语句的返回结果样式,对于特定的用户可以限制某些字段显示被自动改写过的值。这是一项非常有用的安全功能,而在
1. 什么是oracle data redaction
不确认正式的中文翻译是什么,我翻译为数据改写。这是一项在12c中出现的oracle高级安全新组件,其作用是限制sql语句的返回结果样式,对于特定的用户可以限制某些字段显示被自动改写过的值。这是一项非常有用的安全功能,而在12c之前如果要实现相同的功能,可能需要创建特定的视图,或者在存储到数据库的时候就用加密算法进行加密。而12c的数据改写功能则在最后数据返回到客户端的前一刻将数据改写,这并不会影响到数据真实的存储。看一个简单的例子就明白了。
原本存储的数据记录如下:
sql> select * from employees;?employee_id first_name last_name social_secu salary----------- -------------------- ------------------------- ----------- ---------- 100 steven king 247-85-9056 7000 101 neena kochhar 334-08-6578 5000
在设置完data redaction之后,再次执行相同的语句,可以看到有隐私性质的列-社会保障号被遮盖了,只显示最后4位,这就实现了安全的目的。
sql> select * from kamus.employees;?employee_id first_name last_name social_secu salary----------- -------------------- ------------------------- ----------- ---------- 100 steven king ***-**-9056 7000 101 neena kochhar ***-**-6578 5000
2. 如何设置oracle data redaction
设置用户的合适权限,由于oracle redaction对于dba用户不起效果,因此需要将dba角色收回。
revoke dba from kamus;grant connect, resource, unlimited tablespace to kamus;grant select on sys.redaction_policies to kamus;grant select on sys.redaction_columns to kamus;grant execute on dbms_redact to kamus;
创建测试环境,包括测试表和测试数据。
create table employees (employee_id number(6,0), first_name varchar2(20), last_name varchar2(25), social_security varchar2(11), salary number(4,0))/?insert into employees (employee_id,first_name,last_name,social_security,salary) values (100,'steven','king','247-85-9056',7000);insert into employees (employee_id,first_name,last_name,social_security,salary) values (101,'neena','kochhar','334-08-6578',5000);commit;?sql> select * from employees;?employee_id first_name last_name social_secu salary----------- -------------------- ------------------------- ----------- ---------- 100 steven king 247-85-9056 7000 101 neena kochhar 334-08-6578 5000
oracle redaction针对单张表的某个字段进行设置,分别通过add_policy存储过程的object_name和column_name来控制;redaction有多种类型,第一种为full,也就是完全改写,对于字符类型的字段将改写为一个空格,对于数字类型的字段改写为0,对于日期类型的字段改写为2001-01-01,类型通过function_type参数来控制。
begindbms_redact.add_policy ( object_schema => 'kamus', object_name => 'employees', policy_name => 'redact_emp', column_name => 'social_security', function_type => dbms_redact.full, expression => '1=1', enable => true );end;/?sql> select * from employees;?employee_id first_name last_name social_secu salary----------- -------------------- ------------------------- ----------- ---------- 100 steven king 7000 101 neena kochhar 5000
redaction的第二种类型是random,对于字符类型的字段将改写为随机字符,对于数字类型的字段改写为具有相同长度的随机数字,对于日期类型的字段改写为随机日期(永远不会跟真实日期相同)。
begindbms_redact.alter_policy ( object_schema => 'kamus', object_name => 'employees', policy_name => 'redact_emp', column_name => 'social_security', action => dbms_redact.modify_column, function_type => dbms_redact.random);end;/?sql> select * from kamus.employees;?employee_id first_name last_name social_secu salary----------- -------------------- ------------------------- ----------- ---------- 100 steven king wa};w~zc i& 7000 101 neena kochhar q9n]##t/yav 5000
redaction的第三种类型是partial,将改写为按照function_parameters参数指定的格式。
begindbms_redact.alter_policy ( object_schema => 'kamus', object_name => 'employees', policy_name => 'redact_emp', column_name => 'social_security', action => dbms_redact.modify_column, function_type => dbms_redact.partial, function_parameters => 'vvvfvvfvvvv,vvv-vv-vvvv,*,1,5');end;/?sql> select * from kamus.employees;?employee_id first_name last_name social_secu salary----------- -------------------- ------------------------- ----------- ---------- 100 steven king ***-**-9056 7000 101 neena kochhar ***-**-6578 5000
3. 如何精细化设置哪些用户才启用数据改写
通过expression参数设置,比如如下所示,所有不是kamus的用户都启用在employees.social_security字段上的数据改写,而如果是kamus用户进行检索,则还是返回真实的数据。
begindbms_redact.alter_policy ( object_schema => 'kamus', object_name => 'employees', policy_name => 'redact_emp', column_name => 'social_security', action => dbms_redact.modify_expression, expression => 'sys_context ( ''userenv'',''session_user'' ) !=''kamus''');end;/
expression参数非常灵活,通过此参数可以使data redaction发挥巨大的作用。expression参数可选值如下图所示。
4. 如何增加数据改写策略
通过dbms_redact.alter_policy存储过程可以增加多个字段的数据改写策略,比如下例,增加在salary字段上的全数据改写。
begindbms_redact.alter_policy ( object_schema => 'kamus', object_name => 'employees', policy_name => 'redact_emp', column_name => 'salary', action => dbms_redact.add_column, function_type => dbms_redact.full, expression => 'sys_context ( ''userenv'',''session_user'' ) !=''kamus''');end;/?sql> select * from kamus.employees;?employee_id first_name last_name social_secu salary----------- -------------------- ------------------------- ----------- ---------- 100 steven king ***-**-9056 0 101 neena kochhar ***-**-6578 0
5. 数据改写到底是发生在哪一阶段,有哪些限制
--where条件中的字段并不会受数据改写影响,可以看到即使最后都是显示salary=0,但是where条件还是正常执行并筛选出正确结果的。sql> select * from kamus.employees where salary>5000;?employee_id first_name last_name social_secu salary----------- -------------------- ------------------------- ----------- ---------- 100 steven king ***-**-9056 0?sql> select * from kamus.employees where salary select * from kamus.employees where salary=5000;?employee_id first_name last_name social_secu salary----------- -------------------- ------------------------- ----------- ---------- 101 neena kochhar ***-**-6578 0?--在启用了数据改写策略的表上无法进行全表的ctas操作。sql> create table t as select * from kamus.employees;create table t as select * from kamus.employees *error at line 1:ora-28081: insufficient privileges - the command references a redacted object.?--如果ctas操作中的字段上没有启用数据改写策略,ctas可以正常进行。sql> create table t as select employee_id,first_name from kamus.employees;?table created.?sql> drop table t;?table dropped.?--如果包含了启用数据改写策略的列,则会报ora-28081错误。sql> create table t as select employee_id,first_name,salary from kamus.employees;create table t as select employee_id,first_name,salary from kamus.employees *error at line 1:ora-28081: insufficient privileges - the command references a redacted object.
share/save
related posts:
oracle 11g new feature – partitionoracle 11g new feature – virtual columnoracle database instance startup fails with error ora-27302 ora-27301
其它类似信息

推荐信息