Python library for decrypting SecureStore secrets
Project description
SecureStore Python library
This repository/package houses a Python implementation of the cross-platform, language-agnostic SecureStore secrets specification. In particular, this library may be used for interacting with SecureStore secrets containers, providing an easy-to-use and idiomatic interface for loading SecureStore containers and decrypting/retrieving secrets from your frontend or backend application, interactively or with key-based decryption.
Usage
This python library is largely intended to be used alongside one of the SecureStore cli companion apps, used to create SecureStore values and manage (add/remove/update) the secrets stored therein. In this example, we'll be using the ssclient cli utility to create a new store.
Creating a secrets vault
Typical SecureStore usage begins by creating a new SecureStore "vault" (an encrypted secrets container) that will store the credentials (usually both usernames/access keys and passwords/api keys) that your app will need for one or more services. Begin by compiling or downloading and installing a copy of ssclient, the SecureStore companion cli.
While you can compile it yourself or manually download pre-built binaries for your platform, you might find it easiest to just install it with npm:
~> npm install --global @neosmart/ssclient
after which you can proceed with the following steps:
~> mkdir secure/
~> cd secure/
~> ssclient create --export-key secrets.key
Password: ************
Confirm Password: ************
# Now you can use `ssclient -p` with your password or
# `ssclient -k secrets.key` to get or set additional
# secrets using the same encryption/decryption key.
Adding secrets
Secrets may be added with your password or the equivalent encryption key file, and may be specified in-line as arguments to ssclient or more securely at a prompt by omitting the value when calling ssclient create:
# ssclient defaults to password-based decryption:
~> ssclient set aws:s3:accessId AKIAV4EXAMPLE7QWERT
Password: *********
similarly:
# Use `-k secrets.key` to load the encryption key and
# skip the prompt for the vault password:
~> ssclient -k secrets.key set aws:s3:accessKey
Value: v1Lp9X7mN2B5vR8zQ4tW1eY6uI0oP3aS5dF7gH9j
Retrieving secrets
Secrets can be retrieved at the commandline with ssclient or programmatically with a SecureStore library for your development language or framework of choice.
This library contains the python implementation of the SecureStore protocol. The SecureStore protocol was intentionally designed to maximize security and compatibility, and, as such, has minimal dependencies (only a dependency on cryptography and compatible with very old versions of python3).
This project has been uploaded to PyPi and can be installed with pip or your favorite modern alternative:
pip install securestore
after which you can use the library as follows:
from securestore import SecretsManager, KeySource
key = KeySource.from_file("secure/secrets.key")
sman = SecretsManager.from_file("secure/secrets.json", key)
# Retrieve and decrypt a specific secret
s3AccessId = sman.get("aws:s3:accessId")
s3AccessKey = sman.get("aws:s3:accessKey")
# List all available keys in the vault
for key in sman.keys():
print(f"* {key}")
Interactively decoding secrets
Normally you would use ssclient locally with password-based decryption to manage secrets in the secrets.json vault, then use key-based decryption to allow for securely decrypting the secrets at runtime without hardcoding any secrets, as shown above. But you can also use this library interactively (or otherwise) to decrypt a SecureStore vault using a password instead:
from securestore import SecretsManager
key = KeySource.from_password("MyPASsWOrd42")
sman = SecretsManager.from_file("secrets.json", key)
sman.get("aws:s3:accessId")
...
API overview
The SecureStore library provides a high-level interface for decrypting and accessing secrets stored in SecureStore v3 vaults.
The following types/classes/interfaces are exposed by this library:
SecretsManager
The primary class used to open vaults and retrieve secrets.
| Method | Description |
|---|---|
from_file(path, key_source) |
Static. Opens a vault from a file on disk using a KeySource. |
from_json(json_str, key_source) |
Static. Opens a vault from the contents of the SecureStore vault as (string or bytes). |
from_dict(data, key_source) |
Static. Opens a vault from a pre-parsed dictionary. |
get(name) |
Retrieves and decrypts the secret associated with name. Returns None if the key does not exist. |
keys() |
Returns a list of all secret names (keys) available in the vault. |
KeySource
An abstraction layer for authentication credentials. Use this to define how the vault should be unlocked.
| Method | Description |
|---|---|
from_password(password) |
Static. For decrypting the vault with a password string. |
from_file(path) |
Static. Loads a decryption key from a file (supports raw binary or ASCII-armored keys). |
from_key(key) |
Static. Creates a key source from the contents of a key (supports bytes, str, or list of integers). |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file securestore-0.1.0.tar.gz.
File metadata
- Download URL: securestore-0.1.0.tar.gz
- Upload date:
- Size: 56.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb2c85b784a049937281f964d6a7872403f753ccc29ee10f7cc0074e5e577746
|
|
| MD5 |
d711dea62a930d400d681a2c97a3499f
|
|
| BLAKE2b-256 |
86cd66128afccb7a32775568ac48687decb22637a5015c45267909b5ffd0284a
|
File details
Details for the file securestore-0.1.0-py3-none-any.whl.
File metadata
- Download URL: securestore-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4a6fab2cf0f5917bb6e39846f74c06518b20697a6cc5596034c480fcb88bb56
|
|
| MD5 |
fecb5b24b1d9da55c6f514448382b2b1
|
|
| BLAKE2b-256 |
16ad9dd0bfe544bc009656d31120925735af25866ef0d41658d284ddb2191501
|