本篇文章是有关sybase安全相关的管理中不容易明白的地方——角色分层和互斥,了解了下面的实验并实现之,你就过关了。
本节中,你将通过三个实验来理解互斥、分层的概念以及相关命令的使用。实验环境要求你拥有系统管理员和安全管理员的角色,有权访问数据库,有用户和权限管理的基础知识。
步骤:
【实验一】角色互斥(用户级)
1、创建角色
create role intern_role
create role doctor_role with passwd "physician"
create role specialist_role
2、增加角色的互斥
alter role intern_role add exclusive membership specialist_role
3、了解登录用户信息
select * from syslogins
4、增加新的登录
sp_addlogin lg1,"okokok"
5、为新的帐户授予intern_role角色和specialist_role角色
sp_role "grant","intern_role","lg1"
sp_role "grant","specialist_role","lg1"
提示信息:
server message: number 11151, severity 16
procedure ''sp_role'', line 36:
cannot grant the role ''specialist_role'' because it is mutually exclusive with role ''intern_role'' which is possessed by grantee ''lg1''. remove the exclusivity and try again.
(1 row affected)
(return status = 1)
【实验二】定义sso_role和sa_role在活动级互斥
1、使角色sso_role和sa_role角色在活动级互斥
alter role sso_role add exclusive activation sa_role
显示提示信息:
server message: number 11126, severity 16
line 1:
cannot add the ''activation'' exclusivity between role ''sso_role'' and role ''sa_role'' because it already exists for this server.
2、为将角色分离创建两个登录用户
sp_addlogin aca_sa,"okokok"
sp_addlogin aca_sso,"okokok"
3、分别为其授予系统员和安全员的角色
sp_role "grant","sa_role","aca_sa"
sp_role "grant","sso_role","aca_sso"
4、锁定超级帐户sa
sp_locklogin "sa","lock"(自己不能锁自己)
以aca_sso"从新登录后再锁定sa用户
sp_locklogin "sa","lock"
5、 增加登录用户lg2用于测试
sp_addlogin "lg2","okokok"
sp_role "grant","sa_role","lg2"(需要sa_role角色的用户)
sp_role "grant","sso_role","lg2"(需要sso_role角色的用户)
6、 查看lg2用户的信息
sp_displaylogin lg2
以lg2登录,查看当前用户激活的角色
select show_role() //任何用户可以使用该命令查看当前登录用户激活的系统角色
执行结果:
sa_role
或使用sp_activeroles命令,任何用户要查看当前登录到adaptive server时所激活的所有角色信息可使用该命令
sp_activeroles
执行结果:
role name
---------
sa_role
7、使用set role命令准备激活sso_role
set role sso_role on
显示提示信息:
server message: number 11150, severity 16
line 1:
operation failed. role ''sso_role'' is mutually exclusive at membership or activation level with role ''sa_role''. remove the exclusivity and try again.
8、若要激活另一活动排斥的角色需先关闭当前角色,然后再将新角色激活。
set role sso_role off
set role sa_role on
【实验三】角色分层
1、创建一个登录用户
sp_addlogin "lg3","okokok"
2、创建角色
create role author_role
create role commtentator_role
create role editor_role
create role chief_editor_role
3、角色分层(当给一个角色授予另一个角色后,即产生角色分层)
grant role author_role to editor_role
grant role commtentator_role to editor_role
grant role editor_role to chief_editor_role
注意:不能把一个角色授予另一个已经直接包含该角色的角色
grant role author_role to editor_role
显示提示信息:
server message: number 11107, severity 10
line 1:
all the roles specified to be granted in the grant role statement have already been granted to grantee ''editor_role''.
注意:可以给一个角色授予另一个已间接包含该角色的角色
grant role author_role to chief_editor_role
注意:不能给一个角色授予一个包含该角色的角色
grant role chief_editor_role to commtentator_role
执行结果:
server message: number 11104, severity 16
line 1:
cannot grant the role ''chief_editor_role'' to role ''commtentator_role'' because it will result in cycle.
4、查看角色分层
select role_contain("commtentator_role","chief_editor_role")
返回值为1
5、授予用户lg3的chief_editor_role角色
grant role chief_editor_role to lg3
6、显示登录用户被授予的角色
sp_displayroles lg3
7、显示角色chief_editor_role包含的所有角色
sp_displayroles chief_editor_role
显示结果为:
role name
---------
author_role
editor_role
7、 查看登录用户lg3被激活的角色及在分层中子级别中的角色
sp_displayroles lg3,expand_down
显示结果:
role name parent role name level
--------- ---------------- -----------
chief_editor_role null 1
author_role chief_editor_role 2
editor_role chief_editor_role 2
author_role editor_role 3
commtentator_role editor_role 3
结论:通过以上实验我们知道,给角色之间增加了分层和互斥功能,使用户授权更加的安全和灵活。
没有评论:
发表评论