Python SDK for Hush secret access via SPIFFE mTLS
Project description
hush-am-sdk-python
Python SDK for fetching secrets from the Hush access-manager via SPIFFE mTLS.
Installation
pip install hush-am-sdk
Configuration
The client reads the following environment variables (all populated by the mufasa injector at runtime — there are no constructor overrides):
| Variable | Default | Description |
|---|---|---|
_HUSH_INJECTOR_SERVER_ADDRESS |
hush-am-access-manager.hush-security.svc:8743 |
Access-manager address (https:// is added if no scheme is present) |
_HUSH_INJECTOR_SPIRE_AGENT_SOCKET_PATH |
unix:///tmp/spire-agent/public/api.sock |
SPIRE agent socket |
_HUSH_INJECTOR_TRUST_DOMAIN |
(required) | SPIFFE trust domain. Used to validate the server's identity as spiffe://<trust-domain>/hush/simba/server |
_HUSH_INJECTOR_POLICY_SNAPSHOT |
(required to call get_secret) |
Base64 policy snapshot |
Usage
from hush import HushClient
with HushClient() as hush:
# Fetch a secret's full key-value map
creds = hush.get_secret("user-a-postgres")
print(creds["username"], creds["password"])
# Fetch a single field
password = hush.get_secret_field("user-a-postgres", "password")
Module-level convenience helpers backed by a singleton client are also available:
from hush import get_secret, get_secret_field
creds = get_secret("user-a-postgres")
password = get_secret_field("user-a-postgres", "password")
Pass an optional bearer token for user-claims filtering:
hush.get_secret("user-a-postgres", token=user_jwt)
Error handling
All SDK errors derive from HushError. Catch the base class for a generic
fallback, or the specific subclasses where the caller can do something useful:
| Exception | Raised when |
|---|---|
HushConfigError |
A required _HUSH_INJECTOR_* env var is missing |
HushSpiffeError |
SPIRE Workload API unreachable or no SVID issued |
HushAuthError |
mTLS handshake failed or server SPIFFE ID mismatch |
HushNetworkError |
Connection / timeout reaching the access-manager |
HushSecretNotFoundError |
Secret missing, or caller's SPIFFE ID has no policy granting access (simba returns 404 for both) |
HushFieldNotFoundError |
Secret exists but the requested field does not |
HushBadRequestError |
Server returned 400 — deployment misconfiguration, not caller-recoverable |
HushServerError |
Server returned 5xx; .status_code and .message available |
from hush import HushClient, HushSecretNotFoundError, HushError
try:
with HushClient() as hush:
creds = hush.get_secret("user-a-postgres")
except HushSecretNotFoundError:
... # secret missing or no access
except HushError as e:
... # any other SDK failure
Running the example
examples/get_postgres_creds.py shows a minimal end-to-end use of the SDK.
It needs a Hush-instrumented runtime to actually fetch a secret — it cannot
run from your laptop because there is no local SPIRE agent.
Required runtime conditions:
- A SPIRE agent reachable at
$_HUSH_INJECTOR_SPIRE_AGENT_SOCKET_PATH(provided by your cluster's SPIRE deployment). - The mufasa admission controller has injected
$_HUSH_INJECTOR_POLICY_SNAPSHOTinto the pod — you do not set this manually. $_HUSH_INJECTOR_TRUST_DOMAINset to your deployment's trust domain.- A Hush policy named
postgres_credsattached to your workload's SPIFFE ID, withusername,password, andhostfields.
Steps inside such a pod:
# 1. Install the SDK
pip install -e /path/to/hush-am-sdk-python
# 2. Confirm the runtime env is populated (the injector usually does this)
echo $_HUSH_INJECTOR_TRUST_DOMAIN
echo $_HUSH_INJECTOR_SPIRE_AGENT_SOCKET_PATH
echo $_HUSH_INJECTOR_POLICY_SNAPSHOT
# 3. Run
python examples/get_postgres_creds.py
To try it out without standing up your own infrastructure, deploy as a
workload modeled on goat-apps/apps/hush-agent-demo/k8s/deployment.yaml —
the same admission-controller annotations, with the container running this
script.
Build & publish
The build and publish Makefile targets produce a wheel and upload it to
public PyPI:
# Build sdist + wheel into dist/
make build
# Build, then publish to PyPI (requires PyPI credentials in ~/.pypirc
# or TWINE_USERNAME / TWINE_PASSWORD env vars)
make publish
CI publishes automatically on v* tags via PyPI trusted publishing — see
.github/workflows/publish.yml.
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 hush_am_sdk-0.1.0.tar.gz.
File metadata
- Download URL: hush_am_sdk-0.1.0.tar.gz
- Upload date:
- Size: 21.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9b424c70b97cb95589f5924fc92172f666ad92e0847fd05c45d5ca772a47180
|
|
| MD5 |
50b067d845c734f97b8404571c725cac
|
|
| BLAKE2b-256 |
225f4e12144422f21690189b0a4e7452260e93cb491cf2d1c126ebc8b4b308e2
|
Provenance
The following attestation bundles were made for hush_am_sdk-0.1.0.tar.gz:
Publisher:
publish.yml on hushsecurity/hush-am-sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hush_am_sdk-0.1.0.tar.gz -
Subject digest:
e9b424c70b97cb95589f5924fc92172f666ad92e0847fd05c45d5ca772a47180 - Sigstore transparency entry: 1452090649
- Sigstore integration time:
-
Permalink:
hushsecurity/hush-am-sdk-python@ab93f4d2b12250aeb707a300a43b143183b131fa -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/hushsecurity
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ab93f4d2b12250aeb707a300a43b143183b131fa -
Trigger Event:
push
-
Statement type:
File details
Details for the file hush_am_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: hush_am_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3416503fcc5fb6e4317bab88f6d2c4aa75fbd0c506855e7d03bcccd3aa9063c
|
|
| MD5 |
f3ea809e4f476108d102f4ec4e1cb7d0
|
|
| BLAKE2b-256 |
a4f226c4958563a102e7b77179e0db847ac1cdf720012bdb5fc2e96d3568a79e
|
Provenance
The following attestation bundles were made for hush_am_sdk-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on hushsecurity/hush-am-sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hush_am_sdk-0.1.0-py3-none-any.whl -
Subject digest:
d3416503fcc5fb6e4317bab88f6d2c4aa75fbd0c506855e7d03bcccd3aa9063c - Sigstore transparency entry: 1452090763
- Sigstore integration time:
-
Permalink:
hushsecurity/hush-am-sdk-python@ab93f4d2b12250aeb707a300a43b143183b131fa -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/hushsecurity
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ab93f4d2b12250aeb707a300a43b143183b131fa -
Trigger Event:
push
-
Statement type: