Credential Rotation Best Practices
Credential rotation is one of the most effective defenses against credential-based attacks. When done properly, it limits the window of opportunity for attackers and reduces the impact of any single credential exposure.
Why Rotation Matters
Even with the best security practices, credentials can be exposed through:
- Developer mistakes
- Third-party breaches
- Insider threats
- Supply chain compromises
- Unknown vulnerabilities
Regular rotation ensures that any exposed credential has a limited useful lifespan. An attacker who finds a credential that was rotated last week has nothing.
Rotation Frequency Guidelines
Different credential types warrant different rotation schedules:
Rotate Immediately (Upon Detection)
Any credential that has been confirmed or suspected to be exposed:
- Credentials found in public repositories
- Credentials detected in breach databases
- Credentials shared through insecure channels
- Credentials accessed by departing employees
Rotate Frequently (30-90 days)
High-privilege credentials with significant blast radius:
- Cloud provider root/admin credentials
- Production database passwords
- CI/CD pipeline tokens
- Service account keys with broad permissions
Rotate Regularly (90-180 days)
Standard operational credentials:
- Application API keys
- Integration tokens
- Service-to-service credentials
- Developer access tokens
Rotate Periodically (180-365 days)
Lower-risk credentials with limited scope:
- Read-only API keys
- Development environment credentials
- Monitoring service tokens
- Public API keys
Building a Rotation Process
Effective credential rotation requires planning and automation:
Step 1: Inventory Your Credentials
You can't rotate what you don't know about. Create a comprehensive inventory:
- Where is each credential stored?
- What systems depend on it?
- Who has access to it?
- When was it last rotated?
- What's the rotation procedure?
Step 2: Establish Ownership
Every credential should have a clear owner responsible for:
- Maintaining rotation schedule
- Executing rotation procedures
- Responding to exposure incidents
- Documenting access and usage
Step 3: Document Rotation Procedures
For each credential type, document:
- Step-by-step rotation process
- Systems that need updating
- Validation steps after rotation
- Rollback procedure if issues arise
- Communication requirements
Step 4: Automate Where Possible
Manual rotation doesn't scale. Prioritize automation for:
- High-frequency rotation credentials
- Credentials used across many systems
- Credentials with complex update requirements
- Emergency rotation scenarios
Step 5: Test Your Process
Regularly test rotation procedures:
- Can you rotate within your target timeframe?
- Do all dependent systems update correctly?
- Are there any manual steps that cause delays?
- Does the team know how to execute the process?
Rotation Strategies by Credential Type
Database Credentials
Challenge: Applications need continuous access during rotation.
Strategy:
- Create new credentials alongside existing ones
- Update applications to use new credentials
- Verify all applications are using new credentials
- Revoke old credentials
Automation: Use connection poolers that support credential refresh, or implement dual-credential support in applications.
API Keys
Challenge: Third-party integrations may cache credentials.
Strategy:
- Generate new API key
- Update all integrations to use new key
- Monitor for requests using old key
- Deprecate old key after confirmation period
- Revoke old key
Automation: Use API gateways that support key rotation, or implement key versioning.
Cloud Provider Credentials
Challenge: Broad permissions and many dependent systems.
Strategy:
- Audit current credential usage
- Create new credentials with same permissions
- Update all dependent systems
- Verify functionality
- Disable old credentials (don't delete immediately)
- Delete old credentials after monitoring period
Automation: Use cloud-native secret management (AWS Secrets Manager, Azure Key Vault, GCP Secret Manager) with automatic rotation.
SSH Keys
Challenge: Keys may be deployed across many systems.
Strategy:
- Generate new key pair
- Deploy public key to all target systems
- Update all clients to use new private key
- Remove old public key from target systems
- Securely destroy old private key
Automation: Use configuration management tools (Ansible, Puppet, Chef) or certificate-based authentication.
OAuth Tokens
Challenge: Tokens may have long expiration times.
Strategy:
- Implement refresh token rotation
- Reduce access token lifetime
- Revoke refresh tokens when rotating
- Re-authenticate applications with new tokens
Automation: Use OAuth libraries that handle token refresh automatically.
Emergency Rotation Playbook
When a credential exposure is detected, speed is critical:
Immediate Actions (0-15 minutes)
- Assess scope — What does this credential provide access to?
- Revoke if possible — Can you disable without breaking production?
- Alert stakeholders — Notify security team and credential owner
- Begin rotation — Start the rotation process immediately
Short-term Actions (15-60 minutes)
- Complete rotation — Finish updating all dependent systems
- Verify functionality — Confirm systems are working with new credentials
- Check for abuse — Review logs for unauthorized access
- Document timeline — Record what happened and when
Follow-up Actions (1-24 hours)
- Root cause analysis — How did the credential get exposed?
- Scope assessment — Were other credentials potentially exposed?
- Process improvement — What changes prevent recurrence?
- Stakeholder communication — Brief relevant parties on incident
Common Rotation Pitfalls
Pitfall 1: Incomplete Updates
Problem: Some systems still use old credentials after rotation.
Solution: Maintain a complete dependency map and verify all systems during rotation.
Pitfall 2: No Rollback Plan
Problem: Rotation breaks production with no way to recover.
Solution: Always have a tested rollback procedure. Consider keeping old credentials active briefly during transition.
Pitfall 3: Manual Processes
Problem: Manual rotation is slow and error-prone.
Solution: Invest in automation. The time spent automating pays off during emergencies.
Pitfall 4: Rotation Without Monitoring
Problem: You don't know if rotation succeeded or if old credentials are still in use.
Solution: Implement logging and alerting for credential usage. Monitor for old credential attempts.
Pitfall 5: Ignoring Service Accounts
Problem: Human credentials get rotated, but service accounts are forgotten.
Solution: Include service accounts in your credential inventory and rotation schedule.
Measuring Rotation Effectiveness
Track these metrics to assess your rotation program:
- Mean time to rotate — How quickly can you rotate a credential?
- Rotation coverage — What percentage of credentials are on a rotation schedule?
- Rotation compliance — Are credentials being rotated on schedule?
- Emergency rotation time — How fast can you rotate during an incident?
- Failed rotations — How often do rotations cause issues?
Key Takeaways
- Regular rotation limits the impact of credential exposure
- Different credential types need different rotation frequencies
- Automation is essential for effective rotation at scale
- Emergency rotation procedures should be documented and tested
- Measure and improve your rotation program continuously
A well-executed rotation program is one of the most effective defenses against credential-based attacks.