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

Onepassword lookup add service accounts #6660

Conversation

Domi-cc
Copy link
Contributor

@Domi-cc Domi-cc commented Jun 9, 2023

SUMMARY

add new service_account_token for onepassword lookup

Fixes #6635

minor_changes:

  • onepassword lookup - adds service_account_token parameters for supporting 1password service accounts
ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

onepassword

ADDITIONAL INFORMATION
lookup('community.general.onepassword', 'KITT', vault='Servers', service_account_token='ops_foobar....')

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added feature This issue/PR relates to a feature request lookup lookup plugin module module new_contributor Help guide this first time contributor plugins plugin (any type) labels Jun 9, 2023
@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-7 Automatically create a backport for the stable-7 branch labels Jun 12, 2023
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! Can you please add a changelog fragment? Thanks.

plugins/lookup/onepassword.py Outdated Show resolved Hide resolved
plugins/lookup/onepassword_raw.py Outdated Show resolved Hide resolved
plugins/modules/onepassword_info.py Outdated Show resolved Hide resolved
jansagurna and others added 3 commits June 12, 2023 22:34
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Felix Fontein <felix@fontein.de>
@ansibullbot ansibullbot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Jun 12, 2023
@jansagurna
Copy link
Contributor

/rebuild

@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Jun 12, 2023
@ansibullbot ansibullbot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Jun 12, 2023
@ansibullbot ansibullbot added needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI and removed needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Jun 13, 2023
@jansagurna
Copy link
Contributor

@samdoran i hope i fixed all your comments please ping me if i missed one.

Co-authored-by: Felix Fontein <felix@fontein.de>
@samdoran
Copy link
Contributor

@jansagurna There are a few minor ones.

The main thing that should still be addressed is the changes to _check_required_params. I think that method should be left as is and the caller in each class should decide if it needs to be called. That provides the cleanest separation of duties.

# Something like this
if not self.service_account_token:
    self._check_required_params(['some', 'params'])

@jansagurna
Copy link
Contributor

@samdoran i removed the check directly from the _check_required_params and added a check before try to login. is this fine for you?

@Domi-cc
Copy link
Contributor Author

Domi-cc commented Jun 14, 2023

are we good here? or do you need any assistance?

plugins/lookup/onepassword.py Outdated Show resolved Hide resolved
Comment on lines 517 to 518
if self.service_account_token:
self._check_required_params(['service_account_token'])
Copy link
Contributor

Choose a reason for hiding this comment

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

The service_account_token attribute can only be set if it was passed as a parameter, so it's not necessary to check for only that parameter in a separate call.

Reading through this more, this method shouldn't be called at all if service_account_token was passed to the lookup. It will either appear to be logged in already or fail before it gets here (if the changes in my other suggestion are made).

All the changes to this method can be removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

removed the self._check_required_params(['service_account_token'])

plugins/lookup/onepassword.py Outdated Show resolved Hide resolved
@ansibullbot ansibullbot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Jun 14, 2023
jansagurna and others added 4 commits June 14, 2023 20:18
Co-authored-by: Sam Doran <github@samdoran.com>
Co-authored-by: Sam Doran <github@samdoran.com>
@ansibullbot ansibullbot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Jun 14, 2023
Copy link
Contributor

@samdoran samdoran left a comment

Choose a reason for hiding this comment

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

Hopefully these are the last few changes. Thank you for all your work.

Comment on lines 516 to 523
if self.service_account_token:
environment_update = {"OP_SERVICE_ACCOUNT_TOKEN": self.service_account_token}
args = [
"whoami",
]

args = [
"account", "add", "--raw",
"--address", "{0}.{1}".format(self.subdomain, self.domain),
"--email", to_bytes(self.username),
"--signin",
]
return self._run(args, environment_update=environment_update)
else:
Copy link
Contributor

Choose a reason for hiding this comment

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

These changes aren't needed since full_signin will be skipped if there is service token. If there is a problem with the service token, the lookup will exit before getting here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Removed these changes.

plugins/lookup/onepassword.py Outdated Show resolved Hide resolved
jansagurna and others added 2 commits June 14, 2023 20:44
Co-authored-by: Sam Doran <github@samdoran.com>
Copy link
Contributor

@samdoran samdoran left a comment

Choose a reason for hiding this comment

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

Look great. Thank you for your contribution.

@samdoran
Copy link
Contributor

shipit

@felixfontein felixfontein merged commit 473e557 into ansible-collections:main Jun 15, 2023
136 checks passed
@patchback
Copy link

