一分鐘玩轉(zhuǎn)Keystone是一種怎樣的體驗
Keystone是OpenStack最基礎(chǔ)、最關(guān)鍵的認證服務(wù),目前已發(fā)展為Identity, Token, Catalog and Policy as a Service。
通過Keystone服務(wù),我們可以在命令行創(chuàng)建user和tenant,也可以為OpenStack項目提供多租戶的支持。搭建Keystone 服務(wù)要求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端口,發(fā)現(xiàn)Keystone已經(jīng)運行起來了,接下來可以通過命令行或API來測試這個服務(wù)。
Keystone客戶端
本地還需要安裝Keystone客戶端嗎?當然不需要,設(shè)置連Python也不求要安裝,直接復(fù)用前面的Keystone容器鏡像。
docker run -i -t –net=host tobegit3hub/keystone_docker bash
Keystone命令行已經(jīng)裝好,使用已經(jīng)提供的openrc文件即可。
- source openrc
- keystone user-create --name=admin --pass=ADMIN_PASS --email=admin@example.com
- +----------+----------------------------------+
- | Property | Value |
- +----------+----------------------------------+
- | email | admin@example.com |
- | enabled | True |
- | id | 6c12289f2324405aaa068da611a8fad0 |
- | name | admin |
- | username | admin |
- +----------+----------------------------------+
- keystone user-list
- +----------------------------------+-------+---------+-------------------+
- | id | name | enabled | email |
- +----------------------------------+-------+---------+-------------------+
- | 6c12289f2324405aaa068da611a8fad0 | admin | True | admin@example.com |
- +----------------------------------+-------+---------+-------------------+
通過API也可以訪問,測試命令如下:
- curl -i \
- -H "Content-Type: application/json" \
- -d '
- { "auth": {
- "identity": {
- "methods": ["password"],
- "password": {
- "user": {
- "name": "admin",
- "domain": { "id": "default" },
- "password": "ADMIN_PASS"
- }
- }
- }
- }
- }' \
- http://localhost:5000/v3/auth/tokens ; echo
Keystone命令
有了環(huán)境,我們就可以使用Keystone命令行進行開發(fā)測試了。
創(chuàng)建新user
- keystone user-create --name=admin --pass=ADMIN_PASS --email=admin@example.com
- +----------+----------------------------------+
- | Property | Value |
- +----------+----------------------------------+
- | email | admin@example.com |
- | enabled | True |
- | id | 6c12289f2324405aaa068da611a8fad0 |
- | name | admin |
- | username | admin |
- +----------+----------------------------------+
列舉所有user
- keystone user-list
- +----------------------------------+-------+---------+-------------------+
- | id | name | enabled | email |
- +----------------------------------+-------+---------+-------------------+
- | 6c12289f2324405aaa068da611a8fad0 | admin | True | admin@example.com |
- +----------------------------------+-------+---------+-------------------+
創(chuàng)建新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 |
+————-+———————————-+
創(chuàng)建新role
keystone role-create –name new-role
+———-+———————————-+
| Property | Value |
+———-+———————————-+
| id | 002701be4fd344538b93db05b9368b5c |
| name | new-role |
+———-+———————————-+
列舉所有role
keystone role-list
+———————————-+———-+
| id | name |
+———————————-+———-+
| 002701be4fd344538b93db05b9368b5c | new-role |
+———————————-+———-+
查看服務(wù)
keystone service-list
總結(jié)
利用Docker和Keystone結(jié)合,我們可以快速clone出一個服務(wù)的運行環(huán)境,并且在本地開發(fā)和生產(chǎn)環(huán)境快速交付,還有更多Keystone命令等待大家去發(fā)現(xiàn)。
未來我們也將推出Glance、Cinder等容器鏡像,讓OpenStack交付更加輕松和容易!
關(guān)于作者:
陳迪豪,UnitedStack有云存儲組PTL,目前專注于Docker、OpenStack社區(qū)。Docker監(jiān)控管理工具Seagull項目作者,開源電子書《理解Linux進程》作者。