Manual Rotation Is Not Rotation
Every security policy says credentials should be rotated regularly. Every audit finding recommends shorter rotation periods. And in practice, most organizations rotate API keys only when they are compromised — which defeats the entire purpose of rotation.
The reason is straightforward: manual rotation is painful. It requires coordinating across services, updating configurations, restarting applications, and verifying that nothing breaks. For organizations with dozens of API keys across multiple services, manual rotation is a full-day project that nobody volunteers for.
Automated rotation solves this by making the process reliable, repeatable, and invisible to operations teams. Keys rotate on schedule without human intervention and without service interruption.
The Rotation Architecture
Zero-downtime rotation requires a specific architectural pattern: overlapping validity. At any given time, both the current key and the previous key are valid. This overlap window ensures that services using the old key continue to function while the new key propagates.
The Rotation Cycle
- Generate. Create a new API key or credential alongside the existing one.
- Distribute. Push the new key to all consumers (applications, CI/CD pipelines, partner systems).
- Verify. Confirm that all consumers are using the new key successfully.
- Revoke. Deactivate the old key after the overlap period expires.
The overlap period depends on how quickly new keys can propagate. For internal services that pull configuration from a secret manager, the overlap might be minutes. For partner integrations that require manual key updates, the overlap might be days or weeks.
Dual-Key Support
Your services must accept multiple valid keys simultaneously for rotation to work without downtime. Common implementation approaches:
Array-based validation. The service checks incoming requests against an array of valid keys rather than a single key. During rotation, the array contains both old and new keys.
Versioned keys. Keys include a version identifier, and the service maintains a mapping of valid versions. New versions are added before old versions are removed.
Token-based with graceful expiration. JWTs and similar tokens can be validated against multiple signing keys. Key rotation updates the signing key while keeping the previous key in the verification set.
Implementation by Secret Manager
AWS Secrets Manager
AWS Secrets Manager has built-in rotation support with Lambda functions:
The rotation Lambda follows a four-step process: createSecret (generate new key), setSecret (update the service with the new key), testSecret (verify the new key works), and finishSecret (mark the new key as current).
AWS provides rotation Lambda templates for common services (RDS databases, Redshift, DocumentDB). For custom API keys, you write a Lambda that implements the four rotation steps for your specific service.
HashiCorp Vault
Vault supports dynamic secrets — credentials generated on demand with automatic expiration:
- Database credentials can be generated per application with TTLs that enforce rotation
- Cloud provider credentials can be generated through Vault's secrets engines with automatic revocation
- PKI certificates can be issued with short lifetimes, forcing regular renewal
Vault's approach is fundamentally different from rotation: instead of rotating long-lived credentials, it issues short-lived credentials that expire automatically.
Azure Key Vault and GCP Secret Manager
Both support event-driven rotation:
- Azure Key Vault triggers Event Grid events near expiration, which can invoke Azure Functions for rotation
- GCP Secret Manager integrates with Cloud Functions for custom rotation logic
Common Rotation Scenarios
Database Credentials
Database credential rotation requires coordinating between the secret manager, the database, and the applications:
- Generate new database password
- Update the database user with the new password (most databases support ALTER USER without interrupting existing connections)
- Update the secret in the secret manager
- Wait for applications to pick up the new credential (via secret refresh)
- Existing connections using the old password continue working until they reconnect
Cloud Provider API Keys
AWS, GCP, and Azure all support creating multiple API keys per service account:
- Create a new API key for the service account
- Update consumers with the new key
- Monitor to confirm no traffic uses the old key
- Delete the old key
Better yet, use instance roles, workload identity, or OIDC federation to eliminate long-lived cloud API keys entirely.
Third-Party Service API Keys
Rotating keys for third-party services (Stripe, Twilio, SendGrid, etc.) depends on each service's API:
- Some services support creating multiple active keys (making overlap straightforward)
- Some require deactivating the old key when creating a new one (requiring faster propagation)
- Some do not support programmatic key management at all (requiring manual steps)
For services without programmatic key management, automate everything except the key generation step and create runbooks for the manual portion.
CI/CD Pipeline Credentials
Pipeline secrets require special consideration:
- Update the secret in your secret manager
- Trigger pipeline secret refresh (or wait for the next pipeline run)
- Verify that pipelines run successfully with the new credential
- Some CI/CD platforms cache secrets — ensure caches are invalidated
Monitoring and Alerting
Automated rotation needs automated monitoring:
- Rotation success/failure alerts. Know immediately when a rotation fails.
- Key age monitoring. Alert when any key exceeds its maximum age, indicating rotation failure.
- Authentication failure spikes. A spike in authentication failures after rotation may indicate a consumer that was not updated.
- Unused key detection. Keys that are never used may be orphaned — investigate and remove them.
How Safeguard.sh Helps
Credential management is a supply chain security control. Safeguard helps by monitoring the applications and pipelines that consume credentials, ensuring that the software components handling your API keys are secure and up to date. When vulnerabilities in authentication libraries or credential handling frameworks are disclosed, Safeguard identifies affected applications — because a perfectly rotated API key is still compromised if the application handling it has a vulnerability that allows credential extraction.