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.

Version 4.2 makes writes atomic and adds logging.

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

Metadata

Release files for keyrings.efile 4.2

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.2
File Size Uploaded
keyrings_efile-4.2.tar.gz 8.5 kB Details

Built distribution (wheel)

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

Total release size: 16.7 kB

Release files / keyrings_efile-4.2.tar.gz

Download URL keyrings_efile-4.2.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
432753e32dd736e17cc7ad395d594016e71e8049ac38c7f63d5ff05c529d25c5
BLAKE2b-256 checksum
How to use checksums
b059ad850566d579a9af1f7b8707158a791f65cb7aa0d10dc60b4a0cabaa5c75
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.2-py3-none-any.whl

Download URL keyrings_efile-4.2-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
08797c38b2ec2fcb8442710f069f06c158c6736490de8e539a85bff55ff65487
BLAKE2b-256 checksum
How to use checksums
fac56bbfcf820e146eaf53f57668e8179fb4d9d3557bd62063510ecc482a1add
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.2 This release

2 release files

4.1

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