openstack云计算keystone架构源码分析

keystone架构

Keystone API

Keystone API与Openstack其他服务的API类似,也是基于ReSTFul HTTP实现的。

Keystone API划分为Admin API和Public API:

  • Public API不仅实现获取版本以及相应扩展信息的操作,同时包括获取Token以及Token租户信息的操作;
  • Admin API主要提供服务开发者使用,不仅可以完成Public API的操作,同时对User、Tenant、Role和Service Endpoint进行管理操作。

Router

Keystone Router主要实现上层API和底层服务的映射和转换功能,包括四种Router类型。

(1) AdminRouter负责将Admin API请求映射为相应的行为操作并转发至底层相应的服务执行;

(2) PublicRouter与AdminRouter类似;

(3) PublicVersionRouter对系统版本的请求API进行映射操作;

(4) AdminVersionRouter与PublicVersionRouter类似。

Services

Keystone Service接收上层不同Router发来的操作请求,并根据不同后端驱动完成相应操作,主要包括四种类型;

(1) Identity Service

Identity Service提供关于用户和用户组的授权认证及相关数据。

Keystone-10.0.0支持ldap.core.Identity,Sql.Identity两种后端驱动,系统默认的是Sql.Identity;

Users:

用户这一概念在openstack中实际上是用来标识一个使用者(an individual API consumer)

一个用户必须被一个具体的domain拥有

所有的用户名不是全局唯一的,在同一个domain中用户名才唯一

Groups:

用户组是一个包含了一系列用户的容器,一个group必须被一个具体的domain拥有

所有的组名不是全局唯一的,在同一domain种组名才唯一

(2) Resource Service

Resouse服务提供关于projects和domains的数据

projects

Projects(在v2.0中称之为Tenants)在openstack中project代表资源的结合

一个project必须被一个具体的domain所拥有

所有的project都不是全局唯一的,仅仅在一个domain中project唯一

新建一个project没有指定domain,它将被添加到默认的domain中即default

Domains

Domains是一个更高级别的包含n个projects-users-groups的容器。
默认的Domains名为Default

在v3版本中的唯一性概念

Domain名,在所有的domains中全局唯一

Role名.在所有的domains中全局唯一

User名,仅仅在它自己所在的domain中唯一

Project名,仅仅在它自己所在的domain中唯一

Group名,仅仅在它自己所在的domain中唯一

基于这些容器结构,domains代表了openstack资源的管理方式,只要某一assignment(project-user-role)被授予权限,一个domain中的用户就可以访问另外一个domain中的资源。

(3) Assignment Service

Assignment Service提供role及role assignments的数据

Roles

role角色标识了一个用户可以获得的权限级别

可以在domain或project级别授予role。

可以分配给单个用户或组级别role。

role名称是全局唯一的。

Role Assignments

A 3-tuple that has a Role, a Resource and an Identity.

Resource指的是project

Identity指的是user

Role指的是role即project-user-role

(4) Token Service

Token Service提供认证和管理令牌token的功能,用户的credentials认证通过后就得到token

Keystone-10.0.0对于Token Service支持Kvs.Token,Memcache.Token,

Memcache_pool.Token,Sql.Token四种后端驱动,系统默认的是kvs.Token

(5) Catalog Service

Catalog Service提供service和Endpoint相关的管理操作(service即openstack所有服务,endpont即访问每个服务的url)

keystone-10.0.0对Catalog Service支持两种后端驱动:Sql.Catalog、Templated.Catalog两种后端驱动,系统默认的是templated.Catalog;

(6) Policy ServicePolicy Service

提供一个基于规则的授权驱动和规则管理

keystone-10.0.0对Policy Service支持两种后端驱动:rules.Policy,sql.Policy,默认使用sql.Policy

Backend Driver

Backend Driver具有多种类型,不同的Service选择不同的Backend Driver。

官方https://docs.openstack.org/keystone/latest/#groups

keystone管理这些概念的方法

组件名称管理对象生成方法保存方式配置项
identityuser,以及 user group-sql, ldap.core

[identity]

driver = keystone.identity.backends.[sql|ldap.core].Identity

token用户的临时 tokenpki,pkiz,uuidsql, kvs,memcached

[token]

driver = keystone.token.persistence.backends.[sql|kvs|memcache|memcache_pool].Token

provider=keystone.token.providers.[pkiz|pki|uuid].Provider
credentialEC2 credential sql

[credential]

driver = keystone.credential.backends.sql.Credential

provider=keystone.token.providers.[core|fernet].Provider

catalogregion,service,endpoint sql|templated

[catalog]

driver = keystone.catalog.backends.[sql|templated].Catalog

assignmenttenant,domain,role 以及它们与 user 之间的关系external, password, tokensql

[assignment]

methods = external, password, token

password = keystone.auth.plugins.password.Password

trusttrustsql 

[trust]

driver = keystone.trust.backends.[sql].Trust

policyKeystone service 的用户鉴权策略 ruels|sql

[default]

policy_file = policy.json

[policy]

driver = keystone.policy.backends.[ruels|sql].Policy

keystone-10.0.0代码结构展示

keystone-manage 是个 CLI 工具,它通过和 Keystone service 交互来做一些无法使用 Keystone REST API 来进行的操作,包括:

