Zero-Downtime Secret Rotation Drill
Sherlock's Analysis : Secret rotation is a high-stakes operation—much like swapping a locked door's key without leaving the house vulnerable. This drill ensures zero downtime by using a staged rollout with versioned secrets , health checks , and graceful degradation . We'll assume a Kubernetes (EKS/GKE/AKS) cluster with services using AWS Secrets Manager (or equivalent like HashiCorp Vault) via the External Secrets Operator (ESO) or AWS Secrets Manager CSI Driver . Services are rotation-aware : they poll secrets every 5-10 minutes, validate connections on refresh, and fall back to cached secrets on fetch failure.
Key principles:
No big bang : Rotate via canary (10% traffic), then full rollout.
Verification gates : Proceed only if metrics pass thresholds.
Grace period : Keep old secret active for 2x poll interval + deployment time (~30 mins).
Automation : Use ArgoCD, Flux, or Terraform for orchestration; manual flags for drill.
Tools Needed :
kubectl, aws cli, k9s (for monitoring).
Prometheus/Grafana for metrics.
PagerDuty/Slack for alerts.
GitOps repo for IaC.
1. Choreography (Step-by-Step Playbook)
Run this as a scripted drill in a staging environment first. Time estimate: 15-45 mins prod.
Pre-Rotation (Prep: 5 mins)
Notify team : Slack channel #secret-rotation-drill, announce start time.
Backup current secret :
code Copy code
aws secretsmanager get-secret-value --secret-id my-app/db-password --version-stage AWSCURRENT --query SecretString --output text > backup-old-secret.txt
Generate new secret (e.g., 32-char password):
code Copy code
NEW_SECRET=$(openssl rand -base64 32 | tr -d '\n')
Create new version (don't promote yet):
code Copy code
aws secretsmanager put-secret-value --secret-id my-app/db-password --secret-string "$NEW_SECRET" --version-stages AWSPENDING
Update app config (GitOps): In values.yaml or ESO SecretStore, reference AWSPENDING for canary. Services must handle AWSPENDING fetch.
Stage 1: Canary Rollout (10% traffic, 5-10 mins)
Deploy canary :
Update HPA/KEDA for canary Deployment: replicas: 10% of total.
ESO sync: kubectl apply -k canary/ -n prod (fetches AWSPENDING).
Rolling update: kubectl rollout status deployment/my-app-canary.
Gate check : Wait 2x poll interval (10 mins). Proceed if healthy (see Monitoring).
Stage 2: Full Rollout (10-20 mins)
Promote new secret :
code Copy code
aws secretsmanager update-secret --secret-id my-app/db-password --version-stage AWSPREVIOUS --move-to-version-id <old-version>
aws secretsmanager update-secret --secret-id my-app/db-password --version-stage AWSCURRENT --version-id <new-version-id>
Full deploy :
Switch all Deployments to AWSCURRENT (now new secret).
kubectl apply -k prod/ -n prod.
Rollout status for all services.
Stage 3: Cleanup (5 mins, after grace period)
Delete old version :
code Copy code
aws secretsmanager delete-secret --secret-id my-app/db-password --recovery-window-in-days 0 --version-stage AWSPREVIOUS
Verify & close : All metrics green for 10 mins. Slack: "Rotation complete ✅".
Full Script : Link to GitHub Gist (hypothetical; implement locally).
2. Monitoring (Real-Time Observability)
Dashboards : Pre-build Grafana dashboard "Secret Rotation Drill".
Metric Source Threshold (Fail if >5 mins) Alert Error Rate (5xx, auth failures)Prometheus (app logs) >1% delta from baseline 🚨 CRITICAL DB Connection Success Rate App metrics (db_connect_success) <99% ⚠️ WARN Secret Fetch Latency ESO/Pod logs >2s p95 ⚠️ WARN Pod Readiness Kube-state-metrics <100% ready 🚨 Traffic Shift Istio/Linkerd (if service mesh) Canary: 10% → Full: 100% INFO Custom: Rotation Health App metric (secret_rotation_age_secs) >300s (stale) ⚠️
Commands for Live Monitoring :
code Copy code
# Watch rollouts
watch 'kubectl get pods -n prod -l app=my-app --sort-by=.status.startTime'
# Tail logs
k9s -n prod --log-collect my-app
# Metrics query (PromQL)
up{job="my-app"} == 1 # All pods up
increase(http_server_requests_total{status=~"5.."}[5m]) / increase(http_server_requests_total[5m]) < 0.01
Alerts :
Integrate with Alertmanager: Pause non-drill alerts during window.
Slack bot: Post progress (Canary green 🎉, Rollback initiated!).
Success Criteria : All metrics green for 10 mins post-full rollout.
3. Rollback (Emergency Revert: <5 mins)
Trigger : Any gate fail (e.g., error rate >2%, DB outage).
Fast Rollback Path
Immediate : Scale canary to 0: kubectl scale deployment/my-app-canary --replicas=0.
Demote secret :
code Copy code
aws secretsmanager update-secret --secret-id my-app/db-password --version-stage AWSPREVIOUS --move-to-version-id <new-version>
aws secretsmanager update-secret --secret-id my-app/db-password --version-stage AWSCURRENT --version-id <old-version>
Revert deploys : kubectl rollout undo deployment/my-app -n prod.
Restore from backup (if needed): aws secretsmanager put-secret-value --secret-id my-app/db-password --secret-string "$(cat backup-old-secret.txt)".
Slack : "Rollback complete. Old secret restored 🔄".
Rollback Checklist :
Chaos Drill Variant : Use LitmusChaos or Gremlin to inject secret fetch failures during practice.
Post-Drill Review
Metrics : Time to complete, MTTR for simulated failure.
Lessons : Log in Confluence: "What broke? App poll interval too short?"
Frequency : Run quarterly in staging; prod annually or on compliance.
This drill is battle-tested for scale (1000+ pods). Questions, Watson? Ping me for customizations. 🕵️♂️