Code Monkey home page Code Monkey logo

keyring_pass's Introduction

keyring_pass

This is a pass backend for keyring

Install with pip install keyring-pass and set the following content in your keyringrc.cfg file:

[backend]
default-keyring = keyring_pass.PasswordStoreBackend

You can modify the default python-keyring prefix for pass, by:

  • adding following to keyringrc.cfg:

    [pass]
    key-prefix=alternative/prefix/path
    binary=gopass
  • (for keyring version 23.0.0 or higher) setting environment variables:

    • KEYRING_PROPERTY_PASS_KEY_PREFIX
    • KEYRING_PROPERTY_PASS_BINARY
  • You can clear the path (start from root), by setting above to . or an empty value (just key-prefix= on the line).

Test your setup

You can check if your setup works end-to-end (creates, reads and deletes a key from password store).

# warning: this will create and delete a key at `<prefix>/test/asd` in your password store
python -m keyring_pass

keyring_pass's People

Contributors

azmeuk avatar bo5o avatar dependabot[bot] avatar devrite avatar formula-spectre avatar nazarewk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

keyring_pass's Issues

"python-keyring" level in pass not wanted

First, I started playing with this and it seems to be exactly what I want. The only niggle of an issue I had was that keyring_pass introduces a top level directory in pass called "python-keyring"
(in the get_key() function).

I tested just having this directory be a symlink to our "api" subsection and that worked perfectly. I also tried it as a symlink to "." (to basically null it out) and that also worked perfectly.

My core issue is that with that addition, I can't use keyring_pass to get all of our creds - I could only use it to get the ones created by keyring_pass. We definitely want to be able to share/reuse credentials between python scripts and other systems (bash, ruby, maybe perl).

Is there a technical reason or security reason for this extra level that I've missed?

Invalid directory created when key-prefix set to '' --- works with . (dot)

Got a chance to test new version v0.7.0 of keyring_pass.

I'm getting the following error with python 3.6 using keyring 21.5.0

keyring -b keyring_pass.PasswordStoreBackend set local/monkey shine
Keyring config file contains incorrect values.
Config file: /Users/matthewsht/.config/python_keyring/keyringrc.cfg
Password for 'shine' in 'local/monkey':

The config file (~/.config/python_keyring/keyringrc.cfg) contains only
[pass]
key-prefix=.

I've checked for extraneous whitespace in the config and don't see any.
With key-prefix=. the password ends up at local/monkey -- which is correct.

According to the documentation, key-prefix='' should also have worked but did not -
I got a directory named ''/local/monkey at the top of tree which was not intended:

pass
Password Store
├── ''
│   └── local
│   └── monkey
│   └── foo
OTHER ENTRIES ELIDED

Invalid directory created when key-prefix set to '' --- works with . (dot)

Got a chance to test new version v0.7.0 of keyring_pass.

The config file (~/.config/python_keyring/keyringrc.cfg) contains
[pass]
key-prefix=.

With key-prefix=. the password ends up at local/monkey -- which is correct.

According to the documentation, key-prefix='' should also have worked but did not -
I got a directory named ''/local/monkey at the top of tree which was not intended:

pass
Password Store
├── ''
│ └── local
│ └── monkey
│ └── foo
OTHER ENTRIES ELIDED

How to configure from NixOS

Nice project! I see you have some .nix related files in here. Could you show me how to configure this from NixOS?
Preferably non-flake or HM.

Thanks. Happy to help update the docs after.

Version 0.8.0 not working on Python <3.9

Thank you for making this very useful Keyring backend for pass!

I am encountering AttributeError: module 'functools' has no attribute 'cache' when using keyring-pass 0.8.0 (latest version as of writing) on Python versions less than 3.9. keyring-pass may be using functools features that only became available with 3.9+. The README and PyPI package metadata indicate Python 3.7+ are supported, however.

Below is a minimal way to reproduce the error using Docker.

Python 3.9 (the failure at the end is expected due to pass not being installed):

$ docker run --rm -it --entrypoint "" -w /root python:3.9 bash -c 'pip install keyring-pass && mkdir -p ~/.config/python_keyring && echo "[backend]" >~/.config/pytho
n_keyring/keyringrc.cfg && echo "default-keyring = keyring_pass.PasswordStoreBackend" >>~/.config/python_keyring/keyringrc.cfg && keyring set https://example.com foobar'
Unable to find image 'python:3.9' locally
3.9: Pulling from library/python
bba7bb10d5ba: Already exists 
ec2b820b8e87: Already exists 
284f2345db05: Already exists 
fea23129f080: Already exists 
7c62c924b8a6: Already exists 
b2210932934e: Pull complete 
ee9c01829d92: Pull complete 
d6285f41f1b6: Pull complete 
Digest: sha256:98f018a1afd67f2e17a4abd5bfe09b998734ba7c1ee54780e7ed216f8b8095c3
Status: Downloaded newer image for python:3.9
Collecting keyring-pass
  Downloading keyring_pass-0.8.0-py3-none-any.whl (4.0 kB)
Collecting keyring<24.0.0,>=23.9.3
  Downloading keyring-23.13.1-py3-none-any.whl (37 kB)
Collecting jaraco-classes<4.0.0,>=3.2.3
  Downloading jaraco.classes-3.2.3-py3-none-any.whl (6.0 kB)
