A wrapper for handling HCP Vault Secrets on an app-by-app basis
Project description
hcp-vault-secrets-wrapper
Simple HCP Vault Secrets Wrapper library
Approach
- Simple HTTP client implementation in generic python
Required Variables
- Client ID and Client Secret: each application requires a unique client ID and secret. Keep these values secret.
- Client Org, App and Project IDs, which can be fetched from the secrets fetching URL provided by HCP:
- Example:
https://api.cloud.hashicorp.com/secrets/2023-11-28/organizations/XXXX/projects/YYYY/apps/ZZZZ/secrets:open- XXXX is the organization ID (a UUID)
- YYYY is the project ID (also a UUID)
- ZZZZ is the application ID (should be human-readble)
- Example:
Implementation
- Use the following pattern to setup an HCP Vault connection for an application
# Keep Secret
HCP_CLIENT_ID = getenv("HCP_CLIENT_ID") or None
HCP_CLIENT_SECRET = getenv("HCP_CLIENT_SECRET") or None
# Not Secret - get from HCP Vault app screen:
HCP_ORG_ID = getenv("HCP_ORG_ID") or None
HCP_PROJECT_ID = getenv("HCP_PROJECT_ID") or None
HCP_APP_ID = getenv("HCP_APP_ID") or None
# Setup secrets manage setup
secrets_mgr = HCPVaultClient(HCP_CLIENT_ID, HCP_CLIENT_SECRET, HCP_ORG_ID, HCP_PROJECT_ID, HCP_APP_ID)
# Fetch secrets
secrets_data = secrets_mgr.fetch_secrets() # Returns object with secrets from HCP
# Access static secrets:
some_secret = secrets_data["SOME_SECRET"]
# Access dynamic secrets and set environ variable
from os import environ
environ["AWS_ACCESS_KEY_ID"] = secrets_data["SOME_SECRET_AWS"]["values"]["access_key_id"]
environ["AWS_SECRET_ACCESS_KEY"] = secrets_data["SOME_SECRET_AWS"]["values"]["secret_access_key"]
environ["AWS_SESSION_TOKEN"] = secrets_data["SOME_SECRET_AWS"]["values"]["session_token"]
Refresh secrets
- The code contains two class variables that cache the secrets to avoid over-querying of secrets from HCP.
- By default, secrets are cached for 25 minutes (or can be controlled by the
refresh_timeout_minconstructor variable)
- By default, secrets are cached for 25 minutes (or can be controlled by the
- Call
fetch_secretsto either pull new secrets (if we exceed the refresh timeout) OR return the last cached secrets.
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 hcp_vault_secrets_wrapper-0.7.5.tar.gz.
File metadata
- Download URL: hcp_vault_secrets_wrapper-0.7.5.tar.gz
- Upload date:
- Size: 25.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22d3aa8654c7d56a7e33b92b0f4061880a5dce2a429d4685a7e824428c08f99c
|
|
| MD5 |
1bfaffec0a3e370b2f12990e180a248c
|
|
| BLAKE2b-256 |
bda5496d46e1c4057d7a0b80257fb76c8087af8157a9bbc54070c06a91eb75c3
|
File details
Details for the file hcp_vault_secrets_wrapper-0.7.5-py3-none-any.whl.
File metadata
- Download URL: hcp_vault_secrets_wrapper-0.7.5-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b52e9bcf08ef268f0bd4416769116adb3fa071925da112190b223f8c5c021ac9
|
|
| MD5 |
60126f0dc04dbb0393a537697b36367e
|
|
| BLAKE2b-256 |
de3f61e4a36324311afb200a98aea87b2fa5eec808b2199773ccf5ba395a8274
|