我的 ansible playbook 中有以下任务:
- name: Test on localhost
hosts: localhost
gather_facts: false
tasks:
- name: Get vault vaules
uri:
url: "{{vault_address_personal}}/v1/{{vault_path_personal}}/pg"
method: GET
validate_certs: no
headers:
X-Vault-Token: "36f8a4d9-64fd-a2ec-b45a-fd041f7e28df"
register: pg_value
此任务失败并显示:
TASK [Get vault vaules] *******************************************************************************************************************************
fatal: [localhost]: FAILED! => {"cache_control": "no-store", "changed": false, "connection": "close", "content": "{\"errors\":[\"permission denied\"]}\n", "content_length": "33", "content_type": "application/json", "date": "Wed, 27 Mar 2019 15:44:29 GMT", "failed": true, "json": {"errors": ["permission denied"]}, "msg": "Status code was not [200]: HTTP Error 403: Forbidden", "redirected": false, "status": 403, "url": "https://vserv-us.sos.ibm.com:8200/v1/generic/user/xyz/pg"}
然而,当我卷曲时,我得到了正确的价值:
curl --header "X-Vault-Token: 36f8a4d9-64fd-a2ec-b45a-fd041f7e28df" https://vserv-us.sos.ibm.com:8200/v1/generic/user/xyz/pg --insecure
{"request_id":"662fb6f5-5271-0551-de6b-cdf7d873f410","lease_id":"","renewable":false,"lease_duration":2764800,"data":{"password":"p0wn-me"},"wrap_info":null,"warnings":null,"auth":null}
看起来像 ansible 不考虑标题。这里有什么遗漏吗?
我也试过:
"X-Vault-Token": "36f8a4d9-64fd-a2ec-b45a-fd041f7e28df"
我遇到了一些问题,它说标题可能会自动大写。所以也试过
"X-VAULT-TOKEN": "36f8a4d9-64fd-a2ec-b45a-fd041f7e28df"
与卷曲配合得很好。还尝试了邮递员,并注意到在邮递员中自动添加了一个授权标头,并带有值Basic Og==
因此尝试添加该附加标头。但没有任何效果。
也尝试了 hash_vault 但得到了同样的错误:
- name: Return all secrets from a path
hosts: localhost
gather_facts: false
tasks:
- name: Return all secrets from a path
debug:
msg: "{{ lookup('hashi_vault', 'secret=generic/user/xyz/pg token=36f8a4d9-64fd-a2ec-b45a-fd041f7e28df url=https://vserv-us.sos.ibm.com:8200 validate_certs=False')}}"