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: ignore errors from "op account get" #5942

Merged
merged 3 commits into from
Feb 22, 2023
Merged

onepassword: ignore errors from "op account get" #5942

merged 3 commits into from
Feb 22, 2023

Conversation

gmarcy
Copy link
Contributor

@gmarcy gmarcy commented Feb 5, 2023

SUMMARY

When using the onepassword lookup plugin, part of the flow is to determine if you are signed in. This is performed in an api version specific function called assert_logged_in() documented as "Check whether a login session exists" which uses the command op account get. When you are not in fact signed in, this cli can return an error which is currently not ignored and can cause the lookup plugin to fail at that point rather than correctly returning the status to indicate that you are not signed in and proceed to signin using the parameters passed for that purpose.

This change passes the ignore_errors=True parameter to the _run function so that the return code can be used to indicate you are not signed in when an error occurs.

changelog fragment

bugfixes:

  • onepassword - Changed to ignore errors from "op account get" calls. Previously, errors would prevent auto-signin code from executing.
ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

plugins/lookup/onepassword.py

ADDITIONAL INFORMATION

ansible task

  • line breaks and indentation added for clarity
  • all signin values changed from valid ones
  • mysecret is not defined to show the proper result saying it does not exist
- name: Load value from 1Password
  set_fact:
    op_fact: "{{ lookup('community.general.onepassword', 'mysecret',
                                     master_password='my_master_password',
                                     secret_key='my_secret_key',
                                     subdomain='my_subdomain',
                                     username='my_username') }}"

before fix applied

fatal: [playbook-secrets]: FAILED! => {
    "msg": "[ERROR] 2023/02/05 11:46:22 You are not currently signed in. Please run `op signin --help` for instructions\n"
}

after fix applied

fatal: [playbook-secrets]: FAILED! => {
    "msg": "[ERROR] 2023/02/05 11:42:50 \"mysecret\" isn't an item. Specify the item with its UUID, name, or domain.\n"
}

cli behavior when not signed in

$ op account get 
[ERROR] 2023/02/05 11:47:04 You are not currently signed in. Please run `op signin --help` for instructions
$ echo $?
1

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added bug This issue/PR relates to a bug lookup lookup plugin new_contributor Help guide this first time contributor plugins plugin (any type) small_patch Hopefully easy to review labels Feb 5, 2023
@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-5 labels Feb 6, 2023
@felixfontein felixfontein changed the title ignore errors from "op account get" onepassword: ignore errors from "op account get" Feb 6, 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.

@gmarcy
Copy link
Contributor Author

gmarcy commented Feb 7, 2023

Thanks for your contribution! Can you please add a changelog fragment? Thanks.

I've updated the previous changelog fragment.

@samdoran
Copy link
Contributor

samdoran commented Feb 7, 2023

This change looks correct. Thank you very much for fixing this. :shipit:

@samdoran
Copy link
Contributor

samdoran commented Feb 7, 2023

@gmarcy It doesn't look like there is a changeling fragment in this PR. You'll need to make a new file in changelog/fragments as described in the docs.

@gmarcy
Copy link
Contributor Author

gmarcy commented Feb 7, 2023

oh, separate file. I put it inline in the PR summary. sorry, first PR here, missed that nuance.

@ansibullbot ansibullbot removed the small_patch Hopefully easy to review label Feb 7, 2023
@ansibullbot ansibullbot added the stale_ci CI is older than 7 days, rerun before merging label Feb 17, 2023
@ansibullbot ansibullbot removed the stale_ci CI is older than 7 days, rerun before merging label Feb 22, 2023
@felixfontein felixfontein merged commit 5648e0e into ansible-collections:main Feb 22, 2023
@patchback
Copy link

patchback bot commented Feb 22, 2023

Backport to stable-5: 💔 cherry-picking failed — conflicts found

❌ Failed to cleanly apply 5648e0e on top of patchback/backports/stable-5/5648e0e2aff5ac1c677dc9047c332498d595dc45/pr-5942

