Chapter 3 OpenStack认证服务(Identity service)
3.1 认证服务的概念
OpenStack认证服务主要提供以下两种功能:
跟踪用户及其权限
通过API端点(endpoint)提供一组可用的服务
在安装认证服务后,需要为OpenStack其他服务进行注册,这样认证服务就能追踪哪些OpenStack服务已安装以及在网络中所处的位置。
需要了解一下OpenStack认证服务以下概念:
用户:任何使用OpenStack云服务的用户、系统、服务的数字化表示。
证书(credential):确保用户身份的数据。例如用户名和密码的组合、用户名和API键(key)的组合等
授权(authentication):确认用户身份的过程
令牌(token):数字-文字文本串,用于访问OpenStack API和资源
租户(tenant):用于定义组或隔离资源的容器
服务(service):OpenStack各个服务名称
终端(endpoint):访问某个服务的URL地址
角色(role):定义用户权限、可执行的操作
Keystone客户端(client):OpenStack认证API的命令行接口
下图展示了OpenStack认证服务的处理流程:
3.2 安装配置OpenStack认证服务
3.2.1 配置预先环境
在安装配置OpenStack认证服务之前,需要创建相应的数据库和一个管理员令牌(token):
[root@controller ~]# mysql -uroot -piforgot
MariaDB [(none)]> CREATE DATABASE keystone;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost'
IDENTIFIED BY 'keystonepw';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%'
IDENTIFIED BY 'keystonepw';
MariaDB [(none)]> flush privileges;
[root@controller ~]# openssl rand -hex 10
c63cfc6c7e303d4515e6
3.2.2 安装配置OpenStack认证服务组件
1. 安装相关软件包:
[root@controller ~]# yum -y install openstack-keystone httpd mod_wsgi python-openstackclient memcached python-memcached
2. 启动Memcached服务并设置为开机自启:
[root@controller ~]# systemctl start memcached
[root@controller ~]# systemctl enable memcached
3. 编辑/etc/keystone/keystone.conf文件:
[root@controller ~]# cp /etc/keystone/keystone.conf{,.bak}
[root@controller ~]# > /etc/keystone/keystone.conf
[root@controller ~]# vi /etc/keystone/keystone.conf
[DEFAULT]
admin_token = c63cfc6c7e303d4515e6
verbose = True
[database]
connection = mysql://keystone:keystonepw@controller/keystone
[memcache]
servers = localhost:11211
[token]
provider = keystone.token.providers.uuid.Provider
driver = keystone.token.persistence.backends.memcache.Token
[revoke]
driver = keystone.contrib.revoke.backends.sql.Revoke
4. 填充认证服务数据库:
[root@controller ~]# su -s /bin/sh -c "keystone-manage db_sync" keystone
3.2.3 配置Apache HTTP服务
1. 修改/etc/httpd/conf/httpd.conf文件:
[root@controller ~]# vi /etc/httpd/conf/httpd.conf
ServerName controller
2. 创建/etc/httpd/conf.d/wsgi-keystone.conf文件并添加以下内容:
[root@controller ~]# vi /etc/httpd/conf.d/wsgi-keystone.conf
Listen 5000
Listen 35357
<VirtualHost *:5000>
WSGIDaemonProcess keystone-public processes=5 threads=1 user=keystone group=keystone display-name=%{GROUP}
WSGIProcessGroup keystone-public
WSGIScriptAlias / /var/www/cgi-bin/keystone/main
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
LogLevel info
ErrorLogFormat "%{cu}t %M"
ErrorLog /var/log/httpd/keystone-error.log
CustomLog /var/log/httpd/keystone-access.log combined
</VirtualHost>
<VirtualHost *:35357>
WSGIDaemonProcess keystone-admin processes=5 threads=1 user=keystone group=keystone display-name=%{GROUP}
WSGIProcessGroup keystone-admin
WSGIScriptAlias / /var/www/cgi-bin/keystone/admin
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
LogLevel info
ErrorLogFormat "%{cu}t %M"
ErrorLog /var/log/httpd/keystone-error.log
CustomLog /var/log/httpd/keystone-access.log combined
</VirtualHost>
3. 创建WSGI组件目录结构并导入相关内容,然后修改目录的属性和权限:
[root@controller ~]# mkdir -p /var/www/cgi-bin/keystone
[root@controller ~]# curl http://git.openstack.org/cgit/openstack/keystone/plain/httpd/keystone.py?h=stable/kilo
| tee /var/www/cgi-bin/keystone/main /var/www/cgi-bin/keystone/admin
[root@controller ~]# chown -R keystone:keystone /var/www/cgi-bin/keystone
[root@controller ~]# chmod 755 /var/www/cgi-bin/keystone/*
4. 启动httpd服务并设置为开机自启:
[root@controller ~]# systemctl restart httpd
[root@controller ~]# systemctl enable httpd
3.3 创建服务实体(service entity)和API终端
OpenStack环境中各个服务都需要一个服务实体以及多个API终端。
3.3.1 配置预先环境
1. 配置认证令牌:
[root@controller ~]# export OS_TOKEN=c63cfc6c7e303d4515e6
2. 配置终端URL:
[root@controller ~]# export OS_URL=http://controller:35357/v2.0
3.3.2 创建认证服务所需的服务实体以及API终端
[root@controller ~]# openstack service create
--name keystone --description "OpenStack Identity" identity
[root@controller ~]# openstack endpoint create
--publicurl http://controller:5000/v2.0
--internalurl http://controller:5000/v2.0
--adminurl http://controller:35357/v2.0
--region RegionOne
identity
3.4 创建项目名、用户以及角色
这里只创建与管理员相关的信息:
[root@controller ~]# openstack project create --description "Admin Project" admin
[root@controller ~]# openstack user create --password adminpw admin
[root@controller ~]# openstack role create admin
[root@controller ~]# openstack role add --project admin --user admin admin
[root@controller ~]# openstack project create --description "Service Project" service
[root@controller ~]# unset OS_TOKEN OS_URL
3.5 验证操作
这里不作介绍,请查看http://docs.openstack.org/kilo/install-guide/install/yum/content/keystone-verify.html,注意,整个实验环境不会用到demo项目和用户。
3.6 创建OpenStack客户端环境脚本
创建admin项目和用户所需要的客户端环境脚本:
[root@controller ~]# vi admin-openrc.sh
export OS_PROJECT_DOMAIN_ID=default
export OS_USER_DOMAIN_ID=default
export OS_PROJECT_NAME=admin
export OS_TENANT_NAME=admin
export OS_USERNAME=admin
export OS_PASSWORD=adminpw
export OS_AUTH_URL=http://controller:35357/v3
export OS_IMAGE_API_VERSION=2
注意,最后导入的环境变量表示镜像服务客户端使用API版本2.0。官方文档将这一变量在镜像服务章节加入的,这里提前介绍。