HashiCorpVaultProvider¶
HashiCorp Vault secret provider (KV v2).
- class scamander.secrets.vault.HashiCorpVaultProvider(vault_addr: str | None = None, vault_role: str | None = None, default_mount: str = 'secret')¶
Bases:
SecretProviderRetrieve secrets from a self-hosted HashiCorp Vault KV v2 store.
Designed for Kubernetes-based Spark workloads. Authentication is tried in this order:
Kubernetes service-account JWT — when the pod has a bound service account its JWT is read from
/var/run/secrets/kubernetes.io/serviceaccount/tokenand exchanged for a Vault token via the Kubernetes auth method.``VAULT_TOKEN`` environment variable — for local development with
vault server -devor CI pipelines that inject a token directly.
Secrets must be stored in KV v2 with a single
valuefield:vault kv put secret/database/pg-password value=hunter2
- Parameters:
vault_addr – Vault server address. Defaults to the
VAULT_ADDRenvironment variable, falling back to"http://vault:8200".vault_role – Vault role used for Kubernetes auth. Defaults to the
VAULT_ROLEenvironment variable, falling back to"scamander".default_mount – Default KV mount path used when
vaultis not passed toget_secret(). Defaults to"secret".
Example:
provider = HashiCorpVaultProvider() password = provider.get_secret("database/pg-password") # Override mount per-call: token = provider.get_secret("api/token", vault="infrastructure")
- get_secret(secret_name: str, vault: str | None = None) str¶
Retrieve a secret from HashiCorp Vault KV v2.
- Parameters:
secret_name – Path to the secret within the KV mount (e.g.
"database/pg-password").vault – KV mount path. Overrides
default_mountset in the constructor.
- Returns:
The string stored under the
valuekey at the given path.- Raises:
ImportError – When
hvacis not installed.RuntimeError – When neither Kubernetes JWT nor
VAULT_TOKENis available.