db_sync: Sync the database.

db_version: Print the current migration version of the database.

mapping_purge: Purge the identity mapping table.

pki_setup: Initialize the certificates used to sign tokens.

saml_idp_metadata: Generate identity provider metadata.

ssl_setup: Generate certificates for SSL.

token_flush: Purge expired tokens.

每个Keystone 组件,比如 catalog, token 等都有一个单独的目录。
每个组件目录中:

routes.py 定义了该组件的 routes (routes 见 探索 OpenStack 之(11):cinder-api Service 启动过程分析 以及 WSGI / Paste deploy / Router 等介绍)。

其中identity 和 assignment 分别定义了 admin 和 public 使用的 routes,分别供 admin service 和 public service 使用。

controller.py 文件定义了该组件所管理的对象,比如 assignment 的controller.py 文件定义了 Tenant、Role、Project 等类。

core.py 定了了两个类 Manager 和 Driver。Manager 类对外提供该组件操作具体对象的方法入口;

Driver 类定义了该组件需要其Driver实现类所提供的接口。
backend 目录下的每个文件是每个具体driver 的实现

下载keystone-10.0.0演示https://www.openstack.org/

keystone服务启动

Keystone is an HTTP front-end to several services. Like other OpenStack applications, this is done using python WSGI interfaces and applications are configured together usingPaste. The application’s HTTP endpoints are made up of pipelines of WSGI middleware。。。

详见:https://docs.openstack.org/keystone/latest/

/usr/bin/keystone-all 会启动 keystone 的两个service:admin and main,它们分别对应 /etc/keystone/keystone-paste.ini文件中的两个composite:

可见 admin service 提供给administrator 使用;main 提供给 public 使用。

它们分别都有 V2.0 和 V3 版本,只是目前的 keystone Cli 只支持 V2.0.比较下 admin 和 public:

名称middlewaresfactory功能区别
admin比 public 多s3_extensionkeystone.service:public_app_factory

从 factory 函数来看, admin service 比 public service 多了identity 管理功能, 以及 assignment 的admin/public 区别:

1. admin 多了对 GET/users/{user_id} 的支持,多了get_all_projects,get_project,get_user_roles 等功能

2. keystone 对 admin service 提供 admin extensions, 比如OS-KSADM等;对 public service 提供 public extensions。

简单总结一下, public service 主要提供了身份验证和目录服务功能;admin service 增加了 tenant、user、role、user group 的管理功能。

public

sizelimit url_normalize build_auth_context token_auth admin_token_auth xml_body_v2

json_body ec2_extension user_crud_extension

keystone.service:admin_app_factory

/usr/bin/keystone-all 会启动 admin 和 public 两个 service,分别绑定不同 host 和 端口。

默认的话,绑定host 都是 0.0.0.0;

admin 的绑定端口是 35357 (admin_port), public 的绑定端口是 5000 (public_port)。

因此,给 admin 使用的OS_AUTH_URL 为 http://controller:35357/v2.0,

给 public 使用的OS_AUTH_URL=http://controller:5000/v2.0

keystone详细说明

WSGI server的父进程(50511号进程)开启两个socket去分别监听本环境的5000和35357号端口,
其中5000号端口是为main的WSGI server提供的,35357号端口为admin的WSGI server提供的。

即WSGI server的父进程接收到5000号端口的HTTP请求时,则将把该请求转发给为main开启的WSGI server去处理,

而WSGI server的父进程接收到35357号端口的HTTP请求时,则将把该请求转发给为admin开启的WSGI server去处理。

vim /etc/keystone/keystone-paste.ini

日志

2016-09-14 11:53:01.037 12698 INFO keystone.common.wsgi [req-07b28d5b-084c-467e-b45a-a4c8a52b7e96
9ff041112e454cca9b54bf117a80ca29 15426931fe4746d08736c5e5c1da6b1c 
- 6e495643fb014e5e8a3992c69d80d234 6e495643fb014e5e8a3992c69d80d234] 
GET http://controller02:35357/v3/auth/tokens

(1) type = composite

这个类型的section会把URL请求分发到对应的Application,use表明具体的分发方式,比如”egg:Paste#urlmap”表示使用Paste包中的urlmap模块,这个section里的其他形式如”key = value”的行是使用urlmap进行分发时的参数。

(2) type = app

一个app就是一个具体的WSGI Application。

(3) type = filter-app

接收一个请求后,会首先调用filter-app中的use所指定的app进行过滤,如果这个请求没有被过滤,就会转发到next所指定的app进行下一步的处理。

(4) type = filter

与filter-app类型的区别只是没有next。

(5) type = pipeline

pipeline由一系列filter组成。

这个filter链条的末尾是一个app。pipeline类型主要是对filter-app进行了简化,否则,如果多个filter,就需要多个filter-app,然后使用next进行连接。OpenStack的paste的deploy的配置文件

主要采用的pipeline的方式。

因为url为http://192.168.118.1:5000/v2.0/tokens,因为基本url的后面接的信息为/v2.0,所以将到public_api的section作相应操作。

作者:Jeff的技术栈原文地址:https://www.cnblogs.com/xiaoyuanqujing/articles/11838827.html

%s 个评论

要回复文章请先登录注册