openstack核心组件——keystone身份认证服务(5)

时间:2019-08-16
本文章向大家介绍openstack核心组件——keystone身份认证服务(5),主要包括openstack核心组件——keystone身份认证服务(5)使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

云计算openstack核心组件——keystone身份认证服务(5)

部署公共环境

ntp openstack mariadb-server rabbitmq-server memcache

 1.wget http://download2.yunwei.edu/shell/yum-repo.sh 下载源

 2.bash yum-repo.sh 三台全部执行脚本 获取源

 3.[root@node1 ~]# cd /etc/yum.repos.d

[root@node1 yum.repos.d]# ls

Centos7-Base-yunwei.repo epel-yunwei.repo old rdo-release-yunwei.repo

[root@node1 yum.repos.d]# 只留下这三种源

 4.yum clean all

5. yum makecache

 如果没有本地源下载 需要下载

 Enable the OpenStack repository

  • On CentOS, the extras repository provides the RPM that enables the OpenStack repository. CentOS includes the extrasrepository by default, so you can simply install the package to enable the OpenStack repository.

# yum install centos-release-openstack-ocata

  • On RHEL, download and install the RDO repository RPM to enable the OpenStack repository.

# yum install https://rdoproject.org/repos/rdo-release.rpm

 如果有直接下载

安装openstack 包

开始部署

 6.yum install python-openstackclient 下载安装客户端

 7. yum install openstack-selinux -y

 systemctl stop firewalld 关闭防火墙

cat /etc/selinux/config 查看状态

[root@node1 ~]# cat /etc/selinux/config

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

# enforcing - SELinux security policy is enforced.

# permissive - SELinux prints warnings instead of enforcing.

# disabled - No SELinux policy is loaded.

SELINUX=disabled

# SELINUXTYPE= can take one of three values:

# targeted - Targeted processes are protected,

# minimum - Modification of targeted policy. Only selected processes are protected.

# mls - Multi Level Security protection.

SELINUXTYPE=targeted

安装数据库 后端登录存储需要数据库

网站用主从架构 企业中云计算用galera 多主架构 只支持innodb引擎 maroadb数据库支持多种引擎 8. yum install mariadb mariadb-server python2-PyMySQL 第一个mariadb是客户端 mariadb-server是数据库服务

 9.cd /etc/my.cnf.d/

[root@node1 my.cnf.d]# ls

auth_gssapi.cnf client.cnf enable_encryption.preset mariadb-server.cnf mysql-clients.cnf tokudb.cnf

10.vim openstack.cnf

输入内容

[mysqld]

bind-address = 192.168.194.7 监听地址(本机地址)

default-storage-engine = innodb 数据库引擎 支持事物 外键

innodb_file_per_table = on 开启表的锁

max_connections = 4096

collation-server = utf8_general_ci

character-set-server = utf8

11.systemctl start mariadb .service 开启

systemctl enable mariadb.service 开机自启

 12.mysql_secure_installation 数据库初始化

Set root password? [Y/n] y 设置密码

New password:

Re-enter new password:

Password updated successfully!

Reloading privilege tables..

... Success!

 By default, a MariaDB installation has an anonymous user, allowing anyone

to log into MariaDB without having to have a user account created for

them. This is intended only for testing, and to make the installation

go a bit smoother. You should remove them before moving into a

production environment.

Remove anonymous users? [Y/n] y 删除匿名用户

... Success!

Normally, root should only be allowed to connect from 'localhost'. This

ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n 是否不允许远程登录 双重否定表示肯定

... skipping.

By default, MariaDB comes with a database named 'test' that anyone can

access. This is also intended only for testing, and should be removed

before moving into a production environment.

Remove test database and access to it? [Y/n] y 删除数据库

- Dropping test database...

... Success!

- Removing privileges on test database...

... Success!

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n] y 重新加载权限

... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MariaDB

installation should now be secure.

Thanks for using MariaDB!

13. mysql -uroot -p123 数据库登录 因为安装了mariadb包

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 9

Server version: 10.1.20-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

MariaDB [(none)]>

14.yum install rabbitmq-server 安装消息队列

分隔开集群 不需要 5672 端口号

我们通过“查询可用 image”这个实际操作让大家对这些概念建立更加感性的认识。User admin 要查看 Project 中的 image

