最近在用 saltstack 获取 token 的时候老是出现 401 认证失败,百度谷歌查了不少资料都没能解决,嗯,此次基本上该出的错都出来了,此次也怪本身没太仔细,加上最近事情较多,看到报错的时候就有些心态爆炸,可是这一步不走通又无法完成后面的内容,放置了一天后,今早上过来又从新看到 saltstack 在 github 上的一篇 issue,以后成功获取,看到结果的时候仍是有些小激动的,遂赶忙记录下来。python
1、环境配置mysql
一、api.conf git
[root@V1 salt]# cat /etc/salt/master.d/api.conf rest_cherrypy: port: 8000 disable_ssl: True
2. eauth.confgithub
[root@V1 salt]# cat /etc/salt/master.d/eauth.conf external_auth: pam: saltapi: - .* - '@wheel' - '@runner'
三、salt-api --versionssql
[root@V1 salt]# salt-api --versions Salt Version: Salt: 2018.3.2 Dependency Versions: cffi: 1.11.5 cherrypy: 3.6.0 dateutil: Not Installed docker-py: Not Installed gitdb: Not Installed gitpython: Not Installed ioflo: Not Installed Jinja2: 2.9.6 libgit2: Not Installed libnacl: Not Installed M2Crypto: 0.21.1 Mako: Not Installed msgpack-pure: Not Installed msgpack-python: 0.5.1 mysql-python: Not Installed pycparser: 2.18 pycrypto: 2.6.1 pycryptodome: Not Installed pygit2: Not Installed Python: 2.7.5 (default, Apr 11 2018, 07:36:10) python-gnupg: Not Installed PyYAML: 3.11 PyZMQ: 14.3.1 RAET: Not Installed smmap: Not Installed timelib: Not Installed Tornado: 4.2.1 ZMQ: 3.2.5 System Versions: dist: centos 7.4.1708 Core locale: UTF-8 machine: x86_64 release: 3.10.0-693.21.1.el7.x86_64 system: Linux version: CentOS Linux 7.4.1708 Core
嗯,排错的过程当中我把 salt 版本也给升级了一下,不得不说官网的安装升级操做真的很是友好,附上连接以下docker
a. BOOTSTRAP - MULTI-PLATFORMshell
Salt Bootstrap 是一个 shell 脚本,可检测目标平台并选择最佳安装方法(取自谷歌翻译 . PS认真脸)json
b. 安装最新版本centos
安装最新版本。 即便是新的主要版本,更新也会安装最新版本。api
此种方式提供了三种版本的安装,分别为 REDHAT / CENTOS 7 PY二、REDHAT / CENTOS 7 PY三、REDHAT / CENTOS 6 PY2,我两种方式都试了下,真的敲方便。
细节很少说,直接上思路,多亏了那位老哥的思路排除401,干看着知道是认证失败,而后又不知道从哪验证心里仍是有些难受的。
[root@salt ~]# cat /etc/salt/master # 查看 master 主配置文件 external_auth: pam: salt: - .* - '@wheel' # to allow access to all wheel modules - '@runner' # to allow access to all runner modules - '@jobs' # to allow access to the jobs runner and/or wheel module [root@salt ~]# systemctl start salt-master salt-minion # 重启 master 和 minion [root@salt ~]# useradd -m salt # 添加帐户 [root@salt ~]# echo testpass | passwd --stdin salt # 给帐户添加一个密码 Changing password for user salt. passwd: all authentication tokens updated successfully. [root@salt ~]# salt-key -Ay # 更新未接受的 keys The following keys are going to be accepted: Unaccepted Keys: salt Key for minion salt accepted. [root@salt ~]# sleep 10 # 等待 10 s [root@salt ~]# salt -a pam --username=salt --password=testpass \* test.ping # 尝试使用pam对minion进行验证 salt: True
当我把依照上述步骤把验证文件放置到 master 主配置文件以后,重启 master 服务(试错过程好几回master、minion 和 api 都有起不来的状况,安装了一些包(如 PyZMQ 等),更新了一下内容(如 pip install CherryPy==3.6.0 等),后面终于调回了报 401,尴尬 ),再用 postman 调用获取token的接口就成功了。
[root@V1 salt]# curl -k http://127.0.0.1:8000/login -H "Accept: application/json" -d username='saltapi' -d password='saltapi' -d eauth='pam' {"return": [{"perms": [".*", "@wheel", "@runner"], "start": 1530760488.001925, "token": "4235157b6841803df754ec2b554e002c0fcb5592", "expire": 1530803688.001926, "user": "saltapi", "eauth": "pam"}]}
后来寻思,若是只是把配置加进了主配置文件就能够了的话,说明在主配置文件的 default_include 应该是没有生效的,没成功以前的配置是这样的
# Per default, the master will automatically include all config files # from master.d/*.conf (master.d is a directory in the same directory # as the main master config file). default_include : master.d/*.conf
在重试的时候加了当前目录
default_include : ./master.d/*.conf
而后 OK 了。
在成功获取到 token 后,我又把配置文件改为了原来的,重启了各项服务,,,尴尬的是并没能重现问题。。。重启了 minion 都没能刷新 key 。。。
大体就是这样,排错的过程当中多找找资料,多尝试,最好看官方的 doc 和 issue ,必定要官方(血泪史)。
拿到 token 的我终于能够进行下一步了。
1. salt-api is not working. "Authentication failure of type "eauth" occurred"