Files
nexus/wiki/concepts/SecretRotation.md

93 lines
2.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "SecretRotation"
type: concept
tags:
- AWS
- Security
- Automation
- DevOps
---
## Definition
Secret Rotation密钥轮换是指定期自动更换敏感凭据密码、API Key、证书等的安全机制旨在防止长期密钥泄露导致的安全风险。
## Why Rotate Secrets?
1. **降低泄露风险**:即使密钥被意外泄露,轮换机制可限制暴露窗口
2. **合规要求**:满足 SOC 2、PCI-DSS 等安全合规标准
3. **密钥生命周期管理**:遵循安全最佳实践中的密钥生命周期原则
4. **应对内部威胁**:限制离职员工或恶意内部人员的凭据滥用
## AWS Secrets Manager Rotation Strategies
### Built-in Rotation Lambdas
AWS Secrets Manager 为以下服务提供开箱即用的轮换 Lambda 函数:
- **RDS 数据库**MySQL、PostgreSQL、MariaDB、Oracle、SQL Server、Aurora
- **Redshift**
- **DocumentDB**
### Custom Rotation Patterns
#### Oracle Database Password Rotation
```
用户密码存储在 Secrets Manager
Lambda 函数被触发(或定时)
Lambda 连接 Oracle 实例(使用当前凭据)
生成新密码
更新数据库中的用户密码
更新 Secrets Manager 中的密码
完成轮换
```
**关键优势**:无需通过邮件发送新密码,通过 AWS 角色授权访问 Secrets
#### SendGrid API Key Rotation
- **问题**:多个团队各自管理 SendGrid API Key轮换需要代码变更和重启应用
- **解决方案**:集中式 SMTP 服务统一处理 SendGrid 轮换,应用只连接内部 SMTP 服务器
- **实现**SMTP 服务在端口 1025 提供服务,应用无需感知后端 API Key 变更
## Rotation Triggers
| 触发方式 | 说明 |
|---------|------|
| 定时轮换 | 按固定间隔(天数)自动触发 |
| 手动触发 | 通过 AWS CLI 或 Console 手动启动 |
| API 调用 | 通过 `rotateSecret` API 编程触发 |
| 事件驱动 | CloudWatch Events 触发 Lambda |
## Best Practices
1. **先集中,后轮换**:先完成 Secrets 集中化管理,再启用轮换
2. **测试回滚**:轮换失败时的回滚机制测试
3. **应用兼容性**:确保应用支持动态获取新凭据(使用 JDBC Wrapper、SDK 等)
4. **监控告警**:轮换失败时的告警通知机制
5. **分阶段实施**:先低风险系统试点,再推广至生产环境
## Related Concepts
- [[SecretsManagement]]:敏感信息管理的整体框架
- [[JDBCWrapper]]:数据库应用获取动态凭据的方式
- [[Lambda]]:用于执行轮换逻辑的无服务器函数
- [[ControlTower]]:企业级 Secrets 管理的治理框架
## Sources
- [[CTP-Topic-62-AWS-Secrets-Manager]] — Oracle 数据库和 SendGrid API Key 轮换实施案例
## Aliases
- Key Rotation
- Credential Rotation
- Password Rotation
- API Key Rotation