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 admin user we can create the admin_domain.

    1. ADMIN_TOKEN=$(\
    2. curl http://localhost:5000/v3/auth/tokens \
    3. -s \
    4. -i \
    5. -H "Content-Type: application/json" \
    6. -d '
    7. {
    8. "auth": {
    9. "identity": {
    10. "methods": [
    11. "password"
    12. ],
    13. "password": {
    14. "user": {
    15. "domain": {
    16. "name": "Default"
    17. },
    18. "name": "admin",
    19. "password": "password"
    20. }
    21. }
    22. },
    23. "scope": {
    24. "project": {
    25. "domain": {
    26. "name": "Default"
    27. },
    28. "name": "admin"
    29. }
    30. }
    31. }
    32. }' | grep ^X-Subject-Token: | awk '{print $2}' )
    33.  
    34. ID_ADMIN_DOMAIN=$(\
    35. curl http://localhost:5000/v3/domains \
    36. -s \
    37. -H "X-Auth-Token: $ADMIN_TOKEN" \
    38. -H "Content-Type: application/json" \
    39. -d '
    40. {
    41. "domain": {
    42. "enabled": true,
    43. "name": "admin_domain"
    44. }
    45. }' | jq .domain.id | tr -d '"' )
    46.  
    47. echo "ID of domain cloud: $ID_ADMIN_DOMAIN"
  • Then we can create our cloud_admin user, within the admin_domain domain.

    1. ID_CLOUD_ADMIN=$(\
    2. curl http://localhost:5000/v3/users \
    3. -s \
    4. -H "X-Auth-Token: $ADMIN_TOKEN" \
    5. -H "Content-Type: application/json" \
    6. -d "
    7. {
    8. \"user\": {
    9. \"description\": \"Cloud administrator\",
    10. \"domain_id\": \"$ID_ADMIN_DOMAIN\",
    11. \"enabled\": true,
    12. \"name\": \"cloud_admin\",
    13. \"password\": \"password\"
    14. }
    15. }" | jq .user.id | tr -d '"' )
    16.  
    17. echo "ID of user cloud_admin: $ID_CLOUD_ADMIN"
  • And we grant to our user cloud_admin the admin role on domain admin_domain.

    1. ADMIN_ROLE_ID=$(\
    2. curl http://localhost:5000/v3/roles?name=admin \
    3. -s \
    4. -H "X-Auth-Token: $ADMIN_TOKEN" \
    5. | jq .roles[0].id | tr -d '"' )
    6.  
    7. curl -X PUT http://localhost:5000/v3/domains/${ID_ADMIN_DOMAIN}/users/${ID_CLOUD_ADMIN}/roles/${ADMIN_ROLE_ID} \
    8. -s \
    9. -i \
    10. -H "X-Auth-Token: $ADMIN_TOKEN" \
    11. -H "Content-Type: application/json"
    12.  
    13. curl http://localhost:5000/v3/domains/${ID_ADMIN_DOMAIN}/users/${ID_CLOUD_ADMIN}/roles\
    14. -s \
    15. -H "X-Auth-Token: $ADMIN_TOKEN" | jq .roles
  • Once the admin_domain has been created with its cloud_admin user, 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_id by the ID of the admin_domain we just created. Locate the policy.v3cloudsample.json file into the etc directory of Keystone's source.

    1. sed s/admin_domain_id/${ID_ADMIN_DOMAIN}/ \
    2. < policy.v3cloudsample.json \
    3. > /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.

    1. CLOUD_ADMIN_TOKEN=$(\
    2. curl http://localhost:5000/v3/auth/tokens \
    3. -s \
    4. -i \
    5. -H "Content-Type: application/json" \
    6. -d '
    7. {
    8. "auth": {
    9. "identity": {
    10. "methods": [
    11. "password"
    12. ],
    13. "password": {
    14. "user": {
    15. "domain": {
    16. "name": "admin_domain"
    17. },
    18. "name": "cloud_admin",
    19. "password": "password"
    20. }
    21. }
    22. },
    23. "scope": {
    24. "domain": {
    25. "name": "admin_domain"
    26. }
    27. }
    28. }
    29. }' | grep ^X-Subject-Token: | awk '{print $2}' )
  • Creating domains dom1 and dom2.

    1. ID_DOM1=$(\
    2. curl http://localhost:5000/v3/domains \
    3. -s \
    4. -H "X-Auth-Token: $CLOUD_ADMIN_TOKEN" \
    5. -H "Content-Type: application/json" \
    6. -d '
    7. {
    8. "domain": {
    9. "enabled": true,
    10. "name": "dom1"
    11. }
    12. }' | jq .domain.id | tr -d '"')
    13.  
    14. echo "ID of dom1: $ID_DOM1"
    15.  
    16. ID_DOM2=$(\
    17. curl http://localhost:5000/v3/domains \
    18. -s \
    19. -H "X-Auth-Token: $CLOUD_ADMIN_TOKEN" \
    20. -H "Content-Type: application/json" \
    21. -d '
    22. {
    23. "domain": {
    24. "enabled": true,
    25. "name": "dom2"
    26. }
    27. }' | jq .domain.id | tr -d '"')
    28.  
    29. echo "ID of dom2: $ID_DOM2"
  • Now we will create a user adm1 in domain dom1.

    1. ID_ADM1=$(\
    2. curl http://localhost:5000/v3/users \
    3. -s \
    4. -H "X-Auth-Token: $CLOUD_ADMIN_TOKEN" \
    5. -H "Content-Type: application/json" \
    6. -d "
    7. {
    8. \"user\": {
    9. \"description\": \"Administrator of domain dom1\",
    10. \"domain_id\": \"$ID_DOM1\",
    11. \"enabled\": true,
    12. \"name\": \"adm1\",
    13. \"password\": \"password\"
    14. }
    15. }" | jq .user.id | tr -d '"')
    16.  
    17. echo "ID of user adm1: $ID_ADM1"
  • We will also grant the admin role on domain dom1 to this adm1 user.

    1. curl -X PUT http://localhost:5000/v3/domains/${ID_DOM1}/users/${ID_ADM1}/roles/${ADMIN_ROLE_ID} \
    2. -s \
    3. -i \
    4. -H "X-Auth-Token: $CLOUD_ADMIN_TOKEN" \
    5. -H "Content-Type: application/json"
    6.  
    7. curl http://localhost:5000/v3/domains/${ID_DOM1}/users/${ID_ADM1}/roles \
    8. -s \
    9. -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 adm1 with a scope on dom1.

    1. ADM1_TOKEN=$(\
    2. curl http://localhost:5000/v3/auth/tokens \
    3. -s \
    4. -i \
    5. -H "Content-Type: application/json" \
    6. -d '
    7. {
    8. "auth": {
    9. "identity": {
    10. "methods": [
    11. "password"
    12. ],
    13. "password": {
    14. "user": {
    15. "domain": {
    16. "name": "dom1"
    17. },
    18. "name": "adm1",
    19. "password": "password"
    20. }
    21. }
    22. },
    23. "scope": {
    24. "domain": {
    25. "name": "dom1"
    26. }
    27. }
    28. }
    29. }' | grep ^X-Subject-Token: | awk '{print $2}' )
  • We create a project prj1 in domain dom1.

    1. ID_PRJ1=$(\
    2. curl http://localhost:5000/v3/projects \
    3. -s \
    4. -H "X-Auth-Token: $ADM1_TOKEN" \
    5. -H "Content-Type: application/json" \
    6. -d "
    7. {
    8. \"project\": {
    9. \"enabled\": true,
    10. \"domain_id\": \"$ID_DOM1\",
    11. \"name\": \"prj1\"
    12. }\
    13. }" | jq .project.id | tr -d '"' )
    14.  
    15. echo "ID of prj1: $ID_PRJ1"
  • When trying and creating a project in domain dom2, it fails.

    1. curl http://localhost:5000/v3/projects \
    2. -s \
    3. -H "X-Auth-Token: $ADM1_TOKEN" \
    4. -H "Content-Type: application/json" \
    5. -d "
    6. {
    7. \"project\": {
    8. \"enabled\": true,
    9. \"domain_id\": \"$ID_DOM2\",
    10. \"name\": \"prj2\"
    11. }\
    12. }" | jq .
  • Creating a standard user usr1 in domain dom1, with default project prj1.

    1. ID_USR1=$(\
    2. curl http://localhost:5000/v3/users \
    3. -s \
    4. -H "X-Auth-Token: $ADM1_TOKEN" \
    5. -H "Content-Type: application/json" \
    6. -d "
    7. {
    8. \"user\": {
    9. \"default_project_id\": \"$ID_PRJ1\",
    10. \"description\": \"Just a user of dom1\",
    11. \"domain_id\": \"$ID_DOM1\",
    12. \"enabled\": true,
    13. \"name\": \"usr1\",
    14. \"password\": \"password\"
    15. }
    16. }" | jq .user.id | tr -d '"' )
    17.  
    18. echo "ID of user usr1: $ID_USR1"
  • Granting Member role to user usr1 on project prj1.

    1. MEMBER_ROLE_ID=$(\
    2. curl http://localhost:5000/v3/roles?name=Member \
    3. -s \
    4. -H "X-Auth-Token: $ADM1_TOKEN" \
    5. | jq .roles[0].id | tr -d '"' )
    6.  
    7. curl -X PUT http://localhost:5000/v3/projects/${ID_PRJ1}/users/${ID_USR1}/roles/${MEMBER_ROLE_ID} \
    8. -s \
    9. -i \
    10. -H "X-Auth-Token: $ADM1_TOKEN" \
    11. -H "Content-Type: application/json"
    12.  
    13. curl http://localhost:5000/v3/projects/${ID_PRJ1}/users/${ID_USR1}/roles \
    14. -s \
    15. -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的更多相关文章

  1. 在Keystone V3基础上改进的分布式认证体系

    目标 使用java实现keystone v3相关功能与概念: api client authentication service discovery distributed multi-tenant ...

  2. OpenStack IdentityService Keystone V3 API Curl实战

    v3 API Examples Using Curl <Tokens> 1,Default scope 获取token Get an token with default scope (m ...

  3. 使用openstackclient调用Keystone v3 API

    本文内容属于个人原创,转载务必注明出处:  http://www.cnblogs.com/Security-Darren/p/4138945.html 考虑到Keystone社区逐渐弃用第二版身份AP ...

  4. [转]OpenStack Keystone V3

    Keystone V3 Keystone 中主要涉及到如下几个概念:User.Tenant.Role.Token.下面对这几个概念进行简要说明. User:顾名思义就是使用服务的用户,可以是人.服务或 ...

  5. OpenStack Keystone V3 简介

    Keystone V3 简介 Keystone 中主要涉及到如下几个概念:User.Tenant.Role.Token.下面对这几个概念进行简要说明. User:顾名思义就是使用服务的用户,可以是人. ...

  6. 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 ...

  7. 【openStack】Libcloud 如何支持 keystone V3?

    Examples This section includes some examples which show how to use the newly available functionality ...

  8. OpenStack Keystone v3 API新特性

    原连接 http://blog.chinaunix.net/uid-21335514-id-3497996.html keystone的v3 API与v2.0相比有很大的不同,从API的请求格式到re ...

  9. Openstack Keystone V3 利用 curl 命令获取 token

    curl -i \ -H "Content-Type: application/json" \ -d ' { "auth": { "identity& ...

随机推荐

  1. Unity简单塔防游戏的开发——敌人移动路径的创建及移动

    软件工程综合实践专题第一次作业 Unity呢是目前一款比较火热的三维.二维动画以及游戏的开发引擎,我也由于一些原因开始接触并喜爱上了这款开发引擎,下面呢是我在学习该引擎开发小项目时编写的一些代码的脚本 ...

  2. Thymleaf 从某处(不包含某处)开始截取字符串到末尾

    简单描述:数据库存放的是id+name,但是做展示的时候,只需要展示name,不展示id.不管是在前台还是在后台,使用传统的方法截取,也是可以的,但是thymleaf提供了一种截取字符串,可以实现从某 ...

  3. 主席树——求区间[l,r]不同数字个数的模板(向左密集 D-query)

    主席树的另一种用途,,(还有一种是求区间第k大,区间<=k的个数) 事实上:每个版本的主席树维护了每个值最后出现的位置 这种主席树不是以权值线段树为基础,而是以普通的线段树为下标的 /* 无修改 ...

  4. 拦截请求并记录相应信息-springboot

    方式: 1.FIlter过滤器 2.interceptor拦截器 3.Aspect切片 一.Filter过滤器形式 只能处理request中的数据  不能确定请求要走的是哪个controller信息 ...

  5. ArrayList源码学习

    1.ArrayList:基于数据实现,允许出现空值和重复元素,当ArrayList中添加的元素数量大于底层数组容量是,会通过扩容机制重新生成一个更大的数组.(非线程安全) 2.源码分析 构造函数 /* ...

  6. ASP.NET Core快速入门学习笔记(第3章:依赖注入)

    课程链接:http://video.jessetalk.cn/course/explore 良心课程,大家一起来学习哈! 任务16:介绍 1.依赖注入概念详解 从UML和软件建模来理解 从单元测试来理 ...

  7. 检查linux版本命令

    lsb_release -a cat /etc/issue cat /proc/version uname -a cat /etc/redhat-release

  8. spark ML pipeline 学习

    一.pipeline 一个典型的机器学习过程从数据收集开始,要经历多个步骤,才能得到需要的输出.这非常类似于流水线式工作,即通常会包含源数据ETL(抽取.转化.加载),数据预处理,指标提取,模型训练与 ...

  9. python打包工具 cx_Freeze介绍

    原理 Python 脚本在装有 Python 的系统中可以直接双击运行,但绝大多数普通用户并没有配置此类环境,而编译为可执行二进制文件后,用户无需预先安装 Python 及依赖库即可像运行普通程序一样 ...

  10. 20175305张天钰《java程序设计》第八周学习总结

    <java程序设计>第八周学习总结 第十五章 泛型与集合框架 一.知识点学习 1.String类 1.String类不可以有子类. 2.用户无法输出String对象的引用,输出的是字符序列 ...