How to Set Up API Key Rotation for OpenClaw Teams
Shared API keys are a security risk. If one team member leaves or a key is leaked, the entire team is compromised. This guide shows how to implement per-user API keys with automated rotation, emergency revocation, and usage tracking for OpenClaw teams.
Why This Is Hard to Do Yourself
These are the common pitfalls that trip people up.
Shared key vulnerability
One leaked key compromises the entire team. Rotation requires coordinating with every user simultaneously.
Zero-downtime rotation
Keys must rotate without breaking active sessions or requiring manual intervention from users
Emergency revocation
When a key is compromised, you need to revoke it instantly without waiting for the next rotation cycle
Usage attribution
With shared keys, you can't track which team member caused high usage or policy violations
Step-by-Step Guide
Audit current API key usage
Identify all places where API keys are used.
# Check current OpenClaw configuration:
grep -r "ANTHROPIC_API_KEY" ~/.openclaw/
grep -r "api_key" ~/.openclaw/config/
# List users and their current access:
openclaw admin users list
# Check for shared keys in environment variables:
env | grep API_KEYSet up key management system
Use a secret manager to store and rotate keys.
# In config/keys/manager.yaml:
key_management:
provider: vault # or "aws-secrets", "azure-keyvault"
vault:
url: https://vault.example.com
auth_method: token
path: secret/openclaw/api-keys
rotation:
enabled: true
schedule: "0 0 * * 0" # Every Sunday at midnight
overlap_period: 7d # Both old and new keys work for 7 days
notify_users: true
revocation:
immediate: true
grace_period: 0sWarning: Without an overlap period, rotating keys will break active sessions. Set `overlap_period` to at least 1 day to allow users to update their local configurations.
Configure per-user keys
Assign unique API keys to each team member.
# Create per-user keys:
openclaw admin keys create \
--user alice@example.com \
--scope "read,write" \
--expires-in 90d
openclaw admin keys create \
--user bob@example.com \
--scope "read" \
--expires-in 30d
# In config/auth/users.yaml:
users:
- email: alice@example.com
key_id: key_alice_abc123
scopes: [read, write]
quota:
daily_tokens: 1000000
monthly_cost_limit: 100.00
- email: bob@example.com
key_id: key_bob_def456
scopes: [read]
quota:
daily_tokens: 500000
monthly_cost_limit: 50.00Implement automated rotation schedule
Configure automatic key rotation.
# In config/keys/rotation.yaml:
rotation_policy:
frequency: 90d
rotation_window: 7d # Keys work during overlap
notifications:
- type: email
recipients: [team@example.com]
notify_before: 7d
- type: slack
webhook: https://hooks.slack.com/services/YOUR/WEBHOOK
notify_before: 1d
automation:
enabled: true
rotate_on_schedule: true
require_manual_approval: false
# Set up cron job for rotation:
# In /etc/cron.d/openclaw-rotation:
0 0 * * 0 /opt/openclaw/bin/rotate-keys --config /etc/openclaw/rotation.yamlSet up emergency revocation
Enable instant key revocation for security incidents.
# Revoke a compromised key immediately:
openclaw admin keys revoke \
--key-id key_alice_abc123 \
--reason "Key leaked in GitHub commit" \
--notify-user
# Revoke all keys for a user:
openclaw admin keys revoke-user \
--email bob@example.com \
--reason "Employee departed"
# In config/keys/revocation.yaml:
revocation:
instant_revoke: true
grace_period: 0s
triggers:
- type: suspicious_usage
threshold: 10x_normal_rate
action: auto_revoke
- type: geographic_anomaly
action: alert_adminWarning: Emergency revocation with zero grace period will immediately break active sessions. Use this only for confirmed security incidents.
Configure key usage monitoring
Track usage per key to identify anomalies.
# In config/monitoring/keys.yaml:
key_monitoring:
enabled: true
metrics:
- type: request_count
per: user
interval: 1h
- type: token_usage
per: user
interval: 1h
- type: error_rate
per: user
interval: 1h
alerts:
- metric: request_count
threshold: 1000
window: 1h
action: notify_admin
- metric: token_usage
threshold: 100000
window: 1h
action: throttle
dashboard:
url: https://grafana.example.com/openclaw-keys
refresh: 30s
# View usage per user:
openclaw admin keys usage --user alice@example.com --range 7d
# Export usage report:
openclaw admin keys report --format csv --output usage.csvKey Rotation Is Critical But Complex
Per-user keys, automated rotation, emergency revocation, usage tracking โ securing API access for teams requires careful planning and implementation. Our security experts set up production-grade key management for OpenClaw teams.
Get matched with a specialist who can help.
Sign Up for Expert Help โ