Backporting merged PR #5942 into main

  1. Ensure you have a local repo clone of your fork. Unless you cloned it
    from the upstream, this would be your origin remote.
  2. Make sure you have an upstream repo added as a remote too. In these
    instructions you'll refer to it by the name upstream. If you don't
    have it, here's how you can add it:
    $ git remote add upstream https://github.com/ansible-collections/community.general.git
  3. Ensure you have the latest copy of upstream and prepare a branch
    that will hold the backported code:
    $ git fetch upstream
    $ git checkout -b patchback/backports/stable-5/5648e0e2aff5ac1c677dc9047c332498d595dc45/pr-5942 upstream/stable-5
  4. Now, cherry-pick PR onepassword: ignore errors from "op account get" #5942 contents into that branch:
    $ git cherry-pick -x 5648e0e2aff5ac1c677dc9047c332498d595dc45
    If it'll yell at you with something like fatal: Commit 5648e0e2aff5ac1c677dc9047c332498d595dc45 is a merge but no -m option was given., add -m 1 as follows instead:
    $ git cherry-pick -m1 -x 5648e0e2aff5ac1c677dc9047c332498d595dc45
  5. At this point, you'll probably encounter some merge conflicts. You must
    resolve them in to preserve the patch from PR onepassword: ignore errors from "op account get" #5942 as close to the
    original as possible.
  6. Push this branch to your fork on GitHub:
    $ git push origin patchback/backports/stable-5/5648e0e2aff5ac1c677dc9047c332498d595dc45/pr-5942
  7. Create a PR, ensure that the CI is green. If it's not — update it so that
    the tests and any other checks pass. This is it!
    Now relax and wait for the maintainers to process your pull request
    when they have some cycles to do reviews. Don't worry — they'll tell you if
    any improvements are necessary when the time comes!

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

@patchback
Copy link

patchback bot commented Feb 22, 2023

Backport to stable-6: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-6/5648e0e2aff5ac1c677dc9047c332498d595dc45/pr-5942

Backported as #6037

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

@felixfontein
Copy link
Collaborator

@gmarcy thanks for fixing this!
@samdoran thanks for reviewing!

patchback bot pushed a commit that referenced this pull request Feb 22, 2023
* ignore errors from "op account get"

* add changelog fragment

* Update changelogs/fragments/5942-onepassword-ignore-errors-from-op-account-get.yml

Co-authored-by: Felix Fontein <[email protected]>

---------

Co-authored-by: Felix Fontein <[email protected]>
(cherry picked from commit 5648e0e)
@github-actions
Copy link

Docs Build 📝

Thank you for contribution!✨

This PR has been merged and your docs changes will be incorporated when they are next published.

felixfontein pushed a commit that referenced this pull request Feb 22, 2023
…m "op account get" (#6037)

onepassword: ignore errors from "op account get" (#5942)

* ignore errors from "op account get"

* add changelog fragment

* Update changelogs/fragments/5942-onepassword-ignore-errors-from-op-account-get.yml

Co-authored-by: Felix Fontein <[email protected]>

---------

Co-authored-by: Felix Fontein <[email protected]>
(cherry picked from commit 5648e0e)

Co-authored-by: Glenn Marcy <[email protected]>
@felixfontein
Copy link
Collaborator

Hmm, for some reasons the unit tests were not running in this PR. Merging this PR thus broke CI (since the tests now fail). I've created a PR to fix this (#6041), but we definitely have to figure out why change detection does not let these tests run...

@felixfontein
Copy link
Collaborator

Looking at the ansible-test sources, it seems that the directory scheme used was never supported for plugins such as lookup plugins. All unit tests for lookup plugin foo have to be in tests/unit/plugins/lookup/test_foo.py.

I'll create a PR to re-arrange them.

@felixfontein
Copy link
Collaborator

#6075 fixes this.

@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Feb 25, 2023
@gmarcy gmarcy deleted the ignore_account_get_errors branch February 25, 2023 20:00
jikamens pushed a commit to jikamens/community.general that referenced this pull request Feb 25, 2023
…#5942)

* ignore errors from "op account get"

* add changelog fragment

* Update changelogs/fragments/5942-onepassword-ignore-errors-from-op-account-get.yml

Co-authored-by: Felix Fontein <[email protected]>

---------

Co-authored-by: Felix Fontein <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug 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.

4 participants