openstack之role篇

来源:互联网 发布:php 开源考试平台 编辑:程序博客网 时间:2024/06/07 14:02

一、role简介

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


二、role基本操作

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

  列举:

  # keystone role-list

 创建:

 # keystone role-create

  删除:

  # keystonerole-delete

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


通过role操作用户

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

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

 # keystone tenant-create --name tenant1 --enabled true

 # keystone tenant-create --name tenant2 --enabled true


 为tenant1创建用户user1, 为tenant2创建用户user2:

  # keystone user-create --name user1 --tenant-id <tenant-id of tenant1> --pass password --enabled true  

  # keystone user-create --name user2 --tenant-id <tenant-id of tenant2> --pass password --enabled true     
       
  先不进行role操作,用user1用户创建一个instance:

  # nova --os-username user1--os-password password --os-tenant-name tenant1 boot test --image "cb79a458-169d-413e-89d0-02bcae61569a" --flavor 1

  #nova --os_username user1 --os_password password --os_tenant_name tenant1 list

  +--------------------------------------+-------+--------+---------------------------+

  | ID                                   | Name  | Status | Networks                  |
  +--------------------------------------+-------+--------+---------------------------+
  | 88bc939b-e29e-44ee-9f09-ec45a93ee6c4 | test | ACTIVE | nova_fixed=192.168.123.65 |
  +--------------------------------------+-------+--------+---------------------------+

  这时候,用user2用户登录,是无法对user1用户创建的instance进行操作的。

  #nova --os_username user2 --os_password password --os_tenant_name tenant2 list

  -- <NULL> --


  创建role test:

  keystone role-create --name test

   +----------+----------------------------------+
   | Property |              Value               |
   +----------+----------------------------------+
   |    id    | 2493283f09c1475198f2337a47aa398f |
   |   name   |              test               |
   +----------+----------------------------------+

  通过role test将user2用户加入到名为tenant1的tenant中:

   # keystone user-role-add --user-id 7b32f4fc92704947802d2eca95edff0d --role-id 2493283f09c1475198f2337a47aa398f --tenant-id 0647347fa21d4221b0197cd282465a00

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

   这样,就把user2用户加入到了tenant1。

  #nova --os_username user2 --os_password password --os_tenant_name tenant1 list

   +--------------------------------------+-------+--------+---------------------------+
   | ID                                   | Name  | Status | Networks                  |
   +--------------------------------------+-------+--------+---------------------------+
   | 88bc939b-e29e-44ee-9f09-ec45a93ee6c4 | test | ACTIVE | nova_fixed=192.168.123.65 |
   +--------------------------------------+-------+--------+---------------------------+
   test2用户可以看到tenant1下的instance。

  # 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,也就是:

   nova list --all_tenants

   不过,略显奇怪的是,通过命令:

  # keystone user-role-list --user-id 7b32f4fc92704947802d2eca95edff0d

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


原创粉丝点击