-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add dest option to systemd_creds_encrypt #10549
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
base: main
Are you sure you want to change the base?
Conversation
b686724 to
154a588
Compare
felixfontein
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution!
This parameter changes the behavior of the module quite a lot: before the module simply encrypted a secret and returned it. It was up to the user to decide whether the encryption needs to be done, and there is no idempotency check.
With a dest parameter, the common expectation for an Ansible module is that the module performs an idempotency check. This is not done by the module right now. Also check mode is not respected: the destination file is always written, even in check mode.
This likely needs some more changes to the module and to the documentation.
changelogs/fragments/10549-systemd-creds-encrypt-dest-option-added.yml
Outdated
Show resolved
Hide resolved
8f2b059 to
6d85d71
Compare
This comment was marked as outdated.
This comment was marked as outdated.
a4cc451 to
4801bc1
Compare
4801bc1 to
8e3fa98
Compare
|
The last commit is implemented wrong, I'll be redoing it. I'm currently blocked on this bug in Fedora — I can't verify whether |
russoz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mks-h
Thanks for your contribution! I second @felixfontein concerns about idempotency, but also adding a couple of comments here.
tests/integration/targets/systemd_creds_encrypt/tasks/main.yaml
Outdated
Show resolved
Hide resolved
| if name is not None: | ||
| encrypt_cmd.append("--name=" + name) | ||
| else: | ||
| elif not dest: | ||
| encrypt_cmd.append("--name=") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be interesting to add one (or more) testcase that expose what happens when name="".
| that: | ||
| - "encrypted_dest_again.changed" | ||
| fail_msg: "The task didn't change, but should have" | ||
| success_msg: "The task changed, as it should have" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps add an decryption test/options as well? That's https://github.com/ansible-collections/community.general/blob/main/plugins/modules/systemd_creds_decrypt.py on the other hand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8e3fa98 to
2f308b2
Compare
russoz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mks-h thanks for your continued work on this.
Left another couple of comments, and @konstruktoid also left comments in the test, but I must confess I did not delve into those. If you could be as kind as to take a look :-)
Other than these minor things, it is looking good to me.
| When using the O(dest) option, you can set this to an empty | ||
| string ("") to prevent C(systemd-creds encrypt) from using | ||
| filename from O(dest) as the credential name. Conversely, | ||
| leave out the O(name) option to let C(systemd-creds encrypt) | ||
| use the filename from O(dest) as the credential name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this note might be better placed in dest below - both cases described required that dest is set.
Also, maybe a more affirmative wording might help. Something like (inserted be low in dest's description):
- When this is set and O(name=""), then the credential_name is XXXXX (not clear to me the right answer here)
- When this is set and O(name) is not passed, then credential name will take the value of O(dest).
- When this is set and O(name) is also set with a non-empty name, then credential name will take the value of O(name) (???? will it???)Or similar - take this with a pinch of salt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think?
2f308b2 to
74e2aa1
Compare
|
The only way I can prove idempotence is to create a new secret each time, and see if the resulting file differs from the existing one. This should result in the files being the same so long as the "timestamp" is explicitly provided. If it isn't, each encryption will result in a different file, since the default is current time. |
|
How about decrypting the encrypted file and comparing its contents with the original file? In any case, I'm wondering whether this should better be a new module (systemd_creds_encrypt_file) instead of a new part of the systemd_creds_encrypt module, since the new functionality behaves quite different from the existing. |
This only verifies the contents, not the attributes. There's no way to read the embedded attributes from a secret. Plus, I'd say it is safer to not decrypt sensitive data — the principle of least privilege, in a way.
The current functionality doesn't change, it only extends to work with more options of the original command. |
There is a very fundamental change: before the module was doing an action. Now it is managing a file. That's quite different. |
|
Or it can still just do an action, if you don't use the Either way, I'm afraid I'm out of ideas on how to verify that the existing secret was created with the same parameters. The credentials may contain salt, because their hashes are different each time you create one — even if you specify all the same parameters explicitly. |
|
Please note that this PR now has a conflict since we reformatted all code in the collection (see #10999). |
SUMMARY
Add support for specifying the output file in
systemd_creds_encrypt, since it is the only way to create an encrypted systemd credential stored in a file for use withLoadCredentialEncryptedoption in systemd service files. Writing the regular output ofsystemd_creds_encryptinto a file using theansible.builtin.copymodule does not work, since the output is different to whatsystemd-credswrites to the file.Adds the
destoption to control the "output" argument of the underlying "systemd-creds" command.ISSUE TYPE
COMPONENT NAME
systemd_creds_encrypt
ADDITIONAL INFORMATION