我是vault的新手,目前正尝试通过自签名证书启用客户端tls身份验证(所有这些都在唯一的CentOS 7节点上)。
当然,首先我跑了:vault auth-enable cert
然后,我创建了一个包含以下内容的policy.hcl
文件:
path "secret/policy/test/foo" {policy="read"}
然后我做了以下事情:
$ vault policy-write test policy.hcl
$ vault write "secret/policy/test/foo" vaule=s3cr3t policy=test
生成客户端证书:
$ openssl genrsa -out client.key 2048
$ openssl req -new -key client.key -out client.csr
$ openssl x509 -req -in client.csr -signkey client.key -out client.crt
最后的行动:
$ vault write auth/cert/certs/test display_name=test policies=test certificate=@/home/vagrant/ssl/client.crt
这一切都在没有任何错误或警告的情况下执行。然后,我编写了一个简单的脚本,在使用TLS进行身份验证后必须只读取一个值:
import os
import hvac
client = hvac.Client(url='https://127.0.0.1:8200', cert=('client.crt', 'client.key'))
print(client.read('secret/policy/test/foo'))
但是当我运行它时,我收到以下错误:
requests.exceptions.SSLError: HTTPSConnectionPool(host='127.0.0.1', port=8200): Max retries exceeded with url: /v1/secret/policy/test/foo (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:579)'),))
服务器日志说:
http: TLS handshake error from 127.0.0.1:33744: remote error: tls: unknown certificate authority
非常感谢任何帮助
修改
要澄清实际问题是什么,我想提一下,当我使用CLI对Vault进行身份验证时:
$ vault auth -method=cert -client-cert=client.crt -client-key=client.key
# returns:
The token below is already saved in the session. You do not
need to "vault auth" again with the token.
token: 8afdb5bd-b6f1-e33e-a391-ced99fa18b5f
token_duration: 2764800
token_policies: [default test]
......似乎工作得很好因为我创建的策略正在附加,我可以从secret/policy/test/foo
读取数据,但Python + HVAC方法不起作用。