Skip to content

Vault policies

HashiCorp Vault is the recommended secret store for Alquimia Platform. Well-designed Vault policies let the runtime resolve credentials with the least privilege required, support rotation, and keep audit records for every secret access.

The runtime can authenticate to Vault in several ways:

MethodUse case
TokenLong-lived static token; suitable for local development, discouraged in production.
KubernetesRuntime pods authenticate using projected service-account tokens.
JWTWorkloads or agents authenticate using SPIFFE JWT-SVIDs.

Production deployments should use Kubernetes auth for runtime services and JWT auth for per-agentspace agent identities.

The runtime uses a pluggable secret resolver selected by ALQUIMIA_REGISTRY_SECRET_RESOLVER:

ResolverValueUse case
Vaultvault (default)Production; dynamic credentials, audit logging, central rotation
EnvironmentenvLocal development, CI tests, or air-gapped environments

When ALQUIMIA_REGISTRY_SECRET_RESOLVER=vault, the runtime reads:

VariableDescription
VAULT_ADDRFull Vault URL including scheme and port, for example https://vault.internal:8200 (used verbatim)
VAULT_MOUNT_POINTKV v2 mount point (default secret). cubbyhole does not work because it is a per-token store
VAULT_AUTH_METHODtoken (default), kubernetes, or jwt
VAULT_AUTH_ROLEVault role the resolver logs in with; required for kubernetes and jwt auth
VAULT_TOKENStatic token; only used with VAULT_AUTH_METHOD=token (local development)

With Kubernetes auth, the runtime’s own Vault client and the alquimia-core resolver log in separately: set both VAULT_K8S_ROLE (runtime) and VAULT_AUTH_ROLE (resolver), and mount a projected service-account token with audience vault (point VAULT_K8S_TOKEN_PATH at it). The static VAULT_TOKEN and the alquimia-vault Kubernetes Secret were removed from the manifests in favour of Kubernetes auth.

Secret references in agent specs are resolved to KV v2 paths based on their scope:

ScopeVault path
globalsecret/data/global/KEY
sharedsecret/data/{realm}/shared/KEY
localsecret/data/{realm}/local/{assistant_id}/KEY

REALM / {realm} is the agentspace_id.

When ALQUIMIA_REGISTRY_SECRET_RESOLVER=env, the runtime reads secret values directly from environment variables. Environment keys use the agentspace name and assistant ID to avoid collisions:

ScopeEnv keyPer-user env key
globalKEYAGENTSPACE_NAME__USER__USER_ID__KEY
sharedAGENTSPACE_NAME__KEYAGENTSPACE_NAME__USER__USER_ID__KEY
localAGENTSPACE_NAME__ASSISTANT_ID__KEYAGENTSPACE_NAME__ASSISTANT_ID__USER__USER_ID__KEY

AGENTSPACE_NAME is normalized for environment variables: uppercased, - and . become _, and a leading digit is prefixed with _. Segments are joined with __ so agentspace and assistant boundaries cannot collide after normalization.

Terminal window
export RESPONSE_PROVIDER_API_KEY="sk-..." # global
export MYSPACE__RESPONSE_PROVIDER_API_KEY="sk-..." # shared
export MYSPACE__SUPPORT_BOT__RESPONSE_PROVIDER_API_KEY="sk-..." # local
# Per-user values for user-scoped secrets
export MYSPACE__USER__ALICE__RESPONSE_PROVIDER_API_KEY="sk-..." # shared, user alice
export MYSPACE__SUPPORT_BOT__USER__ALICE__RESPONSE_PROVIDER_API_KEY="sk-..." # local, user alice

The authenticated user_id is propagated through secret resolution. The user’s unique identifier (sub for OIDC/JWT, API-token subject otherwise) is the canonical principal.subject. Per-user resolution is opt-in per secret via user_scoped: true (CLI: alquimia registry secrets add KEY --user-scoped).

  • For a user-scoped secret, supplying a user_id reads only the per-user value and fails closed (SecretRefError) if no per-user value is set. There is no fallback to the scope default.
  • For a non-user-scoped secret, any user_id is ignored and the scope default is always used. Writing or deleting a per-user value for a non-user-scoped secret raises an error rather than touching the default.
  • global secrets do not support per-user overrides.

