Replies: 1 comment
-
Hi @1ovsss , welcome! This is similar/related to an older request related to caching auth: In particular this explanation about using Vault Agent with auto-auth: Why renewal is difficultSince the code for each lookup and module executes independently, each invocation has to somehow discover or know that a token needs to be renewed before it could make the extra call. Alternatively, we can ask for forgiveness by first trying to use the token and then attempting renewal if it ends up invalid, but we don't know whether the token is renewable when we try to do that. If we try to discover first, like looking up the token, then we do an extra, probably unnecessary roundtrip to the server on every invocation just to see if we should renew or not. Additionally, some tokens do not have the ability to lookup information about themselves so that method won't work on those at all. Some of this can be mitigated with options to control behavior, which unfortunately also bloats the number of options, even more than it already is. If we had extra metadata passed in other than just the token itself, like when it was issued, what the TTL is, etc., it could help, but there's no way to pass it in now, and it means either changing the way So, it is possible that it could be achievable, but there are a lot of thorny issues around it, so I don't have much in the way of plans for it right now. Vault Agent is designed specifically to handle renewals, so it works well running alongside Ansible with this collection. More workaroundsAnother option might be to intersperse your tasks with calls to - name: renew
run_once: true # if you use different tokens per host, this should be false; true prevents unnecessary renewals against hosts in parallel
ansible.builtin.set_fact:
ansible_hashi_vault_token: "{{ lookup('community.hashi_vault.vault_write', 'auth/token/renew-self').auth.client_token }}" You could repeat that task wherever, you just have to be careful about variable precedence. It would be nicer if we could set it once in a vars:
ansible_hashi_vault_token: "{{ lookup('community.hashi_vault.vault_write', 'auth/token/renew-self').auth.client_token }}"
tasks:
- name: message
block:
- name: sec1
debug:
msg: "{{ lookup('hashi_vault', 'secret=some/secret/path:sec1') }}"
- name: sleep
command: sleep 800
- name: sec2
debug:
msg: "{{ lookup('hashi_vault', 'secret=some/secret/path:sec2') }}"
- name: sleep
command: sleep 200
- name: sec3
debug:
msg: "{{ lookup('hashi_vault', 'secret=some/secret/path:sec3') }}"
tags: [ sleep-vlt ] (does not work because the lookup is never executed) If you're willing to modify every task, you can force the templating by adding the token explicitly: vars:
my_token: "{{ lookup('community.hashi_vault.vault_write', 'auth/token/renew-self').auth.client_token }}"
tasks:
- name: message
block:
- name: sec1
debug:
msg: "{{ lookup('hashi_vault', 'secret=some/secret/path:sec1', token=my_token) }}"
- name: sleep
command: sleep 800
- name: sec2
debug:
msg: "{{ lookup('hashi_vault', 'secret=some/secret/path:sec2', token=my_token) }}"
- name: sleep
command: sleep 200
- name: sec3
debug:
msg: "{{ lookup('hashi_vault', 'secret=some/secret/path:sec3', token=my_token) }}"
tags: [ sleep-vlt ] |
Beta Was this translation helpful? Give feedback.
-
SUMMARY
It would be nice if hashi_vault will auto renew token during ansible execution uses token with configured token_ttl and token_max_ttl.
ISSUE TYPE
COMPONENT NAME
lookup
ADDITIONAL INFORMATION
let's say i have following vault configuration:
i get token like this:
This token has access to
/sys/token/*
so it can renew itself (i checked with curl) and from output above i assume"renewable": true
also makes it possible.but tasks below:
where 800+200 > 900, gives me:
Beta Was this translation helpful? Give feedback.
All reactions