使用 Oracle Label Security
使用 Oracle Label Security
本教程的目的是使用 Oracle Label Security 基于标签策略设置安全性。
大约 30 分钟
本教程包括下列主题:
将鼠标置于此图标上以加载和查看本教程的所有屏幕截图。(警告:此操作会同时加载所有屏幕截图,网速较慢时,响应时间可能会比较长。)
注:此外,您还可以在下列步骤中将鼠标放在每个单独的图标上,从而仅加载和查看与该步骤相关的屏幕截图。
Oracle Label Security 简化了职责的划分:当 LBACSYS(OLS 的默认 Oracle-DBA)创建策略时,将自动授予 LBACSYS 名称为“<策略名>_DBA”的角色,带“ADMIN”选项,这样便可以将该角色授予其他用户以完成并“拥有”该策略。在本教程中,用户称作“sec_admin”和“HR_sec”。
访问控制策略包含三个部分:
| 1. |
包含敏感数据 (LOCATIONS) 和该数据的所有者 (hr) 的表,数据所有者将确定其数据的敏感性,以及各级敏感数据的相应访问用户。
|
| 2. |
OLS 策略的用户相关部分由 HR_sec 用户维护,该用户创建数据库用户和角色并向他们授予许可。 |
| 3. |
Oracle Label Security 标签(用于数据和用户,支持由数据所有者定义的访问策略)由 sec_admin 创建。此外,此用户还负责维护应用程序的性能。 |
当策略已经过测试并准备付诸实际应用时,LBACSYS 将撤消“HR_sec”和“sec_admin”的所有必需的执行权限和角色。
返回主题列表
在本教程中,您将创建一组用户和角色来演示 OLS 如何工作。要创建用户和角色,请执行以下步骤:
| 1. |
打开一个终端窗口,执行以下命令:
cd /home/oracle/wkdir
sqlplus /nolog
@ols_create_admin_users_and_roles
set echo off prompt *** Create admin users: sec_admin and hr_sec prompt connect system/oracle grant connect, create any index to sec_admin identified by welcome1; grant connect, create user, drop user, create role, drop any role to hr_sec identified by welcome1;
prompt prompt ***** Create roles: emp_role connect hr_sec/welcome1; create role emp_role;
prompt ***** Grant system and object privileges to roles and users connect system/oracle; grant connect to emp_role;
connect hr/hr; grant select on hr.locations to emp_role;
connect hr_sec/welcome1;
prompt ***** Create Steven King (President) create user SKING identified by welcome1; grant emp_role to SKING;
prompt ***** Create Karen Partners (Sales Manager rep. to SKing) create user KPARTNER identified by welcome1; grant emp_role to KPARTNER;
prompt ***** Create Louise Doran (Sales Rep in Karen Partners team) create user LDORAN identified by welcome1; grant emp_role to LDORAN;

|
返回主题列表
在本部分中,您将创建策略,将角色授予管理用户并为策略创建级别和标签。执行以下操作:
| 1. |
LBACSYS 创建一个将控制 hr.LOCATIONS 表的访问权限的策略;该策略名为“ACCESS_LOCATIONS”;隐藏列(将附加到 hr.LOCATIONS 表以保存数据标签)的名称为“OLS_COLUMN”。在 SQL*Plus 会话中,执行以下脚本以创建策略。
@ols_create_policy
connect lbacsys/lbacsys BEGIN SA_SYSDBA.CREATE_POLICY ( policy_name => 'ACCESS_LOCATIONS', column_name => 'OLS_COLUMN', default_options => 'READ_CONTROL,LABEL_DEFAULT,HIDE'); END; /

|
| 2. |
创建策略后,将自动授予 LBACSYS 该策略的管理角色,带“admin”选项。为实现正确的职责划分,LBACSYS 将此角色以及某些其他执行权限授予管理用户“HR_sec”和“sec_admin”。从 SQL*Plus 会话中,执行以下脚本:
@ols_grant_role
Prompt grant ACCESS_LOCATIONS_DBA to sec_admin and HR_sec: grant ACCESS_LOCATIONS_DBA to sec_admin; grant ACCESS_LOCATIONS_DBA to HR_sec;
Prompt grant execute on SA_COMPONENTS to sec_admin: grant execute on SA_COMPONENTS to sec_admin;
Prompt grant execute on SA_USER_ADMIN to HR_sec: grant execute on SA_USER_ADMIN to HR_sec;

