[转]Setting Keystone v3 domains
http://www.florentflament.com/blog/setting-keystone-v3-domains.html
The Openstack Identity v3 API, provided by Keystone, offers features that were lacking in the previous version. Among these features, it introduces the concept of domains, allowing isolation of projects and users. For instance, an administrator allowed to create projects and users in a given domain, may not have any right in another one. While these features look very exciting, some configuration needs to be done to have a working identity v3 service with domains properly set.
Keystone API protection section of the developer's doc provides hints about how to set-up a multi-domain installation. Starting from there, I describe the full steps to have a multi-domain setup running, by using curl to send http requests and jq to parse the json answers.
Setting an admin domain and a cloud admin
First, we have to start on a fresh non multi-domain installation with the default policy file.
- With the - adminuser we can create the- admin_domain.- ADMIN_TOKEN=$(\ 
 curl http://localhost:5000/v3/auth/tokens \
 -s \
 -i \
 -H "Content-Type: application/json" \
 -d '
 {
 "auth": {
 "identity": {
 "methods": [
 "password"
 ],
 "password": {
 "user": {
 "domain": {
 "name": "Default"
 },
 "name": "admin",
 "password": "password"
 }
 }
 },
 "scope": {
 "project": {
 "domain": {
 "name": "Default"
 },
 "name": "admin"
 }
 }
 }
 }' | grep ^X-Subject-Token: | awk '{print $2}' ) ID_ADMIN_DOMAIN=$(\
 curl http://localhost:5000/v3/domains \
 -s \
 -H "X-Auth-Token: $ADMIN_TOKEN" \
 -H "Content-Type: application/json" \
 -d '
 {
 "domain": {
 "enabled": true,
 "name": "admin_domain"
 }
 }' | jq .domain.id | tr -d '"' ) echo "ID of domain cloud: $ID_ADMIN_DOMAIN"
- Then we can create our - cloud_adminuser, within the- admin_domaindomain.- ID_CLOUD_ADMIN=$(\ 
 curl http://localhost:5000/v3/users \
 -s \
 -H "X-Auth-Token: $ADMIN_TOKEN" \
 -H "Content-Type: application/json" \
 -d "
 {
 \"user\": {
 \"description\": \"Cloud administrator\",
 \"domain_id\": \"$ID_ADMIN_DOMAIN\",
 \"enabled\": true,
 \"name\": \"cloud_admin\",
 \"password\": \"password\"
 }
 }" | jq .user.id | tr -d '"' ) echo "ID of user cloud_admin: $ID_CLOUD_ADMIN"
- And we grant to our user - cloud_adminthe- adminrole on domain- admin_domain.- ADMIN_ROLE_ID=$(\ 
 curl http://localhost:5000/v3/roles?name=admin \
 -s \
 -H "X-Auth-Token: $ADMIN_TOKEN" \
 | jq .roles[0].id | tr -d '"' ) curl -X PUT http://localhost:5000/v3/domains/${ID_ADMIN_DOMAIN}/users/${ID_CLOUD_ADMIN}/roles/${ADMIN_ROLE_ID} \
 -s \
 -i \
 -H "X-Auth-Token: $ADMIN_TOKEN" \
 -H "Content-Type: application/json" curl http://localhost:5000/v3/domains/${ID_ADMIN_DOMAIN}/users/${ID_CLOUD_ADMIN}/roles\
 -s \
 -H "X-Auth-Token: $ADMIN_TOKEN" | jq .roles
- Once the - admin_domainhas been created with its- cloud_adminuser, we can enforce a domain based policy. In order to do that, we have to copy the policy.v3cloudsample.json file over our former- /etc/keystone/policy.json, while replacing the string- admin_domain_idby the ID of the- admin_domainwe just created. Locate the- policy.v3cloudsample.jsonfile into the- etcdirectory of Keystone's source.- sed s/admin_domain_id/${ID_ADMIN_DOMAIN}/ \
 < policy.v3cloudsample.json \
 > /etc/keystone/policy.json
Warning, current version (commit 19620076f587f925c5d2fa59780c1a80dde15db2) of policy.v3cloudsample.json doesn't allow cloud_admin to manage users in other domains than its own (see bug 1267187). Until the patch is merged, I suggest using this policy.c3cloudsample.json under review.
Creating domains and admins
From now on, the admin user can only manage projects and users in the Default domain. To create other domains we will have to authenticate with the cloud_admin user created above.
- Getting a token scoped on the - admin_domain, for user- cloud_admin.- CLOUD_ADMIN_TOKEN=$(\ 
 curl http://localhost:5000/v3/auth/tokens \
 -s \
 -i \
 -H "Content-Type: application/json" \
 -d '
 {
 "auth": {
 "identity": {
 "methods": [
 "password"
 ],
 "password": {
 "user": {
 "domain": {
 "name": "admin_domain"
 },
 "name": "cloud_admin",
 "password": "password"
 }
 }
 },
 "scope": {
 "domain": {
 "name": "admin_domain"
 }
 }
 }
 }' | grep ^X-Subject-Token: | awk '{print $2}' )
- Creating domains - dom1and- dom2.- ID_DOM1=$(\ 
 curl http://localhost:5000/v3/domains \
 -s \
 -H "X-Auth-Token: $CLOUD_ADMIN_TOKEN" \
 -H "Content-Type: application/json" \
 -d '
 {
 "domain": {
 "enabled": true,
 "name": "dom1"
 }
 }' | jq .domain.id | tr -d '"') echo "ID of dom1: $ID_DOM1" ID_DOM2=$(\
 curl http://localhost:5000/v3/domains \
 -s \
 -H "X-Auth-Token: $CLOUD_ADMIN_TOKEN" \
 -H "Content-Type: application/json" \
 -d '
 {
 "domain": {
 "enabled": true,
 "name": "dom2"
 }
 }' | jq .domain.id | tr -d '"') echo "ID of dom2: $ID_DOM2"
- Now we will create a user - adm1in domain- dom1.- ID_ADM1=$(\ 
 curl http://localhost:5000/v3/users \
 -s \
 -H "X-Auth-Token: $CLOUD_ADMIN_TOKEN" \
 -H "Content-Type: application/json" \
 -d "
 {
 \"user\": {
 \"description\": \"Administrator of domain dom1\",
 \"domain_id\": \"$ID_DOM1\",
 \"enabled\": true,
 \"name\": \"adm1\",
 \"password\": \"password\"
 }
 }" | jq .user.id | tr -d '"') echo "ID of user adm1: $ID_ADM1"
- We will also grant the - adminrole on domain- dom1to this- adm1user.- curl -X PUT http://localhost:5000/v3/domains/${ID_DOM1}/users/${ID_ADM1}/roles/${ADMIN_ROLE_ID} \
 -s \
 -i \
 -H "X-Auth-Token: $CLOUD_ADMIN_TOKEN" \
 -H "Content-Type: application/json" curl http://localhost:5000/v3/domains/${ID_DOM1}/users/${ID_ADM1}/roles \
 -s \
 -H "X-Auth-Token: $CLOUD_ADMIN_TOKEN" | jq .roles
Creating projects and users
The adm1 user can now fully manage domain dom1. He is allowed to manage as many projects and users as he wishes within dom1, while not being able to access resources of domain dom2.
- Now we authenticate as user - adm1with a scope on- dom1.- ADM1_TOKEN=$(\ 
 curl http://localhost:5000/v3/auth/tokens \
 -s \
 -i \
 -H "Content-Type: application/json" \
 -d '
 {
 "auth": {
 "identity": {
 "methods": [
 "password"
 ],
 "password": {
 "user": {
 "domain": {
 "name": "dom1"
 },
 "name": "adm1",
 "password": "password"
 }
 }
 },
 "scope": {
 "domain": {
 "name": "dom1"
 }
 }
 }
 }' | grep ^X-Subject-Token: | awk '{print $2}' )
- We create a project - prj1in domain- dom1.- ID_PRJ1=$(\ 
 curl http://localhost:5000/v3/projects \
 -s \
 -H "X-Auth-Token: $ADM1_TOKEN" \
 -H "Content-Type: application/json" \
 -d "
 {
 \"project\": {
 \"enabled\": true,
 \"domain_id\": \"$ID_DOM1\",
 \"name\": \"prj1\"
 }\
 }" | jq .project.id | tr -d '"' ) echo "ID of prj1: $ID_PRJ1"
- When trying and creating a project in domain - dom2, it fails.- curl http://localhost:5000/v3/projects \ 
 -s \
 -H "X-Auth-Token: $ADM1_TOKEN" \
 -H "Content-Type: application/json" \
 -d "
 {
 \"project\": {
 \"enabled\": true,
 \"domain_id\": \"$ID_DOM2\",
 \"name\": \"prj2\"
 }\
 }" | jq .
- Creating a standard user - usr1in domain- dom1, with default project- prj1.- ID_USR1=$(\ 
 curl http://localhost:5000/v3/users \
 -s \
 -H "X-Auth-Token: $ADM1_TOKEN" \
 -H "Content-Type: application/json" \
 -d "
 {
 \"user\": {
 \"default_project_id\": \"$ID_PRJ1\",
 \"description\": \"Just a user of dom1\",
 \"domain_id\": \"$ID_DOM1\",
 \"enabled\": true,
 \"name\": \"usr1\",
 \"password\": \"password\"
 }
 }" | jq .user.id | tr -d '"' ) echo "ID of user usr1: $ID_USR1"
- Granting - Memberrole to user- usr1on project- prj1.- MEMBER_ROLE_ID=$(\ 
 curl http://localhost:5000/v3/roles?name=Member \
 -s \
 -H "X-Auth-Token: $ADM1_TOKEN" \
 | jq .roles[0].id | tr -d '"' ) curl -X PUT http://localhost:5000/v3/projects/${ID_PRJ1}/users/${ID_USR1}/roles/${MEMBER_ROLE_ID} \
 -s \
 -i \
 -H "X-Auth-Token: $ADM1_TOKEN" \
 -H "Content-Type: application/json" curl http://localhost:5000/v3/projects/${ID_PRJ1}/users/${ID_USR1}/roles \
 -s \
 -H "X-Auth-Token: $ADM1_TOKEN" | jq .roles
The domain administrator adm1 ended up creating a project prj1 and a user usr1 member of the project. usr1 can now get a token scoped onprj1 and manage resources into this project.
[转]Setting Keystone v3 domains的更多相关文章
- 在Keystone V3基础上改进的分布式认证体系
		目标 使用java实现keystone v3相关功能与概念: api client authentication service discovery distributed multi-tenant ... 
- OpenStack IdentityService Keystone V3 API Curl实战
		v3 API Examples Using Curl <Tokens> 1,Default scope 获取token Get an token with default scope (m ... 
- 使用openstackclient调用Keystone v3 API
		本文内容属于个人原创,转载务必注明出处: http://www.cnblogs.com/Security-Darren/p/4138945.html 考虑到Keystone社区逐渐弃用第二版身份AP ... 
- [转]OpenStack Keystone V3
		Keystone V3 Keystone 中主要涉及到如下几个概念:User.Tenant.Role.Token.下面对这几个概念进行简要说明. User:顾名思义就是使用服务的用户,可以是人.服务或 ... 
- OpenStack Keystone V3 简介
		Keystone V3 简介 Keystone 中主要涉及到如下几个概念:User.Tenant.Role.Token.下面对这几个概念进行简要说明. User:顾名思义就是使用服务的用户,可以是人. ... 
- Keystone V3 API Examples
		There are few things more useful than a set of examples when starting to work with a new API. Here a ... 
- 【openStack】Libcloud 如何支持 keystone V3?
		Examples This section includes some examples which show how to use the newly available functionality ... 
- OpenStack Keystone v3 API新特性
		原连接 http://blog.chinaunix.net/uid-21335514-id-3497996.html keystone的v3 API与v2.0相比有很大的不同,从API的请求格式到re ... 
- Openstack Keystone V3 利用 curl 命令获取 token
		curl -i \ -H "Content-Type: application/json" \ -d ' { "auth": { "identity& ... 
随机推荐
- MySQL存储过程中的事务执行失败之后获取错误信息
			1.表结构: 2. 存储过程中: 代码如下: BEGINDECLARE CONTINUE HANDLER FOR SQLEXCEPTIONBEGINROLLBACK;GET DIAGNOSTICS C ... 
- Unity中锚点的动态设置
			问题背景 在做签到系统时,需求给的效果图如下 效果图像这样,中间是模型,周围其他是签到框这样的布局,我想动态生成各个动态框,涉及到一个定位问题,锚点的设置(动态去设置每个item的位置) 实现方法 S ... 
- ID3、C4.5、CART决策树介绍
			决策树是一类常见的机器学习方法,它可以实现分类和回归任务.决策树同时也是随机森林的基本组成部分,后者是现今最强大的机器学习算法之一. 1. 简单了解决策树 举个例子,我们要对”这是好瓜吗?”这样的问题 ... 
- ***ThinkPHP中的常用方法汇总总结:M方法,D方法,U方法,I方法
			thinkPHP中M()和D()的区别 在实例化的过程中,经常使用D方法和M方法,这两个方法的区别在于M方法实例化模型无需用户为每个数据表定义模型类,如果D方法没有找到定义的模型类,则会自动调用M方法 ... 
- python调用函数超时设置
			1.Windows中sign报错,Linux能很好的使用: https://pypi.python.org/pypi/timeout-decorator 2.Windows可以使用,Linux报错不能 ... 
- 异步简析之BlockingCollection实现生产消费模式
			目前市面上有诸多的产品实现队列功能,比如Redis.MemCache等... 其实c#中也有一个基础的集合类专门用来实现生产/消费模式 (生产模式还是建议使用Redis等产品) 下面是官方的一些资料和 ... 
- react-native自定义TextInput光标颜色
			<TextInput defaultValue="Highlight Color is red" selectionColor={'red'} style={styles.s ... 
- C语言第01次作业--顺序、分支结构
			1.本章学习总结 1.1 思维导图 1.2本章学习体会及代码量学习体会 1.2.1学习体会 本周我学到了很多C语言中基础的结构和语法(见思维导图),能对一些生活中的简单问题对应编写程序解决一些这些简单 ... 
- MyBatis  sqlsession 简化  使用工具类创建
			2019-04-09 @Test public void Test() throws Exception { // 1.读取配置文件 String resource = "mybatis-c ... 
- HDU 2204 Eddy's 爱好 (容斥原理)
			<题目链接> 题目大意: Ignatius 喜欢收集蝴蝶标本和邮票,但是Eddy的爱好很特别,他对数字比较感兴趣,他曾经一度沉迷于素数,而现在他对于一些新的特殊数比较有兴趣. 这些特殊数是 ... 
