【发布时间】:2019-05-15 23:59:06
【问题描述】:
我正在尝试访问我的 Ansible playbook 中的一些 Vault kv 机密...
- hosts: localhost
connection: local
tasks:
- name: Retrieve secret/hello using native hashi_vault plugin
debug: msg="{{ lookup('hashi_vault', 'secret=secret/my-secret:foo token={{ vault_token }} url={{ vault_address }} ')}}"
我发现在使用第一版 kv 存储引擎存储 secret/my-secret 的情况下,这可以正常工作。但是,当使用第二版时,我看到以下错误...
fatal: [localhost]: FAILED! => {"msg": "An unhandled exception occurred while running the lookup plugin 'hashi_vault'. Error was a <class 'ansible.errors.AnsibleError'>, original message: The secret secret/my-secret doesn't seem to exist for hashi_vault lookup"}
是我做错了什么,还是 hasi_vault 查找插件不支持第二版 kv 引擎?
干杯!
标记
【问题讨论】:
-
试试
secret=secret/data/my-secret:foo -
有趣。我试过了,现在我得到了一个稍微不同的错误......
fatal: [localhost]: FAILED! => {"msg": "An unhandled exception occurred while running the lookup plugin 'hashi_vault'. Error was a <class 'ansible.errors.AnsibleError'>, original message: The secret secret/data/my-secret does not contain the field 'foo'. for hashi_vault lookup"} -
好的,这似乎可行,但不确定这是否是最好的方法!
--- - hosts: localhost connection: local vars: secret: "{{ lookup('hashi_vault', 'secret=secret/data/my-secret:data') }}" tasks: - name: Retrieve secret/hello using native hashi_vault plugin debug: msg="{{ secret['foo'] }}" -
所以在 KV2 中,API 发生了变化,使得端点现在是
<usually secret>/data/<field>并返回一个 JSON,其中data作为顶级键,data和metadata作为嵌套键。您的 KV 对位于data。然后,与 Vault 的 REST API 的 python 绑定需要您实施的使用更新。在此处查看文档:vaultproject.io/api/secret/kv/kv-v2.html#read-secret-version。我可以在答案中写出来。 -
嘿,你有解决方案 w.r.t kv2 引擎