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 saving private key ansible-vault encrypted #805

Open
agowa opened this issue Oct 3, 2024 · 3 comments
Open

Add saving private key ansible-vault encrypted #805

agowa opened this issue Oct 3, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@agowa
Copy link

agowa commented Oct 3, 2024

SUMMARY

Enable community.crypto.openssl_privatekey to save the private key using ansible-vault encryption.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

community.crypto.openssl_privatekey

ADDITIONAL INFORMATION

My current usage may be a bit unusual but what I was trying to do was create a task within the roll that generates the private key for an internal CA to sign stuff but store that private key within the playbook on the controller. Aka. If a private key does not exist within a specific variable name it'll create one and add an additional yaml file to the playbook that contains said variable with the newly generated private key so that it'll be persistent for future runs but still allow the playbook to be a template for multiple similar projects (It doesn't have to be a yaml file and a variable directly, just an ansible-vault encrypted file/asset would already be enough).

Also being able to have the module store the private key using ansible-vault encryption could be quite useful for a bunch of other usages as well as it is may more secure than just being able to secure it using a passphrase.

@felixfontein felixfontein added the enhancement New feature or request label Oct 3, 2024
@felixfontein
Copy link
Contributor

openssl_privatekey is a module, not an action plugin, so it has no access to Ansible Vault.

There are very few action plugins which support using Ansible Vault, and all I'm aware of only allow to read Vault encrypted stuff. (The only Ansible plugin I'm aware of that encrypts is the ansible.builtin.vault filter: https://docs.ansible.com/ansible/devel/collections/ansible/builtin/vault_filter.html)

To implement what you want to do, you should use the community.crypto.openssl_privatekey_pipe module together with the ansible.builtin.vault filter (to write the key if it was (re-)generated by the community.crypto.openssl_privatekey_pipe module). (You probably should combine the vault filter with the copy or template module to write its result to a file.)

The openssl_privatekey_pipe examples (https://docs.ansible.com/ansible/devel/collections/community/crypto/openssl_privatekey_pipe_module.html#examples) shows how to combine the module with community.sops to (re-)generate a SOPS encrypted key, if necessary. Combining it with Ansible Vault should go similarly. (If you figure out how to combine them you could add another example to the module, I'm sure this will be useful for other users as well.)

@agowa
Copy link
Author

agowa commented Oct 6, 2024

Hmm, that could work. It's a bit more effort to not have it overwritten but should work.

But just a dumb thought, just adding ansible-vault as an optional dependency for this feature wouldn't work? So that the vault encryption isn't done on the controller but on the target (which then may be delegated to e.g. localhost or to a specific CA-VM)?
My main goal is to have at-rest encryption...

@felixfontein
Copy link
Contributor

But just a dumb thought, just adding ansible-vault as an optional dependency for this feature wouldn't work? So that the vault encryption isn't done on the controller but on the target (which then may be delegated to e.g. localhost or to a specific CA-VM)? My main goal is to have at-rest encryption...

On the controller you cannot access the parts of ansible-core that handle vault, and you also don't have access to the vault password used by the controller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants