Python/keyrings: Difference between revisions
< Python
| (4 intermediate revisions by the same user not shown) | |||
| Line 6: | Line 6: | ||
# or | # or | ||
python3 -m pip install --upgrade keyring keyrings.alt | |||
== cryptfile == | == cryptfile == | ||
| Line 12: | Line 12: | ||
https://pypi.org/project/keyrings.cryptfile/ | https://pypi.org/project/keyrings.cryptfile/ | ||
python3 -m pip keyrings.cryptfile | python3 -m pip install --upgrade keyrings.cryptfile | ||
~/.config/python_keyring | ~/.config/python_keyring | ||
Clear cryptfile config and cache: | Clear cryptfile config and cache: | ||
rm -f ~/.local/share/python_keyring/cryptfile_pass.cfg | rm -f ~/.local/share/python_keyring/cryptfile_pass.cfg | ||
rm -rf ~/.config/python_keyring | rm -rf ~/.config/python_keyring | ||
--- | |||
- | Change password in crypt file: | ||
export INF=~/.local/share/python_keyring/cryptfile_pass.cfg | |||
export OUTF=temp.cfg | |||
python -m keyrings.cryptfile.convert GCM $INF $OUTF | |||
=== clone cryptfile install === | === clone cryptfile install === | ||
| Line 86: | Line 89: | ||
dbus-run-session -- sh | dbus-run-session -- sh | ||
echo -n "your_login_password" | gnome-keyring-daemon --unlock | echo -n "your_login_password" | gnome-keyring-daemon --unlock | ||
--- | |||
Config files: | |||
<pre> | |||
$ cat ~/.config/python_keyring/keyringrc | |||
# Headless SSH box: gnome-keyring cannot create its collection without a | |||
# graphical prompt, so use the encrypted file backend instead. | |||
[backend] | |||
default-keyring=keyrings.cryptfile.cryptfile.CryptFileKeyring | |||
</pre> | |||
== keyring == | |||
See [[python/keyring]] | |||
== keywords == | == keywords == | ||
Latest revision as of 05:01, 18 September 2026
keyrings
Another keyring db for other usage
sudo apt install python3-keyring python3-keyrings.alt # which also installs: python3-pycryptodome python3-secretstorage # or
python3 -m pip install --upgrade keyring keyrings.alt
cryptfile
https://pypi.org/project/keyrings.cryptfile/
python3 -m pip install --upgrade keyrings.cryptfile ~/.config/python_keyring
Clear cryptfile config and cache:
rm -f ~/.local/share/python_keyring/cryptfile_pass.cfg rm -rf ~/.config/python_keyring
---
Change password in crypt file:
export INF=~/.local/share/python_keyring/cryptfile_pass.cfg export OUTF=temp.cfg python -m keyrings.cryptfile.convert GCM $INF $OUTF
clone cryptfile install
$ git clone https://github.com/frispete/keyrings.cryptfile $ cd keyrings.cryptfile $ pyvenv env $ . env/bin/activate (env) $ pip install -e .
example cryptfile session
(env) $ python3
Python 3.4.5 (default, Jul 03 2016, 12:57:15) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from keyrings.cryptfile.cryptfile import CryptFileKeyring
>>> kr = CryptFileKeyring()
>>> kr.set_password("service", "user", "secret")
Please set a password for your new keyring: ******
Please confirm the password: ******
>>> ^d
(env) $ python3
Python 3.4.5 (default, Jul 03 2016, 12:57:15) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from keyrings.cryptfile.cryptfile import CryptFileKeyring
>>> kr = CryptFileKeyring()
>>> kr.get_password("service", "user")
Please enter password for encrypted keyring: ******
'secret'
>>> ^d
from getpass import getpass
from os import getenv
from keyrings.cryptfile.cryptfile import CryptFileKeyring
kr = CryptFileKeyring()
kr.keyring_key = getenv("KEYRING_CRYPTFILE_PASSWORD") or getpass()
kr.get_password("service", "user")
---
Error:
keyring.errors.InitError: Failed to create the collection: Prompt dismissed..
Cause:
- This error occurs because the keyring library is trying to open a secure system dialog to unlock or create a credentials collection, but your environment cannot display it. This is a common issue when running tools like poetry, az cli, or flyte over SSH, inside a headless Linux environment, or within a Docker container where a graphical desktop interface is missing.
Fix:
### NO: export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring
# or
dbus-run-session -- sh echo -n "your_login_password" | gnome-keyring-daemon --unlock
---
Config files:
$ cat ~/.config/python_keyring/keyringrc # Headless SSH box: gnome-keyring cannot create its collection without a # graphical prompt, so use the encrypted file backend instead. [backend] default-keyring=keyrings.cryptfile.cryptfile.CryptFileKeyring
keyring
See python/keyring