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

passwordstore: Support subkey creation and update #8952

Merged
merged 1 commit into from
Oct 7, 2024

Conversation

mluzarreta
Copy link
Contributor

SUMMARY

passwordstore lookup - Add the ability to create and update subkeys in password files.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

passwordstore lookup

ADDITIONAL INFORMATION

Here some command lines to illustrate the feature:

# Create a new 'foo' subkey, in an new password store file (in this case, main password is empty)
❯ ansible -m debug -i localhost, -a "msg={{ lookup('community.general.passwordstore', 'example/test', create=true, subkey='foo') }}" localhost
localhost | SUCCESS => {
    "msg": "u6V31gj3d0i3lLbO"
}
# Replace the 'foo' subkey and keep a backup trace in the password file
❯ ansible -m debug -i localhost, -a "msg={{ lookup('community.general.passwordstore', 'example/test', create=true, subkey='foo', overwrite=true, backup=true) }}
" localhost
localhost | SUCCESS => {
    "msg": "8jRMhmn9bE-Ra:Yh"
}
# Replace the main password
❯ ansible -m debug -i localhost, -a "msg={{ lookup('community.general.passwordstore', 'example/test', create=true, overwrite=true) }}" localhost
localhost | SUCCESS => {
    "msg": "Mjol:uhPxIiGcchM"
}
# Display the content of the password file
❯ pass example/test 
Mjol:uhPxIiGcchM

foo: 8jRMhmn9bE-Ra:Yh
lookup_pass: First generated by ansible on 01/10/2024 11:37:25
lookup_pass: old subkey password foo was u6V31gj3d0i3lLbO (Updated on 01/10/2024 11:38:03)

@ansibullbot ansibullbot added feature This issue/PR relates to a feature request lookup lookup plugin plugins plugin (any type) labels Oct 1, 2024
@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot added ci_verified Push fixes to PR branch to re-run CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Oct 1, 2024
@ansibullbot ansibullbot removed the ci_verified Push fixes to PR branch to re-run CI label Oct 1, 2024
@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot added the ci_verified Push fixes to PR branch to re-run CI label Oct 1, 2024
@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-9 Automatically create a backport for the stable-9 branch labels Oct 1, 2024
Copy link
Collaborator

@felixfontein felixfontein left a 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! A few first comments are below:

The option actually isn't added to DOCUMENTATION and self.paramvals (line 554 and following ones), so you cannot actually use it.

plugins/lookup/passwordstore.py Outdated Show resolved Hide resolved
plugins/lookup/passwordstore.py Outdated Show resolved Hide resolved
@ansibullbot ansibullbot removed the ci_verified Push fixes to PR branch to re-run CI label Oct 2, 2024
@mluzarreta mluzarreta force-pushed the main branch 2 times, most recently from 358079a to 26e3bf3 Compare October 2, 2024 08:39
@mluzarreta
Copy link
Contributor Author

Thanks for your contribution! A few first comments are below:

The option actually isn't added to DOCUMENTATION and self.paramvals (line 554 and following ones), so you cannot actually use it.

@felixfontein I added some details in the documentation but this PR does not add any parameter, it just allows the creation/update of a subkey using the existing parameters (subkey, create, overwrite, backup).

@felixfontein @russoz I rewrote the commit with your suggestions. Thank you for the review 😄

@felixfontein
Copy link
Collaborator

The option actually isn't added to DOCUMENTATION and self.paramvals (line 554 and following ones), so you cannot actually use it.

It seems I totally overlooked that the option already exists. Sorry for that :)

@mluzarreta
Copy link
Contributor Author

FYI I've just corrected a regression:

-                    elif not self.passdict.get(self.paramvals['subkey']):  # password exists but not the subkey
+                    elif self.paramvals["subkey"] != "password" and not self.passdict.get(self.paramvals['subkey']):  # password exists but not the subkey

@ansibullbot ansibullbot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Oct 3, 2024
Copy link
Collaborator

@russoz russoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@felixfontein
Copy link
Collaborator

If nobody objects, I'll merge this in a week.

@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Oct 7, 2024
@felixfontein felixfontein merged commit 24f2b98 into ansible-collections:main Oct 7, 2024
141 checks passed
Copy link

patchback bot commented Oct 7, 2024

Backport to stable-9: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-9/24f2b980b79cedd199959a29cbfd022cd5791076/pr-8952

Backported as #8996

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Oct 7, 2024
@felixfontein
Copy link
Collaborator

@mluzarreta thanks for your contribution!
@russoz thanks for reviewing!

felixfontein pushed a commit that referenced this pull request Oct 7, 2024
…creation and update (#8996)

passwordstore: Support subkey creation and update (#8952)

(cherry picked from commit 24f2b98)

Co-authored-by: Manuel Luzarreta <mluzarreta.pro@pm.me>
Massl123 pushed a commit to Massl123/community.general that referenced this pull request Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-9 Automatically create a backport for the stable-9 branch feature This issue/PR relates to a feature request lookup lookup plugin plugins plugin (any type)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants