The user wants a "blue/green secrets rotation drill."
This involves creating a procedure (a drill or runbook) for rotating secrets (passwords, API keys, certificates) in a Blue/Green deployment architecture.
Key components required:
- Cutover Steps: How to switch from the old secrets (Blue) to the new secrets (Green).
- Rollbacks: How to revert if things go wrong.
- Verification: How to ensure the new secrets are working and the system is healthy.
Context & Assumptions:
- Architecture: Blue/Green usually implies two identical production environments. However, with secrets, it often means the application code supports two sets of credentials simultaneously, or the infrastructure allows traffic shifting while one environment uses new secrets and the other uses old ones.
- Interpretation A (Infrastructure Blue/Green): Blue Env has old secrets. Green Env is spun up with new secrets. Traffic shifts from Blue to Green. (Classic Blue/Green).
- Interpretation B (Application-level Secret Rotation): The running application supports active rotation, often by having a "primary" and "secondary" slot in memory or config, or by reloading config without downtime.
- Selection: I will focus on a hybrid approach which is most robust: The "Dual-Write/Dual-Read" or "Sidecar" strategy, but framed within a deployment lifecycle. Most modern "Blue/Green Secret Rotation" actually refers to the Vault or Platform capability where a "Green" version of the secret is generated, the app is told to use it, and if it fails, it falls back to "Blue".
- Actually, the most standard industry standard for "Blue/Green Secrets" is:
- App is using Secret V1 (Blue).
- We generate Secret V2 (Green).
- We update the App/Config to accept V2 alongside V1 (or switch traffic to a Green Environment using V2).
- Verification.
- Revoke V1.
Let's structure this as a "Drill Runbook" – actionable steps for an SRE or DevOps team.
Structure:
- Objective: Clear goal (rotate credentials with zero downtime).
- Prerequisites: What is needed before starting (access, tools, monitoring).
- Phase 1: Preparation (The "Green" Secret Generation): creating the new secret without killing the old one.
- Phase 2: Deployment/Cutover (The Switch): Getting the app to use the new secret.
- Phase 3: Verification (Sanity Check): Proving it works.
- Phase 4: Cleanup (Deprecating "Blue"): Deleting the old secret.
- Phase 5: Rollback Plan (The "Oh No" Button): What to do if Phase 2/3 fails.
Specific Details to Flesh Out:
- Database Rotation: This is the hardest one. Usually involves creating a new user or updating the password.
- Strategy: Create
user_new. Grant perms. Update app config to user_new. Restart/Reload app. Verify. Drop user_old.
- API Keys: Easier. Generate new key. Update config. Deploy. Disable old key.
- The "Blue/Green" Terminology in Secrets: Some secret managers (like AWS Secrets Manager or HashiCorp Vault) allow versioning.
- Step: Create Version 2 (Green).
- Step: App pulls "Latest" or "Green" label.
- Step: If fail, point back to Version 1 (Blue).
Let's refine the "Blue/Green" aspect for the user.
- Scenario: We have a Production Database.
- Current State: App uses DB User
app_service_blue.
- Drill: Rotate to
app_service_green.
- Why? Because simply changing the password on
app_service_blue creates a race condition where the app crashes before it can pull the new config. By having two users (Blue and Green), we can swap seamlessly.
Drafting the Steps:
- Step 0: Prereqs. Monitoring dashboards, logs, access to DB, access to Secret Manager.
- Step 1: Generate Green. Create new user/key.
- Step 2: Inject Green. Update Secret Manager.
- Step 3: Propagate. Trigger a rolling restart or config reload.
- Step 4: Verify. Check logs for "Access Denied".
- Step 5: Revoke Blue. (Optional post-verification).
Rollback:
- If the app crashes, switch config back to "Blue" credentials and restart.
Verification:
- Synthetic transactions (canary tests).
- Log analysis (looking for auth errors).
- Connectivity checks.
Refining the Output Format:
Use a structured Runbook format. Bold headers, code blocks for commands (generic/pseudo), and a clear distinction between the phases.
Self-Correction during drafting: Make sure to distinguish between Infrastructure Blue/Green (swapping servers) and Secret Blue/Green (swapping credentials). The user specifically asked for "Secrets Rotation Drill". I will focus on the Credential Swapping pattern (often called the "Leashed" or "Two-User" rotation strategy).
The Strategy:
- Blue (Current): Active credentials.
- Green (New): Generated credentials.
- Cutover: Update App to use Green.
- Rollback: Fallback to Blue.
I will provide a specific example for a Database credential rotation, as that is the most critical and common use case, but mention API keys as well.
Outline:
- Scenario: Web App -> Database.
- Concept: The "Alias" pattern (Blue user vs Green user).
- Drill Execution Steps:
- Phase 1: Provisioning (Create Green).
- Phase 2: Publication (Update Vault/K8s).
- Phase 3: Cutover (Reload/Restart).
- Phase 4: Verification.
- Phase 5: Revocation (Delete Blue).
- Rollback Procedure.
- Verification Checklist.
Let's write this out. I'll ensure the tone is professional and operationally focused. I will add a specific section on why this specific method works (zero downtime).
This drill documents the procedure for rotating secrets (e.g., Database Credentials, API Keys) using a Blue/Green strategy.
In this context, "Blue" represents the current active secret, and "Green" represents the newly generated secret. This approach allows for a zero-downtime rotation by ensuring the application is configured to accept both old and new credentials during the transition window.
Prerequisites
- Orchestration Tool: Kubernetes, HashiCorp Vault, or AWS Secrets Manager.
- Dual-Auth Capability: The target system (e.g., Postgres, Redis) must support multiple active credentials or simultaneous connections for a brief period.
- Monitoring: Real-time logs and error-rate dashboards (e.g., Datadog, Splunk).
Phase 1: Preparation (The "Green" Generation)
Objective: Create a new credential set (Green) without disrupting the existing (Blue) set.
- Generate New Secret:
- Create a new password/key (Green).
- Do not overwrite the existing secret (Blue).
- Store as Version 2:
- Store the Green secret in the vault/config map as
DB_PASSWORD_GREEN or version v2.
- Apply "Green" to Infrastructure (Write-only):
- Action: Run a migration script to add the Green credential to the downstream system (e.g.,
CREATE USER app_user_green ...).
- Verify: Ensure the Green user exists and has correct read/write permissions.
- Note: The application is still using Blue.
Phase 2: The Cutover (Activate Green)
Objective: Switch the application logic to use the Green secret.
Step 2.1: Config Injection / Restart
- Action: Update the application environment variables or secrets manager reference to point to the Green secret.
- K8s Example: Update the Deployment to reference the new secret name or key.
- Rolling Restart: Trigger a rolling restart to propagate the new environment variable.
- Why this is Blue/Green: Old pods continue running with Blue secrets. New pods spin up with Green secrets. Both sets of pods coexist momentarily.
Step 2.2: Immediate Smoke Test
- Execute a synthetic transaction (e.g., "Ping DB") to ensure the new pods can authenticate.
Phase 3: Verification & Soak
Objective: Ensure Green is stable before destroying Blue.
Drill Checklist:
- Check Auth Logs: Verify no
401 Unauthorized or Access Denied errors in the application logs.
- Check DB Connections: Verify active connections are shifting from
app_user_blue to app_user_green.
- Latency Check: Ensure query latency hasn't spiked due to connection pool exhaustion.
- Orphan Check: Ensure no old pods are stuck in a
CrashLoopBackOff state trying to use the Blue secret.
Phase 4: Rollback Procedure (The "Panic Button")
Trigger: Authentication errors spike, or the Green credential fails to connect.
- Stop Deployment:
- Halt the rolling update immediately.
kubectl rollout pause deployment/my-app
- Revert Config:
- Change the environment variable pointer back to the Blue secret (
DB_PASSWORD_BLUE).
- Rollback Release:
kubectl rollout undo deployment/my-app
- Verification:
- Watch logs to confirm pods are successfully authenticating with Blue again.
- Note: Because we haven't deleted Blue yet, rollback is instantaneous.
Phase 5: Deprecation (Cleanup Blue)
Trigger: Green has been stable for a defined period (e.g., 15 minutes or 24 hours depending on policy).
- Revoke Blue Credential:
- Action: Run a script to revoke the Blue credential from the downstream system.
- SQL Example:
DROP USER app_user_blue; or REVOKE ALL PRIVILEGES...
- Delete Blue Secret:
- Remove the Blue secret from the Secrets Manager/Vault.
- Final Verification:
- Check logs for any delayed services attempting to use Blue (should result in errors, confirming the secret is truly dead).
Drill Run Sheet (Example: Postgres Credential Rotation)
| Step | Action | Command / Tool | Expected Result | Status |
|---|
| 1 | Generate | Vault CLI / Python Script | New PW generated locally | [ ] |
| 2 | Provision User | psql -c "CREATE USER app_green..." | User created in DB | [ ] |
| 3 | Update App Spec | kubectl set env deployment/app DB_USER=app_green | Rolling restart initiated | [ ] |
| 4 | Monitor Logs | kubetail app | No 5xx errors, DB connects success | [ ] |
| 5 | Rollback (Test) | kubectl rollout undo deployment/app | Reverts to app_blue successfully | [ ] |
| 6 | Re-Cutover | kubectl set env deployment/app DB_USER=app_green | Back to Green | [ ] |
| 7 | Cleanup | psql -c "DROP USER app_blue" | Blue user removed | [ ] |
Key Success Criteria for the Drill
- Zero Downtime: The application layer remained responsive throughout the restart.
- No Data Leak: The Blue credential was never deleted before the Green credential was verified.
- Rollback Speed: The team demonstrated the ability to revert to the Blue secret in under 60 seconds.