3. Keystone(Rocky) - 认证服务

2020-07-19  本文已影响0人  找呀找提莫

3.1 Keystone说明

3.2 Kenstone功能

3.3 名词解释

3.4 部署 Keystone

3.4.1 创建Keystone数据库

create database keystone character;

grant all privileges on keystone.* to 'keystone'@'localhost' identified by 'keystone';
grant all privileges on keystone.* to 'keystone'@'%' identified by 'keystone';

flush privileges;

3.4.2 在初始配置生成一个随机值作为管理员令牌

[root@controller ~]# openssl rand -hex 10;
7b152382d84315c02cf0

3.4.3 安装配置Keystone

yum install openstack-keystone python2-openstackclient http mod_wsgi

vim /etc/keystone/keystone.conf
# 添加管理员令牌
admin_token = 7b152382d84315c02cf0
# 修改数据库配置
[database]
connection = mysql+pymysql://keystone:keystone@controller/keystone
#                             用户      密码
[token]
provider = fernet

3.4.3 初始化keystone数据库

su -s /bin/sh -c "keystone-manage db_sync" keystone

3.4.4 初始化Fernet keys

keystone-manage fernet_setup --keystone-user keystone --keystone-group keystone
keystone-manage credential_setup --keystone-user keystone --keystone-group keystone

在Queen版本前,keystone需要运行在两个不同的端口上,用来运行identify v2 API,除5000端口外,还需要35357上运行一个单独的管理服务;移除v2 API后,keystone只需要一个5000端口就可以运行所有API

keystone-manage bootstrap --bootstrap-password admin \
  --bootstrap-admin-url http://controller:5000/v3/ \
  --bootstrap-internal-url http://controller:5000/v3/ \
  --bootstrap-public-url http://controller:5000/v3/ \
  --bootstrap-region-id RegionOne

3.4.5 配置apache托管keystone

ln -sv /usr/share/keystone/wsgi-keystone.conf /etc/httpd/conf.d/

vim +95 /etc/httpd/conf/httpd.conf
ServerName controller.alec.com:80

systemctl start httpd
systemctl enable httpd

3.4.6 通过设置环境变量来配置管理账户

export OS_USERNAME=admin
export OS_PASSWORD=admin
export OS_PROJECT_NAME=admin
export OS_USER_DOMAIN_NAME=Default
export OS_PROJECT_DOMAIN_NAME=Default
export OS_AUTH_URL=http://controller:5000/v3
export OS_IDENTITY_API_VERSION=3

# 设置环境变量后,会自动生成admin域、项目、用户、角色、服务实体、API端点(怀疑是3.4.4生成的,待验证)

3.4.7 创建域、项目、用户和角色

# 创建 example 域(default域已经存在,这是只是创建域的一个方法)
openstack domain create --description "An Example Domain" example
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | An Example Domain                |
| enabled     | True                             |
| id          | 94f16414c32249b29cbe19dea06009ef |
| name        | example                          |
| tags        | []                               |
+-------------+----------------------------------+

创建一个的service项目,OpenStack的组件会关联到这个项目中

# 在 default 域中创建 service 项目
openstack project create --domain default --description "Service Project" service
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | Service Project                  |
| domain_id   | default                          |
| enabled     | True                             |
| id          | 059e13ceff1f4bfc9b9a0a3466d573bf |
| is_domain   | False                            |
| name        | service                          |
| parent_id   | default                          |
| tags        | []                               |
+-------------+----------------------------------+

创建一个普通项目、用户、角色

# 创建 demo 项目
openstack project create --domain default --description "Demo Project" demo
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | Demo Project                     |
| domain_id   | default                          |
| enabled     | True                             |
| id          | ff5f94d5a8714249a42a7b4f6bc1587b |
| is_domain   | False                            |
| name        | demo                             |
| parent_id   | default                          |
| tags        | []                               |
+-------------+----------------------------------+


# 创建 demo 用户
openstack user create --domain default --password-prompt demo
User Password:demo
Repeat User Password:demo
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | bfda144c255847d3a9209ea282764c3b |
| name                | demo                             |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+

