Skip to main content

Python library for decrypting SecureStore secrets

Project description

PyPI - Version PyPI - Python Version PyPI - Types

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

securestore-0.1.2.tar.gz (56.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

securestore-0.1.2-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file securestore-0.1.2.tar.gz.

File metadata

  • Download URL: securestore-0.1.2.tar.gz
  • Upload date:
  • Size: 56.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for securestore-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ca1c50043f294c23e5745e916a0521e823e023692a0cec8d81c9e93e77d1dccd
MD5 b0dccde150afbd2a70358c2b4cd75102
BLAKE2b-256 aee00579a6ef13574940123d1566aa4b1c239033adc8fecbdd4e108746cf9aba

See more details on using hashes here.

File details

Details for the file securestore-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: securestore-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for securestore-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2616c62137c1d5d919fc6fd2acc9657fb3e6f13d1840de766d8162d1bd889a48
MD5 a3b7b7d7bb71756fc1848451cf03c3e0
BLAKE2b-256 ad8f7cd4ed05dcb5cd83ad72f861fd4ababf78c59a01d980303415e75c3b8047

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page