Skip to main content

coreason-vault (The Safe)

License CI Status Code Style: Ruff Documentation

The centralized guardian of secrets for the CoReason platform.

coreason-vault manages secrets at rest and in memory, replacing legacy local encryption and unsafe environment variable practices with a robust, centralized Vault-based architecture.

Mission

  • Secure Retrieval: Fetch API keys and database credentials securely from HashiCorp Vault.
  • Key Rotation & Leases: Handle dynamic secrets with lease management.
  • Encryption as a Service (EaaS): Delegate encryption of sensitive user data to Vault's Transit Engine, ensuring the application never handles encryption keys.

Features

  • "The Safe" Philosophy: Application code never sees long-lived credentials or performs its own encryption.
  • Transit Engine Integration: Replaces local crypto.py by offloading encryption/decryption to Vault.
  • Just-in-Time Secrets: Fetches secrets on demand with caching (TTL ~60s) to prevent API hammering.
  • Dynamic Secrets: Supports retrieval of dynamic secrets with lease information.
  • Automated Authentication: Seamlessly handles AppRole (local/VM) and Kubernetes (Prod) authentication with auto-renewal.
  • Resilience: Built-in retries and circuit breaking for Vault connection issues.

Installation

pip install coreason-vault

Usage

from coreason_vault import VaultManager, VaultConfig
from coreason_vault.exceptions import SecretNotFoundError

# 1. Initialize
# Automatically reads configuration from environment variables:
# VAULT_ADDR, VAULT_ROLE_ID/SECRET_ID (or K8S Auth), etc.
config = VaultConfig()
vault = VaultManager(config)

# 2. Fetch Secret (KV Version 2)
try:
    # Fetches from 'secret/data/coreason/services/openai' (mount point defaults to 'secret')
    creds = vault.secrets.get("coreason/services/openai")
    print(f"Using API Key: {creds['api_key'][:4]}...")
except SecretNotFoundError:
    print("Fatal: OpenAI credentials missing")

# 3. Encrypt Sensitive Data (Transit Engine)
# The app never sees the encryption key. Vault handles the cryptography.
ciphertext = vault.cipher.encrypt(
    plaintext="Sensitive Patient Data",
    key_name="patient-data-key",
    context="user_123"  # Optional: Key derivation context for extra security
)
print(f"Stored in DB: {ciphertext}")
# Output example: vault:v1:QmF...

# 4. Decrypt Data
original_plaintext = vault.cipher.decrypt(
    ciphertext=ciphertext,
    key_name="patient-data-key",
    context="user_123"
)
print(f"Decrypted: {original_plaintext}")

Configuration

The library uses pydantic-settings to load configuration from environment variables.

Variable Description Default
VAULT_ADDR Required. The URL of the Vault server. -
VAULT_NAMESPACE The Vault namespace (Enterprise/Cloud). None
VAULT_ROLE_ID AppRole Role ID. None
VAULT_SECRET_ID AppRole Secret ID. None
VAULT_K8S_ROLE Kubernetes Role Name (for K8s auth). None
KUBERNETES_SERVICE_ACCOUNT_TOKEN K8s SA Token (injected by K8s). None
VAULT_MOUNT_POINT KV v2 Mount Point. secret
VAULT_VERIFY_SSL Verify SSL certificates. True
VAULT_TOKEN_TTL Token validation interval in seconds. 60

License

This software is licensed under the Prosperity Public License 3.0. Commercial use beyond a 30-day trial requires a separate license. See LICENSE for details.

Metadata

Release files for coreason-vault 0.3.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 coreason-vault 0.3.1
File Size Uploaded
coreason_vault-0.3.1.tar.gz 12.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for coreason-vault 0.3.1
File Interpreter ABI Platform
coreason_vault-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 29.8 kB

Release files / coreason_vault-0.3.1.tar.gz

Download URL coreason_vault-0.3.1.tar.gz
Size 12.4 kB
Tags Source
SHA-256 checksum
How to use checksums
04661d5170c92d84678de6b7dd5e57c2bec2b449ae2009d04741c70b612ad451
BLAKE2b-256 checksum
How to use checksums
14ee9b442c0d8fceb8ae8589dde6b4fd0dacd732456236fc515b39031ec9104e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 28, 2026.

Transparency log

Release files / coreason_vault-0.3.1-py3-none-any.whl

Download URL coreason_vault-0.3.1-py3-none-any.whl
Size 17.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4c9c6ea090918a9574433da699cb78bc638e8f246eee2e4d28aa5648f014b42b
BLAKE2b-256 checksum
How to use checksums
ab1f027860781eed6a8446aad7738fc0ceb77cbbd0a46b467fc2c3b12ada9043
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 28, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.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