分享

[openstack][G版]keystone源码记录

tntzbzc 发表于 2014-11-19 22:40:18 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 0 24475
问题导读
1.在G版中密码和token两个验证方法由哪个文件来实现?
2.WSGImiddleware在keystone应用中的作用是什么?








Keystone项目的主要目的是给整个openstack的各个组件(项目)提供一个统一的验证方式。用户管理,身份验证是几乎所有的软件管理都要处理的问题,Keystone对于通常的应用场景所不同的是他要解决分布式环境下的统一认证。
       Keystone的程序结构也是采用openstack通常所用的manager,driver方式,这中方式的一个好处是driver可以被灵活的替换,通过配置的方式动态替换。Keystone 的实现方式同其他openstack项目不太一样的是,他使用了了一个python语言的特性   

  1. def__getattr__(self, name):
  2.         """Forward calls to theunderlying driver."""
  3.         # NOTE(termie): context is the firstargument, we're going to strip
  4.         #               that for now, in the futurewe'll probably do some
  5.         #               logging and whatnot in thisclass
  6.         f = getattr(self.driver, name)
  7.         @functools.wraps(f)
  8.         def _wrapper(context, *args, **kw):
  9.             return f(*args, **kw)
  10.         setattr(self, name, _wrapper)
  11.         return _wrapper
复制代码


让driver中的方法直接融入进manager类。在keystone中,验证数据的存储方式都有很多种,有sql数据库形式,kvs形式(Dict在内存中存储)等,一种driver就是对应一种存储形式。

      简单介绍一下各个模块的功能,auth实现通过插件的方式实现验证功能,Keystone/auth/plugins目录下password.py,token.py实现了密码和token两个验证方法,你也可以通过继承AuthMethodHandler类实现自己的验证方法,作为插件插入验证链中。Catalog主要实现如构造Catalog等相关功能,实现endpoints的注册,提供endpoints的发现机制。对应于每个服务(如:identity,volume,image,compute等)都会有一个对应的endpoints,如对应compute服务的endpoints为如下格式
  1. {"adminurl":"http://192.168.128.8:8774/v2/$(tenant_id)s","internalurl":"http://192.168.128.8:8774/v2/$(tenant_id)s", "publicurl":"http://192.168.128.8:8774/v2/$(tenant_id)s"}
复制代码


。policy提供了基于规则的验证引擎和验证管理接口。Token提供对于Token的生成删除等相关功能。Trust提供级联授权的相关功能,感兴趣的朋友可以看下这个文档https://github.com/openstack/identity-api/blob/master/openstack-identity-api/src/markdown/identity-api-v3-os-trust-ext.md

        实际的openstack的项目,对于keystone的应用是通过WSGImiddleware 这种可插拔的方式来实现的,具体就是通过paste 配置实现keystone验证功能的filter或app。以nova对于keystone的使用为例,nova实际是加了authtoken这个filter,authtoken的实际是在keystone的client api (python-keystoneclient-master)keystoneclient/middleware/auth_token.py文件中实现的,其中filter_factory,app_factory调用AuthProtocol类来具体实现相关功能。(注:这里对于WSGI,和paste,以及openstack对其的实现的方式不作具体讲解了)。

       Keystone V3 版本的api改动比较大,v3 api现在还没有完全实现,这里有一个v3api的文档https://github.com/openstack/identity-api/blob/master/openstack-identity-api/src/markdown/identity-api-v3.md


相关文章
Openstack源代码分析之keystone服务(keystone-all)
http://www.aboutyun.com/thread-10139-1-1.html

Openstack之keystone源代码分析1--WSGI接口流程分析
http://www.aboutyun.com/thread-10137-1-1.html

Openstack之keystone源代码分析2--Controller->Manager->Driver
http://www.aboutyun.com/thread-10138-1-1.html





没找到任何评论,期待你打破沉寂

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条