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

Fall back when keyring is locked #7037

Closed
wants to merge 2 commits into from

Conversation

remram44
Copy link
Contributor

Pull Request Check List

Resolves: #1917

  • Added tests for changed code.
  • Updated documentation for changed code.

Description

Fall back if keyring is locked.

This avoids Poetry crashing with KeyringLocked if no keyring is available or the user doesn't unlock it, in situation where no credentials are needed.

If credentials were needed and the keyring is locked, the user will get a permission error, which I believe is perfectly fine.

I think Poetry shouldn't request access to the keyring before the remote server has actually asked for credentials, but this can be done in a subsequent change. #1917 is affecting many users.

@remram44 remram44 changed the base branch from master to 1.2 November 15, 2022 17:23
@dimbleby
Copy link
Contributor

see #6612

Copy link
Member

@neersighted neersighted left a comment

Choose a reason for hiding this comment

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

Needs tests (and mostly looks like a less correct #6612 -- @MatthieuBizien, are you still working on that PR)?

We also do not accept PRs against the 1.2 branch -- this change must go into master to be accepted.

@@ -46,9 +46,14 @@ def get_credential(
return default

import keyring
import keyring.errors
Copy link
Member

Choose a reason for hiding this comment

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

This is unnecessary.

credential = keyring.get_credential(name, username)
except keyring.errors.KeyringLocked:
self._is_available = False
break
Copy link
Member

Choose a reason for hiding this comment

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

This flow-control doesn't make sense (we shouldn't abort trying all names) -- instead, defaulting credential to None and logging make more sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the keyring is locked because the user canceled, asking them again and again is not very good UX. A single poetry install command might prompt the user a hundred times...

@remram44 remram44 changed the base branch from 1.2 to master November 15, 2022 17:34
@felix-ht
Copy link

felix-ht commented Nov 15, 2022

i did some reading in the code and the root cause of this issue seems to be that any request made by poetry tries to get auth information from the keyring even if the config of the PasswordManager has no indication that the requets needs auth in the first place. This is also the reason why any operation that does any kind of requests fails, with the keyring errors.

The solution should be to only check the keyring if the config of the PasswordManager holds a entry but this entry has no password stored.

This will most likely need more changes than this PR. (Working some stuff out right now but will create a PR as well)

The only option to avoid this is to make the fallback behavior of PasswordManager a config - this certainly is a larger change so getting this merged would be gerat - #7038

credential = keyring.get_credential(name, username)
try:
credential = keyring.get_credential(name, username)
except keyring.errors.KeyringLocked:

Choose a reason for hiding this comment

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

This is missing the #3012 error which is common for headless servers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel like no retry should happen, even with different service names, when getting a KeyringLocked, but I am not sure that behavior is appropriate for all the other KeyringError subclasses.

@radoering
Copy link
Member

Closing because #8227 has been merged.

@radoering radoering closed this Oct 3, 2023
Copy link

github-actions bot commented Mar 3, 2024

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Keyring errors during non-publishing operations
6 participants