For an agent to receive the caller identifier at inference time, set resolve_acting_user_id: true in the agent spec. The runtime then passes acting_user_id to tools, prompts, and secret resolution.

ScopePer-user Vault path
sharedsecret/data/{realm}/shared/users/{user_id}/KEY
localsecret/data/{realm}/local/{assistant_id}/users/{user_id}/KEY

This lets multi-tenant deployments store per-user credentials without changing agent specs, while preventing accidental fallback to a shared credential when a user-specific one is missing.

Terminal window
# Production (Kubernetes auth)
export ALQUIMIA_REGISTRY_SECRET_RESOLVER=vault
export VAULT_ADDR=https://vault.internal:8200
export VAULT_MOUNT_POINT=secret
export VAULT_AUTH_METHOD=kubernetes
export VAULT_K8S_ROLE=alquimia-runtime-master
export VAULT_AUTH_ROLE=alquimia-runtime-master
export VAULT_K8S_TOKEN_PATH=/var/run/secrets/vault/service-account/vault-token
# Local development (agentspace=myspace, assistant=support-bot)
export ALQUIMIA_REGISTRY_SECRET_RESOLVER=env
export MYSPACE__SUPPORT_BOT__RESPONSE_PROVIDER_API_KEY="sk-..."

A good Vault policy for Alquimia Platform follows these principles:

  • Scope by role — masters need broader registry access than workers.
  • Scope by agentspace — workers serving one agentspace should not read secrets from another.
  • Use dynamic credentials — prefer Vault database secrets engines for PostgreSQL and Redis over static passwords.
  • Avoid broad wildcards — grant access only to the paths each service actually needs.
  • Log everything — enable audit devices so every read and write is recorded.

At minimum, separate the runtime into two service roles:

RoleTypical access
MasterRead/write registry and agentspace secrets, manage identity provisioning, lease its own database credentials.
WorkerRead global secrets and the agentspace it serves, lease its own database credentials, no registry write access.

When agentspace isolation is required, generate a dedicated worker policy for each agentspace or use SPIFFE-based JWT roles created by the agentspace provisioner.

When AGENTSPACE_PROVISIONING_ENABLED=true, the runtime master creates a scoped Vault ACL policy and three JWT auth roles per agentspace:

policy: as-{agentspace_id}-agents
roles: as-{agentspace_id}-reader
as-{agentspace_id}-editor
as-{agentspace_id}-operator

Each role is bound to a SPIFFE ID such as spiffe://alquimia.ai/agentspace/{agentspace_id}/tier/{reader|editor|operator}. Agents authenticate to Vault with their JWT-SVID and receive a token scoped to their agentspace and role tier. This is the recommended way to enforce least-privilege secret access for agent identities.

Configure the Vault JWT auth mount path with AGENTSPACE_PROVISIONING_VAULT_JWT_AUTH_PATH (default jwt). See Runtime configuration and Authorization policies for the full Zero Trust flow.

Vault database secrets engines can issue short-lived PostgreSQL and Redis credentials. The runtime leases these credentials at startup, renews them while in use, and revokes them on shutdown. This reduces the value of stolen credentials and removes the need for manual rotation.

When using dynamic credentials:

  • Create a least-privilege database role for the runtime.
  • Set TTLs that match your compliance requirements without causing excessive churn.
  • Ensure the database user created by Vault can be dropped cleanly when the lease expires.

Some credentials, such as provider API keys and S3 access keys, do not support dynamic issuance. Store these as KV v2 secrets and rotate them manually or through an automated pipeline. Keep the secret reference name stable so agent specs do not need to change during rotation.

Before the runtime starts in production:

  1. Enable the required secrets engines: KV v2, database, and any others you need.
  2. Enable the Kubernetes and JWT auth backends.
  3. Write a master policy scoped to registry, identity provisioning, and its own credentials.
  4. Write worker policies scoped to the agentspaces they serve.
  5. Configure Kubernetes auth roles bound to the runtime service account.
  6. Configure the JWT auth backend with the SPIFFE trust-domain keys.
  7. Populate KV secrets for static credentials.
  8. Set the runtime environment to use Kubernetes auth (VAULT_AUTH_METHOD=kubernetes) and the correct Vault role in both VAULT_K8S_ROLE and VAULT_AUTH_ROLE.