# 创建 user 角色
openstack role create user
+-----------+----------------------------------+
| Field     | Value                            |
+-----------+----------------------------------+
| domain_id | None                             |
| id        | 5eb3696fba5f47f0b2ed1c1c60c9ff5c |
| name      | user                             |
+-----------+----------------------------------+

# 添加 user 角色到 demo 项目和用户
openstack role add --project demo --user demo user

3.5 验证服务

取消 OS_TOKEN OS_URL

unset OS_TOKEN OS_URL

作为 admin 用户,请求认证令牌

openstack --os-auth-url http://controller:35357/v3 \
  --os-project-domain-name default --os-user-domain-name default \
  --os-project-name admin --os-username admin token issue
  Password: admin
+------------+--------------------------------------------------------------------------------
| Field      | Value
+------------+--------------------------------------------------------------------------------
| expires    | 2020-07-17T09:08:29+0000
| id         | gAAAAABfEwS6GJWppKNjn0YDWJunrn_hQJmCCiuvCXt3KVgnVBiQefZ6CqXDozGxA0ChYn1XQ-20rP0Fz6O7sqvI_HnfReWcpgQTbgvo0SsawBR6QmUSlyCKp9yOe7fcNU9m4Dt1OEAQ_hN6WNm_1leHJ-pdPmem29lPtMha-DHiMifzuJKNL8k
| project_id | c6f8d8041d5c4f128c4d6c489156b875
| user_id    | 5d7d7304b8b44434a6e942fe94728c4a

作为demo 用户,请求认证令牌

openstack --os-auth-url http://controller:5000/v3 \
  --os-project-domain-name default --os-user-domain-name default \
  --os-project-name demo --os-username demo token issue
Password: demo
+------------+-------------------------------------------------------------
| Field      | Value
+------------+-------------------------------------------------------------
| expires    | 2020-07-17T09:11:52+0000
| id         | gAAAAABfEwT5BOP7z_jXLp2ZfkPXHBLtxfCJIKKSisboBvnWtF9qll4xb26xlERvXwe3nW7AN2rtpoS93i24KWgwUHDhQsfPxb7NbXEbFHeSsy3rpebJ_FSqb0jerzFWo2TR9f6KQgqNldUl8DbjapK7hMdAChIAPcyB6mcR8SiHugC7ven-ONQ
| project_id | ff5f94d5a8714249a42a7b4f6bc1587b
| user_id    | bfda144c255847d3a9209ea282764c3b

3.6 创建OpenStack 客户端环境脚本

3.6.1 创建脚本

创建admin-openrc

cat <<EOF >> admin-openrc
export OS_PROJECT_DOMAIN_NAME=Default
export OS_USER_DOMAIN_NAME=Default
export OS_PROJECT_NAME=admin
export OS_USERNAME=admin
export OS_PASSWORD=admin
export OS_AUTH_URL=http://controller:5000/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
EOF

创建demo-openrc

cat <<EOF > demo-openrc
export OS_PROJECT_DOMAIN_NAME=Default
export OS_USER_DOMAIN_NAME=Default
export OS_PROJECT_NAME=demo
export OS_USERNAME=demo
export OS_PASSWORD=demo
export OS_AUTH_URL=http://controller:5000/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
EOF

3.6.2 使用脚本

加载admin-openrc文件来身份认证服务的环境变量位置和admin项目和用户证书

source admin-openrc

请求认证令牌

openstack token issue
+------------+--------------------------------------------------------------------------
| Field      | Value
+------------+--------------------------------------------------------------------------
| expires    | 2020-07-17T09:31:14+0000
| id         | gAAAAABfEwVPiOYCR6nRZUPBGDMozhzg9UoLCy4mXOY-ww9CpWSK7Wi8Pw3mrFxhogh9zupK4pa4aERerFsYAq6-P3qxvJhROz1D6RQzWmNOCJPWe6BAe_XYW1oEUN-Q97veTqNetY0kH0UlHCRHutmVYZPW6Lb3n0PNSEtCPUgi5g8iAIF5vJY
| project_id | c6f8d8041d5c4f128c4d6c489156b875
| user_id    | 5d7d7304b8b44434a6e942fe94728c4a
上一篇下一篇

猜你喜欢

热点阅读