-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hashi_vault - environment variable guidelines #10
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
- Adds `ANSIBLE_HASHI_VAULT_ADDR` env - Moves `VAULT_ADDR` env to `LOW_PRECEDENCE_ENV_VAR_OPTIONS` - Resolves ansible-collections#10
Should not the support of environment variables starting with
|
Hi @pilou- , thanks for commenting. I think the issue with relying on underlying defaults, especially for options we require, is that it makes for an unclear or inconsistent user experience on the Ansible side. As it relates to I found in using the plugin that when my auth method failed, the failure didn't stop it from operating because I had a token in a place that In my opinion, the defaults in And so even though we are duplicating some functionality by processing it within Ansible, the purpose of this is to provide a consistent experience, especially within a specific release. This isn't always cut and dry: for example when the Your last example, is always an option for anyone regardless of what we do or don't process as far as env vars go. Env vars solve some of that. I'll be looking to add Unlike modules (tasks), we don't have as many ways to set these things for lookups. Those things aside, I would like to know more about your position. Does the presence of these env vars cause issues for your use cases? |
About #13 the unix user used by the lookup tests should not be the user executing the vault service.
The
No. |
We're using AWX, and trying to find the best path forward to provide the AppRole credentials to this lookup plugin in an AWX context. While the We would prefer using env variables over extra_vars as we then don't need to provide the authentication parameters in calls to the lookup plugin.
vs
|
@h3m5k perfect, thanks! |
SUMMARY
The
hashi_vault
lookup takes several parameters via environment variables, and recently, some via INI (ansible.cfg
) as well.Most of the original vars were intended to re-use vars that are commonly used in the vault CLI., like
VAULT_ADDR
andVAULT_TOKEN
.Along the way some newer ones have been added that aren't related to the vault CLI but are strictly for the plugin, but also adopted the
VAULT_
prefix, and some others usedANSIBLE_VAULT_
as their prefix.An additional consideration is that in Ansible, environment variables have higher precedence (are preferred) over INI values. We can think of this in terms of specificity; the INI value is defined "ansible-wide" (for your specific implementation), while the env var is defined per invocation so it should be considered more specific, especially given that the env vars defined for plugin parameters are specific to that Ansible plugin (usually denoted with the
ANSIBLE_
prefix) and so have no use outside of that context.The precedence issue becomes less clear when we take values that have meaning outside of ansible, like the
VAULT_
vars used in the vault CLI.I believe we should consider then that an env var with meaning outside of Ansible has a lower precedence (is less preferred) than an INI value defined in
ansible.cfg
, as in the context of Ansible, an INI value is a more specific value.Additional background on the
ANSIBLE_
prefix:PROPOSAL
This proposal aims to provide guidelines on how we name environment variables, and how we handle their precedence.
Ansible-only vars
This applies to a parameter to the plugin that will not inherit any existing vault CLI env var.
ANSIBLE_HASHI_VAULT_
. This name is on the long side, however it keeps to the pattern of starting withANSIBLE_
. Also considered (and even used before this proposal) wasANSIBLE_VAULT_
however this may cause confusion with Ansible Vault (unrelated to this plugin).env:
key in the plugin's argspec, so that the standard plugin loader can take care of it.Even if there is no specific existing
VAULT_
env var, we don't know whether one will be introduced in the future, and so don't want to use these names.Variables used outside of Ansible
This applies to env vars that have a meaning outside of Ansible, but whose value we want to use. Examples include the vault CLI env vars, but also the
$HOME
variable as used for a default for thetoken_path
parameter.ANSIBLE_HASHI_VAULT_
var (following guidelines above to add it to the argspec) so that the value can be overridden for specific Ansible invocations, overriding both the non-Ansible var and INI value.RELATED ISSUES & PRs
See this project: https://github.com/ansible-collections/community.hashi_vault/projects/1
Not all will be listed here, but want to point some specific examples.
lookup_hashi_vault.token_path
in config file being overridden by env HOME community.general#373 / hashi_vault - Change token_path env var loading precedence community.general#902 -- here the issue of specifying$HOME
in the argspec was revealed to make the INI value practically unusable, since$HOME
is basically always defined already. The solution was to load its value in code only when the value wasn't populated by any other method. In this PR I also added Ansible-specific env vars fortoken_path
andtoken_file
, but used aVAULT_
prefix which I now realize was an anti-pattern (I expect to introduce a PR to correct that).VAULT_ADDR
is probably the most common way of setting the address for a vault server, it becomes more difficult to use an INI value to enforce a specific server's usage in Ansible, without overriding the env var on every invocation. I propose a new Ansible-specific var and to loadVAULT_ADDR
in code as the least preferred source of the value.COMPONENT NAME
hashi_vault.py
The text was updated successfully, but these errors were encountered: