Secrets Management for OpenClaw
A dedicated secrets manager is the gold standard for storing API keys, tokens, and credentials. Unlike environment variables, a secrets manager provides access auditing, automatic rotation, fine-grained access control, and centralized management.
Why a Dedicated Secrets Manager?
| Feature | Env Variables | .env Files | Secrets Manager |
|---|---|---|---|
| Access audit log | ❌ | ❌ | ✅ |
| Automatic rotation | ❌ | ❌ | ✅ |
| Fine-grained access control | ❌ | ❌ | ✅ |
| Centralized management | ❌ | ❌ | ✅ |
| No plaintext on disk | ✅ | ❌ | ✅ |
| Compliance support | Partial | ❌ | ✅ |
| Setup complexity | Simple | Simple | Moderate |
HashiCorp Vault
Vault is the most popular open-source secrets manager and supports dynamic secrets, automatic rotation, and multiple auth methods:
Install and Configure Vault
# Install Vault
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install vault
# Start dev server (for testing only!)
vault server -dev
# Store OpenClaw secrets
export VAULT_ADDR="http://127.0.0.1:8200"
vault kv put secret/openclaw \
openai_api_key="sk-proj-..." \
anthropic_api_key="sk-ant-..."Configure OpenClaw to Use Vault
# config.yaml
secrets:
provider: vault
vault:
address: "https://vault.example.com:8200"
auth_method: token # token | kubernetes | approle | aws
token: "${VAULT_TOKEN}"
path: "secret/data/openclaw"
field_map:
OPENAI_API_KEY: "openai_api_key"
ANTHROPIC_API_KEY: "anthropic_api_key"Dynamic Secrets (Auto-Rotating)
# Vault can generate short-lived, auto-rotating credentials
# (for databases, cloud credentials — not AI API keys which don't support this)
vault write database/roles/openclaw \
db_name=mydb \
creation_statements="CREATE USER..." \
default_ttl="1h" \
max_ttl="24h"AWS Secrets Manager
# Create secrets
aws secretsmanager create-secret \
--name "openclaw/openai-api-key" \
--description "OpenAI API key for OpenClaw agents" \
--secret-string "sk-proj-..."
aws secretsmanager create-secret \
--name "openclaw/anthropic-api-key" \
--secret-string "sk-ant-..."# config.yaml
secrets:
provider: aws_secretsmanager
aws:
region: "us-east-1"
secrets:
OPENAI_API_KEY:
secret_name: "openclaw/openai-api-key"
ANTHROPIC_API_KEY:
secret_name: "openclaw/anthropic-api-key"Use an IAM role (not an IAM user) for EC2/ECS deployments to avoid managing static credentials:
// IAM policy to allow OpenClaw to read its secrets
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": ["secretsmanager:GetSecretValue"],
"Resource": "arn:aws:secretsmanager:us-east-1:123456789:secret:openclaw/*"
}]
}Doppler
Doppler provides a simple SaaS secrets manager with a great developer experience:
# Install Doppler CLI
curl -Ls --tlsv1.2 --proto "=https" --retry 3 https://cli.doppler.com/install.sh | sh
# Login
doppler login
# Set up a project
doppler setup
# Inject secrets into OpenClaw
doppler run -- openclaw run "your task"
# In CI/CD
doppler run -- openclaw start --daemonAzure Key Vault
# Create a Key Vault
az keyvault create \
--name "openclaw-secrets" \
--resource-group "my-rg" \
--location "eastus"
# Store a secret
az keyvault secret set \
--vault-name "openclaw-secrets" \
--name "openai-api-key" \
--value "sk-proj-..."secrets:
provider: azure_keyvault
azure:
vault_url: "https://openclaw-secrets.vault.azure.net/"
# Uses DefaultAzureCredential (managed identity, env, CLI)
secrets:
OPENAI_API_KEY: "openai-api-key"
ANTHROPIC_API_KEY: "anthropic-api-key"Kubernetes Secrets + External Secrets Operator
# Install External Secrets Operator
helm repo add external-secrets https://charts.external-secrets.io
helm install external-secrets external-secrets/external-secrets -n external-secrets --create-namespace# ExternalSecret resource
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
name: openclaw-secrets
spec:
refreshInterval: 1h
secretStoreRef:
name: vault-backend
kind: SecretStore
target:
name: openclaw-secrets
data:
- secretKey: OPENAI_API_KEY
remoteRef:
key: secret/openclaw
property: openai_api_keyEmergency Procedures (Leaked Secret Response)
- Revoke immediately — go to the provider dashboard and revoke the compromised key
- Generate new key — create a replacement key
- Update secrets manager — update the stored secret
- Deploy update — ensure all running agents pick up the new key
- Review audit logs — check for unauthorized usage with the old key
- Post-mortem — document how the key was exposed and prevent recurrence
What's Next
- Security Overview — Back to the full security picture
- API Key Best Practices — Key rotation and scoping
- Docker Deployment — Inject secrets in containerized deployments
Secrets Management Patterns
The simplest safe pattern for small deployments is environment-variable injection from a secrets manager at container startup — the secret never exists on disk, only in memory for the lifetime of the process. This works well for up to a few dozen secrets. As the number of secrets grows or as you need fine-grained access control and audit logging of secret access, move to a dedicated secrets manager like Vault, AWS Secrets Manager, or Google Secret Manager. These services provide secret versioning, automatic rotation, access policies, and detailed access logs — capabilities that are impractical to replicate with environment variables alone.
For multi-agent deployments, use unique credentials per agent, not shared credentials. When you have ten agents sharing one API key, a compromise of any one agent exposes all of their operations. With per-agent credentials, you can immediately revoke access for the compromised agent, audit exactly what it accessed, and leave all other agents unaffected. The operational overhead of managing more credentials is justified by the security and incident response benefits.
Emergency revocation is a critical capability to plan for before you need it. Document the exact steps required to revoke each type of credential and how long it takes to take effect. Test the revocation process before an incident — discovering that key revocation takes twenty minutes to propagate across a CDN during an active incident is far more stressful than discovering it during a drill. A documented and tested revocation runbook is one of the highest-value security investments for an AI agent deployment.