|
| 3. |
sec_admin 用户为策略创建级别。每个策略由级别(一个或多个)以及可选的区和组(未包含在本示例中)组成。执行以下脚本,为策略创建级别。
@ols_create_level
connect sec_admin/welcome1; BEGIN SA_COMPONENTS.CREATE_LEVEL ( policy_name => 'ACCESS_LOCATIONS', level_num => 1000, short_name => 'PUB', long_name => 'PUBLIC'); END; / execute SA_COMPONENTS.CREATE_LEVEL ('ACCESS_LOCATIONS',2000,'CONF','CONFIDENTIAL'); execute SA_COMPONENTS.CREATE_LEVEL ('ACCESS_LOCATIONS',3000,'SENS','SENSITIVE');

|
| 4. |
sec_admin 用户还创建标签(只包含级别,不包含区或组)。执行以下脚本:
@ols_create_label
connect sec_admin/welcome1;
execute SA_LABEL_ADMIN.CREATE_LABEL('ACCESS_LOCATIONS',1000,'PUB');
Prompt execute SA_LABEL_ADMIN.CREATE_LABEL('ACCESS_LOCATIONS',2000,'CONF')
execute SA_LABEL_ADMIN.CREATE_LABEL('ACCESS_LOCATIONS',2000,'CONF');
Prompt execute SA_LABEL_ADMIN.CREATE_LABEL('ACCESS_LOCATIONS',3000,'SENS')
execute SA_LABEL_ADMIN.CREATE_LABEL('ACCESS_LOCATIONS',3000,'SENS');

|
返回主题列表
稍后,将通过把前面创建的标签应用于数据来限制数据访问权限。在此之前,需要对用户进行授权并授予策略权限,以便定义与这些用户匹配的访问权限。执行以下操作:
| 1. |
HR_sec 用户将标签绑定到用户,并定义他们的许可。从 SQL*Plus 会话中,执行以下脚本来创建用户标签授权:
@ols_set_user_label
connect hr_sec/welcome1; BEGIN SA_USER_ADMIN.SET_USER_LABELS ( policy_name => 'ACCESS_LOCATIONS', user_name => 'SKING', max_read_label => 'SENS', max_write_label => 'SENS', min_write_label => 'CONF', def_label => 'SENS', row_label => 'SENS'); END; / Prompt Karin Partners is allowed to read public and confidential data Prompt from hr.LOCATIONS. execute SA_USER_ADMIN.SET_USER_LABELS
('ACCESS_LOCATIONS','KPARTNER','CONF','CONF','PUB','CONF','CONF'); Prompt Louise Doran is allowed to read public data from hr.LOCATIONS. execute SA_USER_ADMIN.SET_USER_LABELS
('ACCESS_LOCATIONS', 'LDORAN', 'PUB','PUB','PUB','PUB','PUB');

|
| 2. |
由于用户以后将向前面定义的隐藏 OLS_COLUMN 中添加数据标签,因此 LOCATIONS 表的所有者 HR 需要该表的“FULL”访问权限。从 SQL*Plus 会话中,执行以下脚本:
@ols_set_user_privs
connect hr_sec/welcome1; execute SA_USER_ADMIN.SET_USER_PRIVS ('ACCESS_LOCATIONS','HR','FULL');

|
返回主题列表
可以将 Oracle Label Security 策略应用于整个应用程序模式或应用于单个应用程序表。您将把它应用于 LOCATIONS 表。执行以下操作:
| 1. |
sec_admin 用户将该策略应用于表。从现在起,由于已经在策略定义中设置了 READ_CONTROL 并且未向行中添加标签,因此任何人都无法读取数据(HR 除外)。执行以下脚本:
@ols_apply_policy
connect sec_admin/welcome1; execute SA_POLICY_ADMIN.APPLY_TABLE_POLICY
('ACCESS_LOCATIONS', 'HR', 'locations');
|
返回主题列表
在测试策略前,必须通过执行以下操作为数据添加标签:
| 1. |
LOCATIONS 表的所有者 HR 将每一行的标签添加到隐藏列“OLS_COLUMNS”中。在本示例中,您将把 Sensitive 标签分配给以下城市:Beijing、Tokyo 和 Singapore。您将把 Confidential 标签分配给以下城市:Munich、Oxford 和 Roma。您将把 Public 标签分配给所有其他城市。
@ols_add_label_column
connect hr/hr;
update locations
set OLS_COLUMN = char_to_label('ACCESS_LOCATIONS','SENS')
where upper(city) in ('BEIJING', 'TOKYO', 'SINGAPORE');
update locations
set OLS_COLUMN = char_to_label('ACCESS_LOCATIONS','CONF')
where upper(city) in ('MUNICH', 'OXFORD', 'ROMA');
update locations
set OLS_COLUMN = char_to_label('ACCESS_LOCATIONS','PUB')
where OLS_COLUMN is NULL;