开启消息队列

15 systemctl start rabbitmq-server.service

systemctl status rabbitmq-server.service

 16 创建一个opstack用户

rabbitmqctl add_user openstack 123 创建一个消息队列

17 rabbitmqctl set_permissions openstack ".*" ".*" ".*"

在网页输入192.168.194.7:15672 进入rabbitmq界面

 没有tags权限 设置管理员身份adminstrator 扩展内容

18 rabbitmqctl set_user_tags openstack administrator

 memcache 数据库缓存

19 yum install memcached python-memcached

 20 vim /etc/sysconfig/memcached

PORT="11211"

USER="memcached"

MAXCONN="1024"

CACHESIZE="64"

OPTIONS="-l 127.0.0.1,::1,node1" 写上本地监听的地址

 21 systemctl start memcached.service 开启缓存服务

systemctl status memcached.service

一、Keystone介绍:
      keystone 是OpenStack的组件之一,用于为OpenStack家族中的其它组件成员提供统一的认证服务,包括身份验证、令牌的发放和校验、服务列表、用户权限的定义等等。云环境中所有的服务之间的授权和认证都需要经过 keystone. 因此 keystone 是云平台中第一个即需要安装的服务。
作为 OpenStack 的基础支持服务,Keystone 做下面这几件事情:
  1. 管理用户及其权限
  2. 维护 OpenStack Services 的 Endpoint
  3. Authentication(认证)和 Authorization(鉴权)
学习 Keystone,得理解下面这些概念:
User
User 指代任何使用 OpenStack 的实体,可以是真正的用户,其他系统或者服务。
当 User 请求访问 OpenStack 时,Keystone 会对其进行验证。Horizon 在 Identity->Users 管理 User

admin:openstack平台的超级管理员,负责openstack服务的管理和访问权限

demo: 常规(非管理)任务应该使用无特权的项目和用户,所有要创建 demo 项目和 demo 用户

除了 admin 和 demo,OpenStack 也为 nova、cinder、glance、neutron 服务创建了相应的 User。 admin 也可以管理这些 User。

Credentials
Credentials 是 User 用来证明自己身份的信息,可以是:
1. 用户名/密码
2. Token
3. API Key
4. 其他高级方式
Authentication
Authentication 是 Keystone 验证 User 身份的过程。User 访问 OpenStack 时向 Keystone 提交用户名和密码形式的 Credentials,Keystone 验证通过后会给 User 签发一个 Token 作为后续访问的 Credential。
Token
Token 是由数字和字母组成的字符串,User 成功 Authentication 后 Keystone 生成 Token 并分配给 User。
  1. Token 用做访问 Service 的 Credential
  2. Service 会通过 Keystone 验证 Token 的有效性
  3. Token 的有效期默认是 24 小时
Project
Project 用于将 OpenStack 的资源(计算、存储和网络)进行分组和隔离。
根据 OpenStack 服务的对象不同,Project 可以是一个客户(公有云,也叫租户)、部门或者项目组(私有云)。
这里请注意:
  1. 资源的所有权是属于 Project 的,而不是 User。
  2. 在 OpenStack 的界面和文档中,Tenant / Project / Account 这几个术语是通用的,但长期看会倾向使用 Project
  3. 每个 User(包括 admin)必须挂在 Project 里才能访问该 Project 的资源。 一个User可以属于多个 Project。
  4. admin 相当于 root 用户,具有最高权限