patchback bot commented Jun 15, 2023

Backport to stable-7: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-7/473e557c2f31425495fa5deed514835bdc508315/pr-6660

Backported as #6710

🤖 @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 Jun 15, 2023
* add service account token and bypass required fields when service account token is set

* add token to base class

* add Info

* add service_account_token

* add service_account_token

* add documentation

* add service_account_token

* fix E111: indentation is not a multiple of 4

* fix lint problems

* Update plugins/lookup/onepassword_raw.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/onepassword_info.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/lookup/onepassword.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* add changelog fragment

* change type service_account_token to align to domain option

* add fragment value

* Update changelogs/fragments/6660-onepassword-lookup-service-account.yaml

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/lookup/onepassword.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* remove service_account_token from onepassword_info.py

* adjust V1 to raise error if service_account_token is set

* adjust V1 to raise error if service_account_token is set

* adjust V1 to raise error if service_account_token is set

* adjust if assert_logged_in

* Update plugins/lookup/onepassword.py

Co-authored-by: Sam Doran <github@samdoran.com>

* Update plugins/lookup/onepassword.py

Co-authored-by: Sam Doran <github@samdoran.com>

* remove double return

* remove new line

* remove new line

* remove new line

* remove spaces

* remove new line

* remove spaces

* Update plugins/lookup/onepassword_raw.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* add _check_required_params

* Update plugins/lookup/onepassword.py

Co-authored-by: Sam Doran <github@samdoran.com>

* Update plugins/lookup/onepassword.py

Co-authored-by: Sam Doran <github@samdoran.com>

* remove _check_required_params

* remove spaces

* Update plugins/lookup/onepassword.py

Co-authored-by: Sam Doran <github@samdoran.com>

* remove code

---------

Co-authored-by: Jan Sagurna <jan.sagurna@sag-solutions.com>
Co-authored-by: Jan Sagurna <58932831+jansagurna@users.noreply.github.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Sam Doran <github@samdoran.com>
(cherry picked from commit 473e557)
@felixfontein
Copy link
Collaborator

@Domi-cc @jansagurna thanks a lot for working on this!
@samdoran thanks a lot for reviewing!

@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Jun 15, 2023
felixfontein pushed a commit that referenced this pull request Jun 15, 2023
… accounts (#6710)

Onepassword lookup add service accounts (#6660)

* add service account token and bypass required fields when service account token is set

* add token to base class

* add Info

* add service_account_token

* add service_account_token

* add documentation

* add service_account_token

* fix E111: indentation is not a multiple of 4

* fix lint problems

* Update plugins/lookup/onepassword_raw.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/onepassword_info.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/lookup/onepassword.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* add changelog fragment

* change type service_account_token to align to domain option

* add fragment value

* Update changelogs/fragments/6660-onepassword-lookup-service-account.yaml

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/lookup/onepassword.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* remove service_account_token from onepassword_info.py

* adjust V1 to raise error if service_account_token is set

* adjust V1 to raise error if service_account_token is set

* adjust V1 to raise error if service_account_token is set

* adjust if assert_logged_in

* Update plugins/lookup/onepassword.py

Co-authored-by: Sam Doran <github@samdoran.com>

* Update plugins/lookup/onepassword.py

Co-authored-by: Sam Doran <github@samdoran.com>

* remove double return

* remove new line

* remove new line

* remove new line

* remove spaces

* remove new line

* remove spaces

* Update plugins/lookup/onepassword_raw.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* add _check_required_params

* Update plugins/lookup/onepassword.py

Co-authored-by: Sam Doran <github@samdoran.com>

* Update plugins/lookup/onepassword.py

Co-authored-by: Sam Doran <github@samdoran.com>

* remove _check_required_params

* remove spaces

* Update plugins/lookup/onepassword.py

Co-authored-by: Sam Doran <github@samdoran.com>

* remove code

---------

Co-authored-by: Jan Sagurna <jan.sagurna@sag-solutions.com>
Co-authored-by: Jan Sagurna <58932831+jansagurna@users.noreply.github.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Sam Doran <github@samdoran.com>
(cherry picked from commit 473e557)

Co-authored-by: Dominik Haßelkuss <Domi-cc@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-7 Automatically create a backport for the stable-7 branch feature This issue/PR relates to a feature request lookup lookup plugin new_contributor Help guide this first time contributor plugins plugin (any type)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

onepassword lookup with service account
5 participants