Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1366531
  • 博文数量: 244
  • 博客积分: 3321
  • 博客等级: 中校
  • 技术积分: 2704
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-26 08:17
个人简介

微信公众号:杰夫弹弹看

文章分类

全部博文(244)

文章存档

2018年(4)

2017年(32)

2016年(25)

2015年(28)

2014年(27)

2013年(34)

2012年(25)

2011年(30)

2010年(39)

分类: 云计算

2014-07-31 14:45:08

keystone设计的policy role based access controls(RBAC)非常有意思,最终暴露给用户的是一种简单的可编辑的语义规则。
举个例子如下:
{   ... 
 "admin_required": "role:admin or is_admin:1",
 "identity:get_user": "rule:admin_required",
 ..
}

keystone的policy使用的driver默认配置是如下:
driver = keystone.policy.backends.sql.Policy


每个相应的API的访问请求都会经过相应RBAC的检测,
在keystone中的API是通过filterprotected,protected的decorator来作用的,
调用入口:
                    self.policy_api.enforce(creds,
                                        action,
                                        authorization.flatten(policy_dict))

具体的时序图以get_user为例如下:


Enforcer这个类其中的enforce方法逻辑如下:

        ....
        self.load_rules()

        # Allow the rule to be a Check tree
        if isinstance(rule, BaseCheck):
            result = rule(target, creds, self)
        elif not self.rules:
            # No rules to reference means we're going to fail closed
            result = False
        else:
            try:
                # Evaluate the rule
                result = self.rules[rule](target, creds, self)
            except KeyError:
                LOG.debug(_("Rule [%s] doesn't exist") % rule)
                # If the rule doesn't exist, fail closed
                result = False
       ...

其中各种rule的就是各种规则来实现不同角色的权限管理,
具体的rule类层次结构如下:


下次我们将对其policy语言的解析处理进行详细的分析
阅读(3291) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~