Horizon 在 Identity->Projects 中管理 Project
通过 Manage Members 将 User 添加到 Project
Service
OpenStack 的 Service 包括 Compute (Nova)、Block Storage (Cinder)、Object Storage (Swift)、Image Service (Glance) 、Networking Service (Neutron) 等。每个 Service 都会提供若干个 Endpoint,User 通过 Endpoint 访问资源和执行操作。
Endpoint
Endpoint 是一个网络上可访问的地址,通常是一个 URL。Service 通过 Endpoint 暴露自己的 API。 Keystone 负责管理和维护每个 Service 的 Endpoint。
可以使用下面的命令来查看 Endpoint。
# source devstack/openrc admin admin
# openstack catalog list
Role
安全包含两部分:Authentication(认证)和 Authorization(鉴权)
Authentication 解决的是“你是谁?”的问题
Authorization 解决的是“你能干什么?”的问题
Keystone 借助 Role 实现 Authorization:
  1. Keystone定义Role
  2. 可以为 User 分配一个或多个 Role,Horizon 的菜单为:Identity->Project->ManageMembers
  1. Service 决定每个 Role 能做什么事情 Service 通过各自的 policy.json 文件对 Role 进行访问控制。 下面是 Nova 服务 /etc/nova/policy.json 中的示例:
        
       上面配置的含义是:对于 create、attach_network 和 attach_volume 操作,任何Role的 User 都可以执行; 但只有 admin 这个 Role 的 User 才能执行 forced_host 操作。
    2. OpenStack 默认配置只区分 admin 和非 admin Role。 如果需要对特定的 Role 进行授权,可以修改 policy.json。
        Openstack对User的验证除了身份验证,还需要鉴别 User 对某个Service是否有访问权限。Policy用来定义什么角色对应什么权限。对Keystone来说,Policy其实是一个JSON文件,默认是 /etc/keystone/policy.json 。通过Policy,Keystone实现了对User的权限管理。
    
    3. openstack系统基本角色有两个:
         一个是管理员admin
         一个是租户_member_

二、Keystone基本架构:

•Token: 用来生成和管理token
•Catalog:用来存储和管理service/endpoint
•Identity:用来管理tenant/user/role和验证
•Policy:用来管理访问权限

 

三、通过例子认识Keystone:         

我们通过“查询可用 image”这个实际操作让大家对这些概念建立更加感性的认识。User admin 要查看 Project 中的 image

第 1 步 登录
当点击时,OpenStack 内部发生了哪些事情?请看下面
Token 中包含了 User 的 Role 信息
第 2 步 显示操作界面
请注意,顶部显示 admin 可访问的  Project 为 “admin” 和 “demo”。 其实在此之前发生了一些事情:
同时,admin 可以访问 Intance, Volume, Image 等服务
这是因为 admin 已经从 Keystone 拿到了各 Service 的 Endpoints
第 3 步 显示 image 列表
点击 “Images”,会显示 image 列表
背后发生了这些事:
首先 admin 将请求发送到 Glance 的 Endpoint
  
Glance 向 Keystone 询问 admin 身份是否有效
接下来 Glance 会查看 /etc/glance/policy.json 判断 admin 是否有查看 image 的权限
 
权限判定通过,Glance 将 image 列表发给 admin。
Troubleshoot
OpenStack 排查问题的方法主要是通过日志。
每个 Service 都有自己的日志文件。
Keystone 主要有两个日志: keystone.log 和 keystone_access.log,保存在 /var/log/apache2/ 目录里。
devstack 的 screen 窗口已经帮我们打开了这两个日志。 可以直接查看:
如果需要得到最详细的日志信息,可以在 /etc/keystone/keystone.conf 中打开 debug 选项
在非 devstack 安装中,日志可能在 /var/log/keystone/ 目录里。

四、keystone配置文件:
vim /etc/keystone/keystone.conf
[DEFAULT]
 
[assignment]
 
[auth]
 
[cache]
 
[catalog]
 
[cors]
 
[cors.subdomain]
 
[credential]
 
[database]
connection = mysql+pymysql://keystone:KEYSTONE_DBPASS@controller/keystone
 
[domain_config]
 
[endpoint_filter]
 
[endpoint_policy]
 
[eventlet_server]
 
[federation]
 
[fernet_tokens]
 
[healthcheck]
 
[identity]
 
[identity_mapping]
 
[kvs]
 
[ldap]
 
[matchmaker_redis]
 
[memcache]
 
[oauth1]
 
[oslo_messaging_amqp]
 
[oslo_messaging_kafka]
 
[oslo_messaging_notifications]
 
[oslo_messaging_rabbit]
 
[oslo_messaging_zmq]
 
[oslo_middleware]
 
[oslo_policy]
 
[paste_deploy]
 
[policy]
 
[profiler]
 
[resource]
 
[revoke]
 
[role]
 
[saml]
 
[security_compliance]
 
[shadow_users]
 
[signing]
 
[token]
provider = fernet
 
[tokenless_auth]
 
[trust]

原文地址:https://www.cnblogs.com/it-peng/p/11363296.html