Collecting more-itertools
  Downloading more_itertools-9.1.0-py3-none-any.whl (54 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 54.2/54.2 kB 4.2 MB/s eta 0:00:00
Collecting importlib-metadata>=4.11.4
  Downloading importlib_metadata-6.7.0-py3-none-any.whl (22 kB)
Collecting jeepney>=0.4.2
  Downloading jeepney-0.8.0-py3-none-any.whl (48 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 48.4/48.4 kB 3.5 MB/s eta 0:00:00
Collecting SecretStorage>=3.2
  Downloading SecretStorage-3.3.3-py3-none-any.whl (15 kB)
Collecting zipp>=0.5
  Downloading zipp-3.15.0-py3-none-any.whl (6.8 kB)
Collecting cryptography>=2.0
  Downloading cryptography-41.0.1-cp37-abi3-manylinux_2_28_x86_64.whl (4.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.3/4.3 MB 38.5 MB/s eta 0:00:00
Collecting cffi>=1.12
  Downloading cffi-1.15.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (441 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 441.2/441.2 kB 26.1 MB/s eta 0:00:00
Collecting pycparser
  Downloading pycparser-2.21-py2.py3-none-any.whl (118 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 118.7/118.7 kB 5.9 MB/s eta 0:00:00
Installing collected packages: zipp, pycparser, more-itertools, jeepney, jaraco-classes, importlib-metadata, cffi, cryptography, SecretStorage, keyring, keyring-pass
Successfully installed SecretStorage-3.3.3 cffi-1.15.1 cryptography-41.0.1 importlib-metadata-6.7.0 jaraco-classes-3.2.3 jeepney-0.8.0 keyring-23.13.1 keyring-pass-0.8.0 more-itertools-9.1.0 pycparser-2.21 zipp-3.15.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

[notice] A new release of pip is available: 23.0.1 -> 23.1.2
[notice] To update, run: pip install --upgrade pip
Password for 'foobar' in 'https://example.com': 
Traceback (most recent call last):
  File "/usr/local/bin/keyring", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.9/site-packages/keyring/cli.py", line 134, in main
    return cli.run(argv)
  File "/usr/local/lib/python3.9/site-packages/keyring/cli.py", line 70, in run
    return method()
  File "/usr/local/lib/python3.9/site-packages/keyring/cli.py", line 87, in do_set
    set_password(self.service, self.username, password)
  File "/usr/local/lib/python3.9/site-packages/keyring/core.py", line 60, in set_password
    get_keyring().set_password(service_name, username, password)
  File "/usr/local/lib/python3.9/site-packages/keyring/core.py", line 32, in get_keyring
    init_backend()
  File "/usr/local/lib/python3.9/site-packages/keyring/core.py", line 83, in init_backend
    set_keyring(_detect_backend(limit))
  File "/usr/local/lib/python3.9/site-packages/keyring/core.py", line 98, in _detect_backend
    or load_config()
  File "/usr/local/lib/python3.9/site-packages/keyring/core.py", line 177, in load_config
    return load_keyring(keyring_name)
  File "/usr/local/lib/python3.9/site-packages/keyring/core.py", line 136, in load_keyring
    class_.priority
  File "/usr/local/lib/python3.9/site-packages/jaraco/classes/properties.py", line 151, in __get__
    return self.fget.__get__(None, owner)()
  File "/usr/local/lib/python3.9/site-packages/keyring_pass/__init__.py", line 64, in priority
    raise RuntimeError(f"`{binary}` executable is missing!")
RuntimeError: `pass` executable is missing!

Python 3.8 (the AttributeError is not expected):

$ docker run --rm -it --entrypoint "" -w /root python:3.8 bash -c 'pip install keyring-pass && mkdir -p ~/.config/python_keyring && echo "[backend]" >~/.config/python_keyring/keyringrc.cfg && echo "default-keyring = keyring_pass.PasswordStoreBackend" >>~/.config/python_keyring/keyringrc.cfg && keyring set https://example.com foobar'
Collecting keyring-pass
  Downloading keyring_pass-0.8.0-py3-none-any.whl (4.0 kB)
Collecting keyring<24.0.0,>=23.9.3
  Downloading keyring-23.13.1-py3-none-any.whl (37 kB)
Collecting jaraco-classes<4.0.0,>=3.2.3
  Downloading jaraco.classes-3.2.3-py3-none-any.whl (6.0 kB)
Collecting more-itertools
  Downloading more_itertools-9.1.0-py3-none-any.whl (54 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 54.2/54.2 kB 1.7 MB/s eta 0:00:00
Collecting importlib-resources
  Downloading importlib_resources-5.12.0-py3-none-any.whl (36 kB)
Collecting SecretStorage>=3.2
  Downloading SecretStorage-3.3.3-py3-none-any.whl (15 kB)
Collecting jeepney>=0.4.2
  Downloading jeepney-0.8.0-py3-none-any.whl (48 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 48.4/48.4 kB 1.9 MB/s eta 0:00:00
Collecting importlib-metadata>=4.11.4
  Downloading importlib_metadata-6.7.0-py3-none-any.whl (22 kB)
Collecting zipp>=0.5
  Downloading zipp-3.15.0-py3-none-any.whl (6.8 kB)
Collecting cryptography>=2.0
  Downloading cryptography-41.0.1-cp37-abi3-manylinux_2_28_x86_64.whl (4.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.3/4.3 MB 3.7 MB/s eta 0:00:00
Collecting cffi>=1.12
  Downloading cffi-1.15.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (442 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 442.7/442.7 kB 4.5 MB/s eta 0:00:00
Collecting pycparser
  Downloading pycparser-2.21-py2.py3-none-any.whl (118 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 118.7/118.7 kB 9.1 MB/s eta 0:00:00
Installing collected packages: zipp, pycparser, more-itertools, jeepney, jaraco-classes, importlib-resources, importlib-metadata, cffi, cryptography, SecretStorage, keyring, keyring-pass
Successfully installed SecretStorage-3.3.3 cffi-1.15.1 cryptography-41.0.1 importlib-metadata-6.7.0 importlib-resources-5.12.0 jaraco-classes-3.2.3 jeepney-0.8.0 keyring-23.13.1 keyring-pass-0.8.0 more-itertools-9.1.0 pycparser-2.21 zipp-3.15.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

[notice] A new release of pip is available: 23.0.1 -> 23.1.2
[notice] To update, run: pip install --upgrade pip
Password for 'foobar' in 'https://example.com': 
Traceback (most recent call last):
  File "/usr/local/bin/keyring", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/site-packages/keyring/cli.py", line 134, in main
    return cli.run(argv)
  File "/usr/local/lib/python3.8/site-packages/keyring/cli.py", line 70, in run
    return method()
  File "/usr/local/lib/python3.8/site-packages/keyring/cli.py", line 87, in do_set
    set_password(self.service, self.username, password)
  File "/usr/local/lib/python3.8/site-packages/keyring/core.py", line 60, in set_password
    get_keyring().set_password(service_name, username, password)
  File "/usr/local/lib/python3.8/site-packages/keyring/core.py", line 32, in get_keyring
    init_backend()
  File "/usr/local/lib/python3.8/site-packages/keyring/core.py", line 83, in init_backend
    set_keyring(_detect_backend(limit))
  File "/usr/local/lib/python3.8/site-packages/keyring/core.py", line 98, in _detect_backend
    or load_config()
  File "/usr/local/lib/python3.8/site-packages/keyring/core.py", line 177, in load_config
    return load_keyring(keyring_name)
  File "/usr/local/lib/python3.8/site-packages/keyring/core.py", line 134, in load_keyring
    class_ = _load_keyring_class(keyring_name)
  File "/usr/local/lib/python3.8/site-packages/keyring/core.py", line 124, in _load_keyring_class
    __import__(module_name)
  File "/usr/local/lib/python3.8/site-packages/keyring_pass/__init__.py", line 28, in <module>
    @functools.cache
AttributeError: module 'functools' has no attribute 'cache'

Thank you for your time!

ImportError with the latest python-keyring

With python-keyring 23.9.0, using keyring_pass raises an ImportError

>>> import keyring_pass
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.10/site-packages/keyring_pass/__init__.py", line 10, in <module>
    from keyring.util import properties, platform_ as platform
ImportError: cannot import name 'properties' from 'keyring.util' (/usr/lib/python3.10/site-packages/keyring/util/__init__.py)

According to this issue, the missing property is reintroduced with 23.9.1, but with a deprecation warning, so this exception will come back in the future.

Compatibility with poetry 1.71

Hi,

I'd like to use keyring_pass as a backend for storing access tokens for a private gitlab pypi registry in poetry. Unfortunately, the current dependency on keyring (^23.9.3) precludes this:

Using version ^0.8.1 for keyring-pass

Updating dependencies
Resolving dependencies... (0.0s)

Because no versions of keyring-pass match >0.8.1,<0.9.0
 and keyring-pass (0.8.1) depends on keyring (>=23.9.3,<24.0.0), keyring-pass (>=0.8.1,<0.9.0) requires keyring (>=23.9.3,<24.0.0).
And because poetry (1.7.1) depends on keyring (>=24.0.0,<25.0.0), keyring-pass (>=0.8.1,<0.9.0) is incompatible with poetry (1.7.1).
So, because poetry-instance depends on both poetry (1.7.1) and keyring-pass (^0.8.1), version solving failed.

Is there actually a breaking change in keyring 24.*, or could this be addressed with a dependency bump? If this is an unknown i'd be happy to have a go at investigating. :)

/usr/lib/python-exec/python3.11/python: No module named keyring_pass.__main__; 'keyring_pass' is a package and cannot be directly executed

I installed keyring_pass via pip install --break-system-packages keyring-pass as a quick and dirty solution before I modify the ebuild and install it system wide (I know it's dangerous, it was just for testing);
but python -m keyring_pass gives this error:
/usr/lib/python-exec/python3.11/python: No module named keyring_pass.__main__; 'keyring_pass' is a package and cannot be directly executed
am I doing something wrong? I'm following the readme to verify that it's working; my ~/.config/python_keyring/keyringrc.cfg has only the following:

[backend]
default-keyring = keyring_pass.PasswordStoreBackend

do I need to put in there something else? I use vanilla pass, not gopass (tho I might migrate to it)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.