功能
keystone在OpenStack中负责:
管理:用户、租户和权限;
认证:组件相互访问的身份认证;
鉴权:提供 RBAC(Role Based Access Control) 权限体系;
服务注册与发现:提供目录服务,维护 OpenStack Services 的 Endpoint;
概念
user:用户,使用平台的实体,可以是人名、业务系统名称、服务名称;
credentials:凭证,证明是哪个user的信息,可以是password、Token、API Key;
authentication:授权,验证user身份的过程。常见情况:user访问某服务时,向Keystone提交用户和密码形式的Credentials,Keystone验证通过后,会返回给user一个token作为后续访问用的 Credentials;
token:令牌,字符串,用作访问 Service的Credential,可以在keystone配置文件中设置有效时长,默认24小时;
project:项目,引申为租户tenant或账户account ,将IaaS层资源计算、存储、网络进行分组隔离;一个project被被多个user按照不同权限绑定,admin拥有最高权限;
role/policy:角色/策略,对资源访问的权限配置,一般有admin、member、view;
group:组,一组user,绑定角色role,划分权限;
domain:域,多项目/租户模式的实现,用来区分default domain、其他domain,规避某个域的超管用户对其他域干扰;
endpoint:服务端点,基于http请求的 API方法的地址;
openstack endpoint list
+----------------------------------+-----------+--------------+----------------+---------+-----------+---------------------------------------+
| ID | Region | Service Name | Service Type | Enabled | Interface | URL |
+----------------------------------+-----------+--------------+----------------+---------+-----------+---------------------------------------+
| | RegionOne | cinderv3 | volumev3 | True | public | http://ip/volume/v3/$(project_id)s |
| | RegionOne | heat-cfn | cloudformation | True | public | http://ip/heat-api-cfn/v1 |
| | RegionOne | keystone | identity | True | admin | http://ip/identity |
| | RegionOne | placement | placement | True | public | http://ip/placement |
| | RegionOne | keystone | identity | True | public | http://ip/identity |
| | RegionOne | glance | image | True | public | http://ip/image |
| | RegionOne | cinderv2 | volumev2 | True | public | http://ip/volume/v2/$(project_id)s |
| | RegionOne | swift | object-store | True | public | http://ip:8080/v1/AUTH_$(project_id)s |
| | RegionOne | nova | compute | True | public | http://ip/compute/v2.1 |
| | RegionOne | neutron | network | True | public | http://ip:9696/ |
| | RegionOne | heat | orchestration | True | public | http://ip/heat-api/v1/$(project_id)s |
| | RegionOne | swift | object-store | True | admin | http://ip:8080 |
| | RegionOne | nova_legacy | compute_legacy | True | public | http://ip/compute/v2/$(project_id)s |
| | RegionOne | cinder | block-storage | True | public | http://ip/volume/v3/$(project_id)s |
+----------------------------------+-----------+--------------+----------------+---------+-----------+---------------------------------------+
服务目录:多组件多次调用的服务的集合;
openstack service list
+----------------------------------+-------------+----------------+
| ID | Name | Type |
+----------------------------------+-------------+----------------+
| | keystone | identity |
| | cinder | block-storage |
| | nova_legacy | compute_legacy |
| | neutron | network |
| | glance | image |
| | heat | orchestration |
| | cinderv3 | volumev3 |
| | swift | object-store |
| | placement | placement |
| | heat-cfn | cloudformation |
| | cinderv2 | volumev2 |
| | nova | compute |
+----------------------------------+-------------+----------------+
过程举例
以nova组件为例:
1、openstack cli或horizon以密码的形式向keystone获取token;
2、客户端向nova-api发起启动实例的http请求;
3、nova-api向keystone验证token;
4、再向keystone确定所属project的资源配额quota;
5、nova-conductor计算已使用的资源量,允许或拒绝请求;
6、nova-api通过rpc调用nova-scheduler选择适当的compute node;
7、nova-api通过rpc调用运行在compute node的nova-compute,完成虚拟机创建;
常用操作
# 创建服务
openstack service create --name 服务名称 --description "selfservice" 服务名称
# 创建服务端点
openstack endpoint create --region 区域名 myService [public|internal|admin] http://ip:3838
# 创建一个用户
openstack user create --password 密码 用户名
# 更改
openstack user set --password 密码 用户名
# 罗列用户
openstack user list
# 查看用户
openstack user show 用户名
# 将用户关联到项目/租户
openstack role add --user 用户名 --project 项目名称 角色
# 删除
openstack user delete 用户名
策略举例
policy官方参考
默认策略文件为/etc/cinder/policy.yaml,可通过cinder.conf的配置块[oslo_policy]的配置项policy_file自定义策略文件。
# 实现:非admin角色的用户不能创建云硬盘
# 创建policy文件
oslopolicy-sample-generator --namespace cinder --output-file policy.yaml
cp policy.yaml /etc/cinder/policy.yaml
# 创建规则context_is_admin,指定角色admin
vim /etc/cinder/policy.yaml
"context_is_admin": "role:admin"
"volume:create": "rule:context_is_admin"
# 重启服务
systemctl restart xxx@c-api