Skip to main content

keyrings.efile

We needed a keyrings implementation that just worked in headless environments. keyrings.efile encrypts passwords using files stored on the local filesystem (/var/tmp/).

It's not secure if an attacker can read all the files, but at least doesn't store the password as plain text.

The current implemetation has the kerying priority set to 20 to take precedence over the Chainer backend. This may change in future releaeses.

Usage

Once installed, the backend is picked up by the standard keyring API:

import keyring

keyring.set_password('mydatabase', 'alice', 'secret')
print(keyring.get_password('mydatabase', 'alice'))   # secret
keyring.delete_password('mydatabase', 'alice')

The backend can also be used directly, regardless of which keyring is active:

from keyrings.efile import EncryptedFile

ef = EncryptedFile()
ef.set_password('mydatabase', 'alice', 'secret')
print(ef.get_password('mydatabase', 'alice'))        # secret
print(ef.list_entries())                             # [('mydatabase', 'alice')]
ef.delete_password('mydatabase', 'alice')

FallbackPasswordHandler returns the stored password, or prompts for one if none is stored. A prompted password is saved only if the with block completes without an exception, so a mistyped password is not remembered:

from keyrings.efile import FallbackPasswordHandler

handler = FallbackPasswordHandler('mydatabase', 'alice')
with handler as password:
    connection = connect(user='alice', password=password)  # raises on bad password

Call handler.delete_password() to remove a stored password that is no longer valid.

Debug logging is available through the keyrings.efile logger:

import logging
logging.basicConfig()
logging.getLogger('keyrings.efile').setLevel(logging.DEBUG)

Update

Version 2.0 implements delete_password.

Version 3.0 adds FallbackPasswordHandler and logging.

Version 4.0 adds list_entries.

Version 4.1 adds uses system firmware information when encrypting passwords as root.

Command line

The keyrings-efile command is provided by the separate keyrings.efile.cli package, installed with either pip install keyrings.efile.cli or pip install keyrings.efile[cli]:

keyrings-efile list                  # list stored services and users
keyrings-efile show SERVICE USER     # display password
keyrings-efile delete SERVICE USER   # delete entry

Release files for keyrings.efile 4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for keyrings.efile 4.1
File Size Uploaded
keyrings_efile-4.1.tar.gz 8.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for keyrings.efile 4.1
File Interpreter ABI Platform
keyrings_efile-4.1-py3-none-any.whl Python 3 none any Details

Total release size: 16.2 kB

Release files / keyrings_efile-4.1.tar.gz

Download URL keyrings_efile-4.1.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7c3797e4a8b2eda0b9c3f3e79f805e96d1272864e6c5358585fdd49bbafa9e5a
BLAKE2b-256 checksum
How to use checksums
336a49fd202c8b5c590ccc48ac2812d72180c4f5a6f217cfd454e0f1668b0180
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / keyrings_efile-4.1-py3-none-any.whl

Download URL keyrings_efile-4.1-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
36259100742977028787b4a6f3259ea0eb7c039b6efe8971f36a442e3a7caf93
BLAKE2b-256 checksum
How to use checksums
03820a5448132bdb3e5e15e49169f6993d236ae923540da31b19d8457521d13e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

4.1 This release

2 release files

4.0

2 release files

3.0

2 release files

2.0

2 release files

1.1

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page