<p>因为你没有经过身份验证,所以你得到了未经授权的401。在</p>
<p>根据本页<a href="https://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html" rel="nofollow noreferrer">salt.netapi.rest_cherrypy</a>
首先,您必须请求登录URL并获得访问令牌,然后您可以通过该令牌访问其他功能。在</p>
<p>如果你需要的话我会解释更多。在</p>
<p>编辑:更多解释:</p>
<p>通过curl请求示例:</p>
<pre><code>curl -si localhost:8000/login \
-c ~/cookies.txt \
-H "Accept: application/json" \
-H "Content-type: application/json" \
-d '{
"username": "saltuser",
"password": "saltuser",
"eauth": "auto"
}'
</code></pre>
<p>通过这个curl命令发送这个请求</p>
^{pr2}$
<p>回应你</p>
<pre><code>HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 206
X-Auth-Token: 6d1b722e
Set-Cookie: session_id=6d1b722e; expires=Sat, 17 Nov 2012 03:23:52 GMT; Path=/
{"return": {
"token": "6d1b722e",
"start": 1363805943.776223,
"expire": 1363849143.776224,
"user": "saltuser",
"eauth": "pam",
"perms": [
"grains.*",
"status.*",
"sys.*",
"test.*"
]
}}
</code></pre>
<p>您可以在其中看到token<strong>“token”:“6d1b722e”</strong></p>
<p>现在你可以发送你的请求包含令牌解释为<strong>认证令牌</strong>。在</p>
<p>编辑2:</p>
<p>请记住,您使用pam进行身份验证,这意味着您的操作系统中必须有相同的用户
编辑3:</p>
<p>在not work中使用这个最小的con作为salt api conf</p>
<pre><code> external_auth:
pam:
saltuser:
- .*
rest_cherrypy:
port: 8000
disable_ssl: True
host: 0.0.0.0
</code></pre>