|
返回主题列表
要提高数据访问的性能,可以为 OLS_COLUMN 创建 BITMAP INDEX。执行以下步骤:
| 1. |
为提高性能,sec_admin 为 OLS_COLUMN 创建一个 BITMAP INDEX:
@ols_create_index
connect sec_admin/welcome1; create bitmap index hr.LOCATIONS_idx on hr.LOCATIONS (OLS_COLUMN);
|
返回主题列表
为限制所有用户对特定范围的 IP 地址的访问,SEC_ADMIN 使用 Oracle 策略管理器向策略中添加了一个 WHERE 子句。执行以下步骤:
| 1. |
在 DOS 提示窗口中输入下列命令:
oemapp opm
|
| 2. |
以 SEC_ADMIN 用户身份登录。
|
| 3. |
导航到受保护的表并选择 Predicate 选项卡。
|
| 4. |
选中下面的复选框以使文本域可编辑并输入下列文本,然后单击 Apply。
sys_context ('userenv','ip_address') between '130.35.44.0' and '130.35.44.255'

|
| 5. |
选择 File > Exit。
|
返回主题列表
要保护策略,您需要撤消 sec_admin 和 HR_sec 的特定于策略的执行权限和角色。执行以下步骤:
| 1. |
从 SQL*Plus 会话中,执行以下脚本:
@ols_revoke_access
connect lbacsys/lbacsys; Prompt revoke ACCESS_LOCATIONS_DBA from sec_admin and HR_sec: revoke ACCESS_LOCATIONS_DBA from sec_admin; revoke ACCESS_LOCATIONS_DBA from HR_sec; Prompt revoke execute on SA_COMPONENTS from sec_admin: revoke execute on SA_COMPONENTS from sec_admin; Prompt revoke execute on SA_USER_ADMIN from HR_sec: revoke execute on SA_USER_ADMIN from HR_sec;
|
返回主题列表
建立应用于表和用户的策略并为数据添加标签后,现在就可以通过执行以下操作对它们进行测试:
| 1. |
执行以下脚本,测试 SKING 用户的访问权限。
@ols_test_policy_sking
connect SKING/welcome1; col city heading City format a25 col country_id heading Country format a11 col Label format a10 select city, country_id, label_to_char (OLS_COLUMN)
as Label from hr.locations order by ols_column;
注意,用户 SKING 可以查看 PUBLIC、CONFIDENTIAL 和 SENSITIVE 数据。

|
| 2. |
现在,您可以通过执行以下脚本测试 KPARTNER 用户的策略:
@ols_test_policy_kpartner
connect kpartner/welcome1;
col city heading City format a25
col country_id heading Country format a11
col Label format a10
select city, country_id, label_to_char (OLS_COLUMN)
as Label from hr.locations order by ols_column;
注意,KPARTNER 可以查看 PUBLIC 和 CONFIDENTIAL 数据。

|
| 3. |
现在,可以通过执行以下脚本测试 PRIVACY 策略:
@ols_test_policy_ldoran
connect ldoran/welcome1;
col city heading City format a25
col country_id heading Country format a11
col Label format a10
select city, country_id, label_to_char (OLS_COLUMN)
as Label from hr.locations order by ols_column;
注意,LDORAN 只能查看 PUBLIC 数据。

|
返回主题列表
现在,您已经测试了策略,接下来您可以通过执行以下操作删除用户和策略:
| 1. |
执行以下脚本:
@ols_cleanup
Prompt ==================================================================== prompt Clean up: prompt ==================================================================== Prompt connect LBACSYS conn lbacsys/lbacsys; prompt ==================================================================== prompt Drop policy (and remove label column) in case it already exists. prompt (Ignore the error message when it does not exist). prompt ==================================================================== execute sa_sysdba.drop_policy ('ACCESS_LOCATIONS', true); Prompt connect HR_sec conn HR_sec/welcome1; prompt ==================================================================== prompt HR_sec drops database users and roles (Ignore the error messages prompt should they not exist): prompt ==================================================================== drop user SKING cascade; drop user KPARTNER cascade; drop user LDORAN cascade; drop role emp_role; Prompt connect SYSTEM conn system/oracle; prompt ==================================================================== prompt SYSTEM drops admin users (Ignore the error messages should prompt they not exist): prompt ==================================================================== drop user sec_admin cascade; drop user HR_sec cascade;
|
返回主题列表
在本教程中,您学习了如何:
 |
创建策略 |
 |
设置用户授权 |
 |
将策略应用于表 |
 |
为数据添加标签 |
 |
测试策略 |
返回主题列表
|