分享

openstack之role篇

xioaxu790 发表于 2014-10-22 09:32:49 [显示全部楼层] 只看大图 回帖奖励 阅读模式 关闭右栏 1 18982
问题导读
1、一个用户如何加入另一个tenant?
2、role的操作有哪些?
3、通过role操作用户,有哪些步骤?






一、role简介
  从《openstack之tenant篇》我们知道,一个用户可以同时属于多个tenant,根据openstack.org里对role的定义,role规定了一个用户能够实现的行为。这个定于似乎稍显神秘,其实从管理用户使用的角度来说,role是和tenant息息相关的,一个用户想要加入另一个tenant,必须借助于role来完成,而由于tenant规定了其成员的行为规范,所以role也间接的起到了对于用户行为的规定。



二、role基本操作
  与user,tenant等一样,role的操作也无怪乎创建,更新,删除,列举等:

  列举:
  1.   # keystone role-list
复制代码



创建:
  1. # keystone role-create
复制代码



  删除:
  1.   # keystonerole-delete
复制代码



  ... 等等,由于太过简单,这里不再说明。



三、通过role操作用户
下面着重介绍通过role将一个用户加入到另一个tenant的小魔法。

  首先,创建两个tenant, 分别命名为tenant1和tenant2(注意创建tenant,user, role的keystone命令必须有administrator权限,这里对所有administrator操作忽略相关用户/密码/tenant的声明):
  1. # keystone tenant-create --name tenant1 --enabled true
  2. # keystone tenant-create --name tenant2 --enabled true
复制代码




为tenant1创建用户user1, 为tenant2创建用户user2:
  1.   # keystone user-create --name user1 --tenant-id <tenant-id of tenant1> --pass password --enabled true  
  2.   # keystone user-create --name user2 --tenant-id <tenant-id of tenant2> --pass password --enabled true     
复制代码



  先不进行role操作,用user1用户创建一个instance:
  1.   # nova --os-username user1--os-password password --os-tenant-name tenant1 boot test --image "cb79a458-169d-413e-89d0-02bcae61569a" --flavor 1
  2.   #nova --os_username user1 --os_password password --os_tenant_name tenant1 list
  3.   +--------------------------------------+-------+--------+---------------------------+
  4.   | ID                                   | Name  | Status | Networks                  |
  5.   +--------------------------------------+-------+--------+---------------------------+
  6.   | 88bc939b-e29e-44ee-9f09-ec45a93ee6c4 | test | ACTIVE | nova_fixed=192.168.123.65 |
  7.   +--------------------------------------+-------+--------+---------------------------+
复制代码



  这时候,用user2用户登录,是无法对user1用户创建的instance进行操作的。
  1. #nova --os_username user2 --os_password password --os_tenant_name tenant2 list
  2.   -- <NULL> --
复制代码



  创建role test:
  1.   keystone role-create --name test
  2.    +----------+----------------------------------+
  3.    | Property |              Value               |
  4.    +----------+----------------------------------+
  5.    |    id    | 2493283f09c1475198f2337a47aa398f |
  6.    |   name   |              test               |
  7.    +----------+----------------------------------+
复制代码



  通过role test将user2用户加入到名为tenant1的tenant中:
  1.    # keystone user-role-add --user-id 7b32f4fc92704947802d2eca95edff0d --role-id 2493283f09c1475198f2337a47aa398f --tenant-id 0647347fa21d4221b0197cd282465a00
复制代码



   其中7b32f4fc92704947802d2eca95edff0d是user2的id,0647347fa21d4221b0197cd282465a00是tenant1的id。

   这样,就把user2用户加入到了tenant1。
  1.   #nova --os_username user2 --os_password password --os_tenant_name tenant1 list
  2.    +--------------------------------------+-------+--------+---------------------------+
  3.    | ID                                   | Name  | Status | Networks                  |
  4.    +--------------------------------------+-------+--------+---------------------------+
  5.    | 88bc939b-e29e-44ee-9f09-ec45a93ee6c4 | test | ACTIVE | nova_fixed=192.168.123.65 |
  6.    +--------------------------------------+-------+--------+---------------------------+
复制代码



   test2用户可以看到tenant1下的instance。
  1.   # nova --os_username user2 --os_password password --os_tenant_name tenant1 delete 88bc939b-e29e-44ee-9f09-ec45a93ee6c4
复制代码




  user2用户可以将user1用户创建的instance删除,因为这个instance在tenant1中。当然,对于tenant1内的资源,user2用户也必须用tenant1内的身份去访问,这就是我们在上边的命令中定义--os_tenant_name为tenant1的原因。



  唯一例外的是admin tenant内的admin用户,因为这是一个administrator用户,所以用这个用户可以对所有tenant内的instance进行查看、更新、删除等操作。此外,admin用户缺省也只能看到自身tenant内的instance,如果想要看到其他tanent内的instance,需要加上参数--all_tenants,也就是:
  1.    nova list --all_tenants
复制代码



   不过,略显奇怪的是,通过命令:
  1.   # keystone user-role-list --user-id 7b32f4fc92704947802d2eca95edff0d
复制代码



   得不到任何用户和role的关系输出,这个命令到底有什么作用,尚待研究。

已有(1)人评论

跳转到指定楼层
hxw2ljj 发表于 2015-4-9 12:43:04
keystone user-role-list --user-id 5bcd65b677384a7e9955c0aef453e5fa 这个命令可以执行的。
keystone.png
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条