keystone系列五:keystone源碼分析


六 keystone架構

 

6.1 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進行管理操作。

6.2 Router
Keystone Router主要實現上層API和底層服務的映射和轉換功能,包括四種Router類型。 
(1) AdminRouter 
  負責將Admin API請求映射為相應的行為操作並轉發至底層相應的服務執行; 
(2) PublicRouter 
  與AdminRouter類似; 
(3) PublicVersionRouter 
  對系統版本的請求API進行映射操作; 
(4) AdminVersionRouter 
  與PublicVersionRouter類似。 
6.3 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種組名才唯一
users和groups

 

 (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
projects和domains

 

Domain名,在所有的domains中全局唯一
Role名.在所有的domains中全局唯一
User名,僅僅在它自己所在的domain中唯一
Project名,僅僅在它自己所在的domain中唯一
Group名,僅僅在它自己所在的domain中唯一



基於這些容器結構,domains代表了openstack資源的管理方式,只要某一assignment(project-user-role)被授予權限,一個domain中的用戶就可以訪問另外一個domain中的資源。
在v3版本中的唯一性概念

 

(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
roles和role assignments

 

(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 Service 
Policy Service提供一個基於規則的授權驅動和規則管理

keystone-10.0.0對Policy Service支持兩種后端驅動:rules.Policy,sql.Policy,默認使用sql.Policy
6.4 Backend Driver

Backend Driver具有多種類型,不同的Service選擇不同的Backend Driver。

官方http://docs.openstack.org/developer/keystone/architecture.html#groups

七 keystone管理這些概念的方法

組件名稱 管理對象 生成方法 保存方式 配置項
identity user,以及 user group - sql, ldap.core

[identity]

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

token 用戶的臨時 token pki,pkiz,uuid sql, kvs,memcached

[token]

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

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

[credential]

driver = keystone.credential.backends.sql.Credential

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

catalog region,service,endpoint   sql|templated

[catalog]

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

assignment tenant,domain,role 以及它們與 user 之間的關系 external, password, token sql

[assignment]

methods = external, password, token

password = keystone.auth.plugins.password.Password

trust trust  sql  

[trust]

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

policy Keystone 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演示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 using Paste. The application’s HTTP endpoints are made up of pipelines of WSGI middleware。。。

詳見:http://docs.openstack.org/developer/keystone/architecture.html

 

/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:

名稱 middlewares factory 功能區別
admin 比 public 多 s3_extension keystone.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作相應操作。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM