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

keyring.set_value Returns None Using Default Backend #690

Open
rahilmansuri1 opened this issue Aug 21, 2024 · 1 comment
Open

keyring.set_value Returns None Using Default Backend #690

rahilmansuri1 opened this issue Aug 21, 2024 · 1 comment

Comments

@rahilmansuri1
Copy link

Issue: keyring.set_value Returns None Using Default Backend

When using keyring.set_value() to store a password without explicitly specifying a backend, the default backend selected is keyring.backends.null.Keyring, which results in the value being stored as None. This happens despite the system having a valid keyring service (Seahorse) managing secrets.

However, when I manually specify the SecretService backend in the code, the password is stored and retrieved correctly. The default backend should ideally select a working backend without requiring manual intervention.

How I Get This Error

Steps to encounter the behavior:

  1. Use the following code snippet to store and retrieve a secret using the default backend:

    import keyring as kr
    
    APP_NAME = 'Keyring-test'
    TEST_KEY = "test_key"
    test_value = "Hello, I am keyring test value"
    
    # Set a value using the default backend
    kr.set_password(APP_NAME, TEST_KEY, test_value)
    
    # Retrieve the value
    retrieved_value = kr.get_password(APP_NAME, TEST_KEY)
    print(f"Retrieved value: {retrieved_value}")
  2. Run the code on a system using Gnome 43.9 (Wayland) with Seahorse handling secrets.

  3. Observe that retrieved_value is None, despite expecting it to return the stored test_value.

  4. Now, try the same code with a specific backend (which works correctly):

    import keyring as kr
    from keyring.backends import SecretService
    
    APP_NAME = 'Keyring-test'
    TEST_KEY = "test_key_with_specific_backend"
    test_value = "Hello, I am keyring test value with specific backend"
    
    # Set a specific backend
    backend = SecretService.Keyring()
    kr.set_keyring(backend)
    
    # Store the value using the specific backend
    kr.set_password(APP_NAME, TEST_KEY, test_value)
    
    # Retrieve the value
    retrieved_value = kr.get_password(APP_NAME, TEST_KEY)
    print(f"Retrieved value: {retrieved_value}")
  5. Observe that when using the specific backend, the value is stored and retrieved correctly.

Expected Behavior

The keyring library should automatically select a functional backend (e.g., SecretService or Gnome Keyring) when no backend is explicitly specified. The stored value should be retrievable using the default backend configuration.

Environment

  • OS: debian 12 (xfce as desktop environment)
  • Backend: Seahorse (handles secrets)
  • Keyring Version: keyring 25.3.0

Additional Context

Here’s the result I observed with the default and specific backends:

--- Setting and Retrieving Value Without Specific Backend ---
Using backend: keyring.backends.null.Keyring (priority: -1)
Password set successfully for key: test_key
Using backend: keyring.backends.null.Keyring (priority: -1)
Value retrieved for key 'test_key': None

--- Setting and Retrieving Value With Specific Backend ---
Current backend: keyring.backends.SecretService.Keyring (priority: 5)
Password set successfully for key: test_key_with_specific_backend
Retrieved password: Hello, I am keyring test value with specific backend

The issue occurs when keyring.get_keyring() defaults to keyring.backends.null.Keyring, which has a priority of -1 and does not store secrets. Manually selecting SecretService.Keyring resolves the issue.

List of the backends :

  • keyring.backends.fail.Keyring (priority: 0)
  • keyring.backends.SecretService.Keyring (priority: 5)
  • keyring.backends.chainer.ChainerBackend (priority: -1)
@jaraco
Copy link
Owner

jaraco commented Sep 21, 2024

Based on the priorities reported, keyring.backends.SecretService.Keyring should be the default backend. Moreover, the null.Keyring should only be selected when specifically configured, such as through Disabling Keyring. You should double-check that you don't have that environment variable set or have the null.Keyring configured.

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

No branches or pull requests

2 participants