6.3.1. 概要
光环云认证服务提供认证、授权、用户管理和服务发现等服务,基于OpenStack Keystone V3 API。
6.3.2. 核心概念
6.3.2.1. 用户账号(User)
用户账号有邮箱、用户名和密码,用于登陆光环云 Cloud的Web管理面板。
6.3.2.2. 项目(Project)
每个用户拥有一个项目,并且作为这个项目的拥有者(Owner),同时可以参与其他用户的项目中去。
6.3.2.3. 区域(Region)
目前支持北京(regionone)区域,除了认证服务是统一入口,其他的服务都区分区域。
6.3.2.3.1. 角色(Role)
目前系统支持的角色有:
- 拥有者(Project_Owner) 是指该项目的所有者,拥有对项目资源和账号CRUD权限,能够创建其他角色的用户。
- 管理员(Project_Admin) 是指该项目的管理者,拥有对项目资源的CRUD权限,不能管理账号。
- 观察者(Project_Observer) 是指该项目的观察者,对项目资源有只读权限。
- 无权限(Project_Noaccess) 对该项目没有任何权限。
6.3.2.4. 服务目录(Service Catalog)
服务目录是指在获得Token并且通过权限认证之后光环云认证服务返回的授权的服务列表,比如,如下
{ "token": { "catalog": [ #以下段即就"服务目录"" { #这一段列出了compute服务的endpoint信息。 "endpoints": [ { "id": "regionone__compute__public__id", "interface": "public", "region": "regionone", "url": "https://regionone-compute-api.sinnetcloud.com.cn" } ], "id": "compute__id", "type": "compute" }, ……
光环云目前支持的服务有云主机服务(Compute),网络服务(Network), 块存储服务(Volume), 报表统计服务(Metering), 监控报警服务(Alarm), 计费服务(Billing)等。
Note
为了降低用户的使用成本,OpenStack Keystone的Domain和Policy的概念在光环云认证服务中被隐藏。
6.3.3. 公共字段
6.3.3.1. 公共请求头
请求头 | 类型 | 说明 |
---|---|---|
Content-Type | string | 指定请求内容类型,当没有指定时,默认是: application/json |
Accept | string | 指定返回内容类型,当没有指定时,默认是: application/json |
X-Auth-Token | string | 请求光环云各服务REST API时要求在请求头中带上的经过认证的Token |
X-Subject-Token | string | 该请求头仅用于Token的DELETE/HEAD/GET操作 |
6.3.3.2. 公共返回头
返回头 | 类型 | 说明 |
---|---|---|
Content-Type | string | 表明返回内容类型,默认是: application/json |
X-Subject-Token | string | 该返回头仅出现于获得Token操作的返回头中 |
6.3.3.3. 常见HTTP返回码
HTTP错误码 | 原因 | 说明 |
200 | Normal | 操作成功,正常返回 |
201 | Created | 一般指创建资源成功,正常返回 |
400 | badRequest | 请求错误 |
401 | unauthorized | 请求所带的Token没有经过认证或者认证失败 |
403 | forbidden | 操作禁止 |
404 | itemNotFound | 没找到对象 |
405 | badMethod | 不支持的HTTP方法 |
413 | overLimit | 超过请求频率的限制 |
503 | serviceUnavailable | 超过请求频率的限制 |
6.3.4. API规范
认证服务API入口与API列表如下:
- API入口: https://identity-api.sinnetcloud.com.cn
- API列表:
资源 | 操作 | HTTP方法 | URI路径 |
---|---|---|---|
Versions (版本) | 版本 (Versions) | GET | / |
Tokens (令牌) | 认证并生成新令牌 | POST | /v3/auth/tokens |
Projects (项目) | 列出某用户的所有项目 | GET | /v3/users/{user_id}/projects |
6.3.5. 版本 (Versions)
该API返回光环云认证服务支持的版本和不同版本支持的状态。目前光环云只支持v3.0版本。
6.3.5.1. 查看API版本
HTTP方法 | URI路径 | 描述 |
---|---|---|
GET | / | 查看API版本 |
请求参数
无。
返回参数
字段名 | 类型 | 描述 |
---|---|---|
verions | dict | API版本详情 |
id | string | 版本号,如v2.0, v3.0 |
status | string | 当前版本状态:stable (稳定状态,推荐使用), beta (测试阶段) |
updated | string | 该版本API最近更新时间 |
请求样例
curl https://identity-api.sinnetcloud.com.cn | python -m json.tool
返回样例
{ "versions": { "values": [ { "id": "v3.0", "links": [ { "href": "https://identity-api.sinnetcloud.com.cn", "rel": "self" } ], "media-types": [ { "base": "application/json", "type": "application/vnd.openstack.identity-v3+json" }, { "base": "application/xml", "type": "application/vnd.openstack.identity-v3+xml" } ], "status": "stable", "updated": "2013-03-06T00:00:00Z" } ] } }
6.3.6. 令牌 (Tokens)
6.3.6.1. 认证并生成新令牌
HTTP方法 | URI路径 | 描述 |
---|---|---|
POST | /v3/auth/tokens | 获取令牌 |
请求参数
字段名 | 类型 | 描述 |
---|---|---|
auth | dict | 认证信息(identity)和认证的范围(scope) |
identity | dict | 认证信息,包含论证方法(methods)和密钥信息(accessKey) |
scope | dict | 认证的范围,是指该获得的token的作用域,光环云支持项目级别的作用域 |
methods | array | 认证方法,目前光环云两种认证方法: password和accessKey: password认证需要用户名(name)和密码(password)认证方法, accessKey认证方法需要accessKey和secretKey |
project | dict | 项目标识信息,光环云只支持通过项目id标识一个项目 |
请求样例
curl -s -X POST https://identity-api.sinnetcloud.com.cn/v3/auth/tokens -H "Content-Type:application/json" -d '{ "auth": { "identity": { "methods": [ "password" ], "password": { "user": { "id": "66d128ca70594ea2bc13972630bf79c0", "password": "3d7ca421" } } }, "scope": { "project": { "id": "f1bd65517b604f35a2a7a3f1f16cf0ed" } } } }'
返回参数
字段名 | 类型 | 描述 |
---|---|---|
X-Subject-Token | string | 一个32位的字符串,验证成功之后在返回头中, 在随后的请求中会用到该Token |
token | dict | 返回token信息,包含了catalog, project, rule, user, methods等信息 |
catalog | array | 服务目录,包含了用户有权限的所有光环云服务的endpoints信息 |
project | dict | 项目信息,包含了项目名,项目ID和项目所属的域 (Domain) 信息 |
user | dict | 用户信息,包含了用户名,用户ID和用户所属的域 (Domain) 信息 |
rules | array | 该用户在该项目上的角色信息 |
expires_at | timestamp | Token失效日期 |
issued_at | timestamp | Token创建日期 |
extras | dict | Token额外信息,该字段暂时为空 |
endpoints | array | 光环云服务id, 类型 (type) 和endpoint信息(包含url, region) |
返回样例
HTTP/1.1 201 Created X-Subject-Token: 8308a5608ef14affb08184479c152a05 { "token": { "catalog": [ { "endpoints": [ { "id": "regionone__volume__public__id", "interface": "public", "region": "regionone", "url": "https://regionone-volume-api.sinnetcloud.com.cn" }, { "id": "regionone__volume__public__id", "interface": "public", "region": "regionone", "url": "https://regionone-volume-api.sinnetcloud.com.cn" } ], "id": "volume__id", "type": "volume" }, { "endpoints": [ { "id": "regionone__image__public__id", "interface": "public", "region": "regionone", "url": "https://regionone-image-api.sinnetcloud.com.cn" }, { "id": "regionone__image__public__id", "interface": "public", "region": "regionone", "url": "https://regionone-image-api.sinnetcloud.com.cn" } ], "id": "image__id", "type": "image" }, { "endpoints": [ { "id": "regionone__compute__public__id", "interface": "public", "region": "regionone", "url": "https://regionone-compute-api.sinnetcloud.com.cn" }, { "id": "regionone__compute__public__id", "interface": "public", "region": "regionone", "url": "https://regionone-compute-api.sinnetcloud.com.cn" } ], "id": "compute__id", "type": "compute" }, { "endpoints": [ { "id": "regionone__share__public__id", "interface": "public", "region": "regionone", "url": "https://regionone-share-api.sinnetcloud.com.cn" }, { "id": "regionone__share__public__id", "interface": "public", "region": "regionone", "url": "https://regionone-share-api.sinnetcloud.com.cn" } ], "id": "share__id", "type": "share" }, { "endpoints": [ { "id": "regionone__network__public__id", "interface": "public", "region": "regionone", "url": "https://regionone-network-api.sinnetcloud.com.cn" }, { "id": "regionone__network__public__id", "interface": "public", "region": "regionone", "url": "https://regionone-network-api.sinnetcloud.com.cn" } ], "id": "network__id", "type": "network" }, { "endpoints": [ { "id": "center__identity__public__id", "interface": "public", "region": "center", "url": "https://identity-api.sinnetcloud.com.cn" } ], "id": "identity__id", "type": "identity" } ], "expires_at": "2014-07-04T06:09:48.853381Z", "extras": {}, "issued_at": "2014-07-04T05:09:48.853413Z", "methods": [ "password" ], "project": { "domain": { "id": "6cb77e5ac1744119b44a7e24a0c1bc7e", "name": "uos_6cb77e5ac1744119b44a7e24a0c1bc7e_domain_default" }, "id": "f1bd65517b604f35a2a7a3f1f16cf0ed", "name": "uos_project" }, "roles": [ { "id": "1a4b9c02eba24151b39eb300a658df7e", "name": "domain_admin" } ], "user": { "domain": { "id": "6cb77e5ac1744119b44a7e24a0c1bc7e", "name": "uos_6cb77e5ac1744119b44a7e24a0c1bc7e_domain_default" }, "id": "66d128ca70594ea2bc13972630bf79c0", "name": "uos_6cb77e5ac1744119b44a7e24a0c1bc7e" } } }
6.3.7. 项目 (Projects)
6.3.7.1. 列出某用户的所有项目
HTTP方法 | URI路径 | 描述 |
---|---|---|
GET | /v3/users/{user_id}/projects | 列出用户{user_id}能够有权限访问的所有项目 |
请求参数
参数名 | 类型 | 描述 |
---|---|---|
X-Auth-Token | string | 通过光环云认证服务获得的有效Token |
请求样例
curl -s -X GET https://identity-api.sinnetcloud.com.cn/v3/users/{user_id}/projects -H "X-Auth-Token: 8308a5608ef14affb08184479c152a05" | python -m json.tool
返回参数
参数名 | 类型 | 描述 |
---|---|---|
projects | array | 项目列表信息 |
enabled | bool | 该项目是否被启用,取值true或false |
domain_id | string | 项目所属域id |
表中只列举部分重要参数,全部参数见 返回样例 。
返回样例
{ "links": { "next": null, "previous": null, "self": "https://identity-api.sinnetcloud.com.cn/v3/users/{User_ID}/projects" }, "projects": [ { "description": "Project One for {User_ID}", "domain_id": "--domain--one--id---", "enabled": true, "id": "--project--one--id--", "links": { "self": "https://identity-api.sinnetcloud.com.cn/v3/projects/--project-one--id--" }, "name": "project-one" }, { "description": "Another project for {User_ID}", "domain_id": "--domain--two--id--", "enabled": true, "id": "--project--two--id--", "links": { "self": "https://identity-api.sinnetcloud.com.cn/v3/projects/--project-two--id--" }, "name": "project-two" } ] }