@[TOC]金仓数据库中的自主存取控制实验
自主存取控制实验
设有一个企业,包括采购、销售和客户管理等三个部门,采购部门经理David,采购员Jeffery;销售部门经理Tom,销售员Jane;客户管理部门经理Kathy,职员Mike。该企业一个信息系统覆盖采购、销售和客户管理等三个部门的业务,其数据库模式为TPC-H数据模式。针对此应用场景,使用自主存取控制机制设计一个具体的权限分配方案。
实验过程
1、 创建用户
(1)为采购、销售和客户管理等三个部门经理创建用户标识,要求具有创建用户或角色的权利。语句为:
create user david with createrole password ‘123456’;
create user tom with createrole password ‘123456’;
create user kathy with createrole password ‘123456’;
(2)为采购、销售和客户管理等三个部门的职员创建用户标识和用户口令。语句为:
create user jeffery with password ‘123456’;
create user jane with password ‘123456’;
create user mike with password ‘123456’;
2、 创建角色并分配权限
(1) 为各个部门分别创建一个查询角色,并分配相应的查询权限。
create role PurchaseQueryRole;
Grant Select on table part to PurchaseQueryRole;
Grant Select on table supplier to PurchaseQueryRole;
Grant Select on table partsupp to PurchaseQueryRole;
create role SaleQueryRole;
Grant Select on table Orders to SaleQueryRole;
Grant Select on table lineitem to SaleQueryRole;
create role CustomerQueryRole;
Grant Select on table Customer to SaleQueryRole;
Grant Select on table nation to SaleQueryRole;
Grant Select on table region to SaleQueryRole;
(2) 为各个部门分别创建一个职员角色,对本部门信息具有查看、插入权限。
create role PurchaseEmployeeRole;
Grant Select,insert on table part to PurchaseEmployeeRole;
Grant Select,insert on table supplier to PurchaseEmployeeRole;
Grant Select,insert on table partsupp to PurchaseEmployeeRole;
create role SaleEmployeeRole;
Grant Select,insert on table orders to SaleEmployeeRole;
Grant Select,insert on table lineitem to SaleEmployeeRole;
create role CustomerEmployeeRole;
Grant Select,insert on table Customer to CustomerEmployeeRole;
Grant Select,insert on table nation to CustomerEmployeeRole;
Grant Select,insert on table region to CustomerEmployeeRole;
(3) 为各部门创建一个经理角色,相应角色对本部门的信息具有完全控制权限,对其他的信息具有查询权。经理有权给本部门职员分配权限。
create role PurchaseMangerRole with createrole;
grant all on table part to PurchaseMangerRole;
grant all on table supplier to PurchaseMangerRole;
grant all on table partsupp to PurchaseMangerRole;
grant SaleQueryRole to PurchaseMangerRole;
grant CustomerQueryRole to PurchaseMangerRole;
create role SaleMangerRole with createrole;
grant all on table orders to SaleMangerRole;
grant all on table lineitem to SaleMangerRole;
grant PurchaseQueryRole to SaleMangerRole;
grant CustomerQueryRole to SaleMangerRole;
create role CustomerMangerRole with createrole;
grant all on table Customer to CustomerMangerRole;
grant all on table nation to CustomerMangerRole;
grant all on table region to CustomerMangerRole;
grant SaleQueryRole to CustomerMangerRole;
grant PurchaseQueryRole to CustomerMangerRole;
3、 给用户分配权限
(1) 给各部门经理分配权限
grant PurchaseMangerRole to david with admin option;
grant SaleMangerRole to david with admin option;
grant CustomerMangerRole to david with admin option;
(2) 给各部门职员分配权限
grant PurchaseEmployeeRole to jeffery;
grant SaleEmployeeRole to jane;
grant CustomerEmployeeRole to mike;
4、 回收角色或用户权限
(1) 收回客户经理角色的销售信息查看权限。
Revoke SaleQueryRole from CustomerMangerRole;
(2) 回收mike的客户部门职员权限
Revoke CustomerEmployeeRole from mike;
5、 验证权限分配正确性
(1) 以david用户名登录数据库,验证采购部门经理的权限
Select * from part;
Select * from orders;
(2) 回收mike的客户部门职员权限
Select * from part;
Select * from customer;
实验结果分析
通过本次实验,我学到了自主存取控制到底是什么。也了解到了with admin option、with check option、with grant option的区别和联系:
(1) with admin option:意思是被授予该权限的用户有权将某个权限(如create any table)授予其他用户或角色,取消是不级联的。如授予A系统权限create session with admin option,然后A又把create session权限授予B,但管理员收回A的create session权限时,B依然拥有create session的权限。但管理员可以显式收回B create session的权限,即直接revoke create session from B。
(2) with check option:在with check option的选项下,可以总结为
update,要保证数据update之后能被视图查询出来,也就是要符合where的条件
insert,保证insert的数据能被视图查询出来
delete,有无 with check option都一样
对于没有where字句的视图,使用with check option是多余的
(3) with grant option权限赋予/取消是级联的,如将with grant option用于对象授权时,被授予的用户也可把此对象权限授予其他用户或角色,不同的是但管理员收回用with grant option授权的用户对象权限时,权限会因传播而失效,如grant select on table with grant option to A,A用户把此权限授予B,但管理员收回A的权限时,B的权限也会失效,但管理员不可以直接收回B的SELECT ON TABLE 权限。
使用角色进行权限分配的优缺点:
(1) 优点:管理权限方便,可以根据实际情况具体地为一些角色分配相应地权利,具有良好地安全性
(2) 缺点:操作繁琐。