一分钟玩转Keystone是一种怎样的体验

Keystone是OpenStack最基础、最关键的认证服务,目前已发展为Identity, Token, Catalog and Policy as a Service。

通过Keystone服务,我们可以在命令行创建user和tenant,也可以为OpenStack项目提供多租户的支持。搭建Keystone 服务要求Python 2.7或以上版本,为了简化安装我们制作了基于Liberty的Keystone容器镜像,一分钟就可以体验Keystone命令了,赶快尝试吧。

Keystone容器

Keystone容器镜像是基于Dockerfile automated build的,完整的源码可以在Github查阅 https://github.com/tobegit3hub/keystone_docker

使用方法非常简单,首先是通过apt或yum安装docker,运行Liberty Keystone就一行命令。

docker run -d -p 5000:5000 -p 35357:35357 tobegit3hub/keystone_docker

查看一下本地的5000和35357端口,发现Keystone已经运行起来了,接下来可以通过命令行或API来测试这个服务。

Keystone客户端

本地还需要安装Keystone客户端吗?当然不需要,设置连Python也不求要安装,直接复用前面的Keystone容器镜像。

docker run -i -t –net=host tobegit3hub/keystone_docker bash

Keystone命令行已经装好,使用已经提供的openrc文件即可。


  1. source openrc 
  2. keystone user-create --name=admin --pass=ADMIN_PASS --email=admin@example.com 
  3. +----------+----------------------------------+ 
  4. | Property |              Value               | 
  5. +----------+----------------------------------+ 
  6. |  email   |        admin@example.com         | 
  7. | enabled  |               True               | 
  8. |    id    | 6c12289f2324405aaa068da611a8fad0 | 
  9. |   name   |              admin               | 
  10. | username |              admin               | 
  11. +----------+----------------------------------+ 
  12. keystone user-list 
  13. +----------------------------------+-------+---------+-------------------+ 
  14. |                id                |  name | enabled |       email       | 
  15. +----------------------------------+-------+---------+-------------------+ 
  16. | 6c12289f2324405aaa068da611a8fad0 | admin |   True  | admin@example.com | 
  17. +----------------------------------+-------+---------+-------------------+ 

通过API也可以访问,测试命令如下:


  1. curl -i \ 
  2.   -H "Content-Type: application/json" \ 
  3.   -d ' 
  4. "auth": { 
  5.     "identity": { 
  6.       "methods": ["password"], 
  7.       "password": { 
  8.         "user": { 
  9.           "name""admin"
  10.           "domain": { "id""default" }, 
  11.           "password""ADMIN_PASS" 
  12.         } 
  13.       } 
  14.     } 
  15.   } 
  16. }' \ 
  17.   http://localhost:5000/v3/auth/tokens ; echo 

Keystone命令

有了环境,我们就可以使用Keystone命令行进行开发测试了。

创建新user


  1. keystone user-create --name=admin --pass=ADMIN_PASS --email=admin@example.com 
  2. +----------+----------------------------------+ 
  3. | Property |              Value               | 
  4. +----------+----------------------------------+ 
  5. |  email   |        admin@example.com         | 
  6. | enabled  |               True               | 
  7. |    id    | 6c12289f2324405aaa068da611a8fad0 | 
  8. |   name   |              admin               | 
  9. | username |              admin               | 
  10. +----------+----------------------------------+ 

列举所有user


  1. keystone user-list 
  2. +----------------------------------+-------+---------+-------------------+ 
  3. |                id                |  name | enabled |       email       | 
  4. +----------------------------------+-------+---------+-------------------+ 
  5. | 6c12289f2324405aaa068da611a8fad0 | admin |   True  | admin@example.com | 
  6. +----------------------------------+-------+---------+-------------------+ 

创建新tenant

keystone tenant-create –name admin-tenant

+————-+———————————-+
| Property   | Value                               |
+————-+———————————-+
| description |                                       |
| enabled      | True                              |
| id                | 8d66b107c30d45ca85353a5182f8a154 |
| name          | admin-tenant                 |
+————-+———————————-+

列举所有tenant

keystone tenant-list

+———————————-+————–+———+
| id                                       | name       | enabled |
+———————————-+————–+———+
| 8d66b107c30d45ca85353a5182f8a154 | admin-tenant | True |
+———————————-+————–+———+

查看tenant详情

keystone tenant-get 8d66b107c30d45ca85353a5182f8a154

+————-+———————————-+
| Property   | Value                               |
+————-+———————————-+
| description |                                        |
| enabled     | True                                |
| id               | 8d66b107c30d45ca85353a5182f8a154 |
| name        | admin-tenant                   |
+————-+———————————-+

创建新role

keystone role-create –name new-role

+———-+———————————-+
| Property | Value                              |
+———-+———————————-+
| id           | 002701be4fd344538b93db05b9368b5c |
| name     | new-role                          |
+———-+———————————-+

列举所有role

keystone role-list

+———————————-+———-+
| id                                       | name   |
+———————————-+———-+
| 002701be4fd344538b93db05b9368b5c | new-role |
+———————————-+———-+

查看服务

keystone service-list

总结

利用Docker和Keystone结合,我们可以快速clone出一个服务的运行环境,并且在本地开发和生产环境快速交付,还有更多Keystone命令等待大家去发现。

未来我们也将推出Glance、Cinder等容器镜像,让OpenStack交付更加轻松和容易!

本文作者:陈迪豪

来源:51CTO

上一篇:私有静态内部类实现线程安全的单例


下一篇:简单mvc框架Power2php