Skip to content
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

Add Key Vault lookup plugin to collection #88

Closed
jgeorgeson opened this issue Apr 4, 2020 · 24 comments
Closed

Add Key Vault lookup plugin to collection #88

jgeorgeson opened this issue Apr 4, 2020 · 24 comments
Labels
has_pr PR fixes have been made medium_priority Medium priority work in In trying to solve, or in working with contributors

Comments

@jgeorgeson
Copy link

SUMMARY

MS have already developed a lookup plugin for Key Vault

https://github.com/Azure/azure_preview_modules/blob/master/lookup_plugins/azure_keyvault_secret.py

Would be great to add it to the collection.

@Fred-sun
Copy link
Collaborator

Fred-sun commented Apr 9, 2020

@jgeorgeson Thank you for taking the time to report this problem. We will deal with it as soon as possible. Thank you very much!

@Fred-sun
Copy link
Collaborator

@haiyuazhang Can you help to add this plug-in at your leisure? Thank you very much!

@ToniCipriani
Copy link

ToniCipriani commented Apr 23, 2020

Azure/azure_preview_modules#379 (comment)

There is one slight issue with this plugin where it takes a very long timeout trying to authenticate with MSI before it tries to use Service Principal.

@Fred-sun
Copy link
Collaborator

@ToniCipriani Thank you for your interest in ansible. We will clarify this as soon as possible. Thank you very much!

@Fred-sun
Copy link
Collaborator

@jgeorgeson I'm glad you're interested in ansible_collection, can you tell me what you plan to do with this plug-in? Thank you very much!

@ToniCipriani
Copy link

@Fred-sun not who you asked but my current use case is using it to eliminate Ansible Vault and integration with Terraform.

Terraform would provision a VM, generate keys and vault them, I would use Ansible to configure the machines using an Azure dynamic inventory, pulling the keys and credentials in the process for the whole playbook to run. No secret values are stored in the playbook itself this way, only the service principal and resource group name are provided at run time.

@jgeorgeson
Copy link
Author

Similar to @ToniCipriani. We want to use lookup plugin in AWX inventory variables to run multi-platform job templates without configuring machine credentials in the job.

@Fred-sun
Copy link
Collaborator

@ToniCipriani @jgeorgeson Ansible 2.10 has added the azure_rm_keyvaultsecret_info module, which should suit your needs. Thank you very much!

Link: https://github.com/ansible-collections/azure/blob/dev/plugins/modules/azure_rm_keyvaultsecret_info.py

@jgeorgeson
Copy link
Author

Thanks @Fred-sun but it does not suit my use case. I can use a lookup plugin (any interpolation, really) in inventory group/host vars, but I can't call a task module there. I want to store things like this

https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#connecting-to-hosts-behavioral-inventory-parameters

in Keyvault so that my inventory can read them dynamically in a new environment to self-bootstrap.

@ToniCipriani
Copy link

Thanks @Fred-sun but it does not suit my use case. I can use a lookup plugin (any interpolation, really) in inventory group/host vars, but I can't call a task module there. I want to store things like this

https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#connecting-to-hosts-behavioral-inventory-parameters

in Keyvault so that my inventory can read them dynamically in a new environment to self-bootstrap.

Actually I kind of got around this. For my use case I'm pulling the private key and ansible_become_pass from the vault in order to start the playbook. So what I did instead was disable gather_facts, have an "always" task that accesses the Key Vault to pull the secrets, then perform set_fact to set those variables, before starting the actual playbook.

Functionally the module does the same thing, since the lookup syntax doesn't actually execute until task time anyways. But I do agree a lookup plugin would make things a bit cleaner and DRY in group/hostvars, especially when some secrets are reused throughout the playbook.

@ToniCipriani
Copy link

@ToniCipriani @jgeorgeson Ansible 2.10 has added the azure_rm_keyvaultsecret_info module, which should suit your needs. Thank you very much!

Link: https://github.com/ansible-collections/azure/blob/dev/plugins/modules/azure_rm_keyvaultsecret_info.py

I checked again Ansible 2.10 is still in development with no timeline on when it's available. Doesn't really help with my current need.

@Fred-sun
Copy link
Collaborator

@ToniCipriani Contributors have submitted relevant PRs #109, and I will advance the merger. Thank you!

@taasest8
Copy link
Contributor

taasest8 commented May 17, 2020

As mentioned by @Fred-sun i opened a pull request to merge the azure keyvault lookup module to this collection from the azure preview role. #109

Code is based on the lookup plugin and on a PR on the „old“ azure preview module that my colleague @taarpa6 opened but closed in favour of merging it to this collection. Taking this over from him as we both worked on the improvement of the lookup plugin.

Improvements were made to parse the http result when the http endpoint is queried especially when not using an azure managed service identity or not on an azure vm.

@Fred-sun
Copy link
Collaborator

@taasest8 Thank you for your contribution, we will advance the merger as soon as possible. Thank you!

@taasest8
Copy link
Contributor

taasest8 commented Jul 3, 2020

Any news to get this merged or if it needs some kind of adjustments / updates ?
#109

@ToniCipriani
Copy link

@Fred-sun any updates on when this will get merged?

@Fred-sun Fred-sun added has_pr PR fixes have been made medium_priority Medium priority work in In trying to solve, or in working with contributors labels Oct 26, 2020
@jghal
Copy link

jghal commented May 3, 2021

This is still an issue we would like to see resolved.

@Xiuxi-Sun
Copy link

@jghal We are working on it! Thank you very much!

@ToniCipriani
Copy link

I actually got around this and stopped using it. There were problems with using the Key Vault lookup plugin, especially with error handling.

The newer azure.azcollection.azure_rm_keyvaultsecret_info resource as part of the Ansible Collection is a bit more robust, use it via the standard task/output register/set_fact methods.

@jwhite-ac
Copy link

Are there still plans to merge this? Unfortunatley the module is of no use in template files, where we have multiple secrets to lookup and template out to VMs.

@Fred-sun
Copy link
Collaborator

Sorry for the inconvenience. #109 still has some formatting issues to fix, they will be merged when fixed. In addition, before merging, it is recommended that you use the azure_rm_keyvaultsecret_info module to meet your needs. Thank you very much!

@jwhite-ac
Copy link

As I said, that module does not work for our use case. We've decided to modify the existing lookup plugin and maintain it ourselves.

@jwhite-ac
Copy link

I assume that if this issue is now closed that you have no intention of including the lookup plugin in this collection?

@taasest8
Copy link
Contributor

Lookup Plugin was merged in this PR #109

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has_pr PR fixes have been made medium_priority Medium priority work in In trying to solve, or in working with contributors
Projects
None yet
Development

No branches or pull requests

7 participants