saltstack獲取token時報錯401

最近在用 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"

相關文章
相關標籤/搜索