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

ChainerBackend not deleting password from lower priority backend #697

Open
jim-easterbrook opened this issue Oct 1, 2024 · 2 comments
Open

Comments

@jim-easterbrook
Copy link
Contributor

Describe the bug
Using kdewallet I can see old keyring passwords listed in "Secret Service". New keyring passwords are listed under the "system" passed to set_password. I assume this is because I previously did not have keyring.backends.kwallet.DBusKeyring installed.

$ python3.11 -m keyring --list-backends
keyring.backends.chainer.ChainerBackend (priority: 10)
keyring.backends.kwallet.DBusKeyring (priority: 5.1)
keyring.backends.SecretService.Keyring (priority: 5)
keyring.backends.fail.Keyring (priority: 0)

$ python3.11 -m keyring get system username correctly finds the old passwords. $ python3.11 -m keyring del system username fails as follows:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/jim/.local/lib/python3.11/site-packages/keyring/__main__.py", line 4, in <module>
    cli.main()
  File "/home/jim/.local/lib/python3.11/site-packages/keyring/cli.py", line 216, in main
    return cli.run(argv)
           ^^^^^^^^^^^^^
  File "/home/jim/.local/lib/python3.11/site-packages/keyring/cli.py", line 120, in run
    return method()
           ^^^^^^^^
  File "/home/jim/.local/lib/python3.11/site-packages/keyring/cli.py", line 157, in do_del
    delete_password(self.service, self.username)
  File "/home/jim/.local/lib/python3.11/site-packages/keyring/core.py", line 73, in delete_password
    get_keyring().delete_password(service_name, username)
  File "/home/jim/.local/lib/python3.11/site-packages/keyring/backends/chainer.py", line 63, in delete_password
    return keyring.delete_password(service, username)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jim/.local/lib/python3.11/site-packages/keyring/backends/kwallet.py", line 150, in delete_password
    raise PasswordDeleteError("Password not found")
keyring.errors.PasswordDeleteError: Password not found

Expected behavior
I would expect to be able to delete any password that I can read.

Environment

  • OS: openSUSE 15.6
$ python3.11 -m pip list | grep keyring
keyring                       25.4.1

$ python3.11 -m keyring --list-backends
keyring.backends.chainer.ChainerBackend (priority: 10)
keyring.backends.kwallet.DBusKeyring (priority: 5.1)
keyring.backends.SecretService.Keyring (priority: 5)
keyring.backends.fail.Keyring (priority: 0)
@jim-easterbrook
Copy link
Contributor Author

jim-easterbrook commented Oct 2, 2024

How to reproduce:

$ python3.11 -m keyring -b keyring.backends.SecretService.Keyring set testing test
Password for 'test' in 'testing': 
$ python3.11 -m keyring get testing test
password
$ python3.11 -m keyring del testing test
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/jim/.local/lib/python3.11/site-packages/keyring/__main__.py", line 4, in <module>
    cli.main()
  File "/home/jim/.local/lib/python3.11/site-packages/keyring/cli.py", line 216, in main
    return cli.run(argv)
           ^^^^^^^^^^^^^
  File "/home/jim/.local/lib/python3.11/site-packages/keyring/cli.py", line 120, in run
    return method()
           ^^^^^^^^
  File "/home/jim/.local/lib/python3.11/site-packages/keyring/cli.py", line 157, in do_del
    delete_password(self.service, self.username)
  File "/home/jim/.local/lib/python3.11/site-packages/keyring/core.py", line 73, in delete_password
    get_keyring().delete_password(service_name, username)
  File "/home/jim/.local/lib/python3.11/site-packages/keyring/backends/chainer.py", line 63, in delete_password
    return keyring.delete_password(service, username)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jim/.local/lib/python3.11/site-packages/keyring/backends/kwallet.py", line 150, in delete_password
    raise PasswordDeleteError("Password not found")
keyring.errors.PasswordDeleteError: Password not found

Of course I can delete the password by specifying the backend with -b, but I'd prefer not to worry about backends in my programmatic use of python-keyring.

@jaraco jaraco added the bug label Oct 26, 2024
@jaraco
Copy link
Owner

jaraco commented Oct 26, 2024

That seems like a bug to me. I see that the chainer's behavior is to suppress NotImplementedError but not other errors from the chained backends. Probably it should also suppress PasswordDeleteError or maybe there should be a separate class of exception for PasswordNotFound so that the chainer can discern between a failure and a non-existent password. Would you be willing to work on a patch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants