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

ansible inline vault #13287

Closed
h0nIg opened this issue Nov 24, 2015 · 18 comments
Closed

ansible inline vault #13287

h0nIg opened this issue Nov 24, 2015 · 18 comments
Assignees
Labels
affects_2.2 This issue/PR affects Ansible v2.2 affects_2.3 This issue/PR affects Ansible v2.3 feature This issue/PR relates to a feature request.

Comments

@h0nIg
Copy link
Contributor

h0nIg commented Nov 24, 2015

Sometimes you want to define a complex variable dictionary and do not want to create a separate vault file for passwords. It would be cool for history purpose to use a plain yml file for variable definition and inline vault variable content like the following. This feature is described by @jpmens on http://jpmens.net/2014/02/22/my-thoughts-on-ansible-s-vault/

nameserver: 10.0.0.1
admin: Jane Jolie
dbpassword: @vault@"AHchx0a+G8mejs84tGxCNKxMFP7tM7Y7kl"
webservertype: nginx
@bcoca bcoca closed this as completed Nov 24, 2015
@h0nIg
Copy link
Contributor Author

h0nIg commented Nov 24, 2015

this is not a duplicate, since the other guy wants to get this implemented by filters and my intention is that this is handled by the ansible yaml parser itself, please reopen!

@bcoca bcoca reopened this Nov 24, 2015
@bcoca
Copy link
Member

bcoca commented Nov 24, 2015

i doubt that will happen as the performance penalty of examining every possible value for vault content will slow down Ansible considerably.

@h0nIg
Copy link
Contributor Author

h0nIg commented Nov 24, 2015

therefore the initial idea was to scan only the first letters and check for a special content like @vault@

@bcoca
Copy link
Member

bcoca commented Nov 24, 2015

yes, that is what will be prohibitive for most users, only those with tiny inventories and few variables would not notice a huge delay.

We have been doing a lot of performance optimization prior to the 2.0 release, most speedups came from avoiding copying and examining the variables as much as we did.

@h0nIg
Copy link
Contributor Author

h0nIg commented Nov 24, 2015

hmm ok.

but to check this statement: do you really think another loop on VariableManager.get_vars for replacing variable content is expensive too? (in comparision to copying on combine_vars). just scrolled the source code and it seems that it would work

@bcoca
Copy link
Member

bcoca commented Nov 24, 2015

try it out, but look at the commit history and you'll see we removed lots of code that scanned and/or copied the variables. What you see now should be the minimal needed for ansible's functionality and it is still slower than what we would want when large inventories are invovled

@bcoca
Copy link
Member

bcoca commented Nov 24, 2015

@h0nIg i do think your idea makes for a better user interface, though no need to add @vault@ as vault already puts in a specific recognizable header.

If you can implement w/o it impacting performance too much, go ahead, i suspect it will be hard to do but will be very happy if you prove me wrong.

@bcoca
Copy link
Member

bcoca commented Nov 25, 2015

i've been thinking about this more, a much more efficient way to do this would be to use a YAML type handler instead of parsing the values.

key: !vault vaultedvalue

would just require that we create a function that handles vaulted strings and register it with the module parser as the one to handle the !vault type.

@h0nIg
Copy link
Contributor Author

h0nIg commented Nov 26, 2015

this seems to be pretty easy, wrote example implementation (not tested):

h0nIg@e680f50

@marcinhlybin
Copy link

I wrote ansible filter that does exactly what you want:
https://github.com/ahes/ansible-filter-plugins/blob/master/vault.py

Have fun :)

@h0nIg
Copy link
Contributor Author

h0nIg commented Apr 6, 2016

@ahes i do not want to include a separate encryption library, i want to use it with ansible capabilities

@alikins
Copy link
Contributor

alikins commented Aug 9, 2016

http://jpmens.net/2014/02/22/my-thoughts-on-ansible-s-vault/ describes something that decrypts to a string.

Would an inline vault need to support decrypting to a more complex object (map, list, etc)?

If a inline vault needed additional info (like an identifier for which key to use), would it be acceptable if that was in a wrapper mapping? Or 'args' to a !vault object?

@h0nIg
Copy link
Contributor Author

h0nIg commented Aug 9, 2016

@alikins

the first one is the intended one.

inline vault should not need to decrypt to a complex object, but it should support to decrypt to a yaml multiline string. the intention is to hide the parts that should be secure only

what do you mean by "wrapper mapping"? i do not have any preference at all

@alikins
Copy link
Contributor

alikins commented Aug 9, 2016

what do you mean by "wrapper mapping"? i do not have any preference at all

Not a particular thing, just a vague idea that the key id may need to be defined outside of the vault blob. One thought was something like a map with the (map) keys being 'key_id' and 'vault_blob', but I didn't really think that through ;->

Current version of my branch should be fine with multiline strings.

@alikins
Copy link
Contributor

alikins commented Aug 9, 2016

One advantage of keeping the decrypted value simple and deserializing to something string like is it makes it easier to wait until the last possible moment to decrypt (as opposed to attempting to decrypt while parsing). That could potentially be as late as remote node module execution[1]...

[1] assuming shared secrets or some pki support in ansible-vault...

@alikins
Copy link
Contributor

alikins commented Aug 22, 2016

@h0nIg
Take a look at #16274

That is an implementation of vault encrypted yaml variables (originally based on your sample implementation)

@ansibot ansibot added the affects_2.2 This issue/PR affects Ansible v2.2 label Sep 8, 2016
@ansibot ansibot added the affects_2.3 This issue/PR affects Ansible v2.3 label Dec 13, 2016
@gebi
Copy link

gebi commented Feb 1, 2017

Just as a note becaue i stumbled over this PR.
Speed would not be a problem if the wrong usage of PBKDF2 would be fixed in ansible vault (#20933).
The reason being, PBKDF2 should only be done ONCE per ansible startup to derive the possible low entropy user password into acceptable key material and not once per encrypted content.
The key derivation function done per content could be MUCH faster (eg. some simple HMAC with matching output length or PBKDF2 with only a single round instead of 10000).

the linked bug report is really about having a method to disable PBKDF2 with 10000 rounds for key material with already known high entropy and is no exact match to this discussion, but also discusses the principle problem in ansible vault.

@bcoca
Copy link
Member

bcoca commented Mar 17, 2017

closing as implemented in #16274, released in 2.3 usable as !vault example i have above

@bcoca bcoca closed this as completed Mar 17, 2017
@ansibot ansibot added feature This issue/PR relates to a feature request. and removed feature_idea labels Mar 2, 2018
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.2 This issue/PR affects Ansible v2.2 affects_2.3 This issue/PR affects Ansible v2.3 feature This issue/PR relates to a feature request.
Projects
None yet
Development

No branches or pull requests

6 participants