amazon-web-services - 在 Cloudformation 上更新堆栈时轮换 AWS 密钥
问题描述
我有一个 Cloudformation 脚本,它调用多个嵌套堆栈,例如创建数据库的堆栈。我首先在秘密管理器中创建一个秘密,然后在数据库实例中使用它作为用户名和密码。我现在不想启用自动秘密轮换。
我的问题是每次更新堆栈时,它都会生成一个新的秘密,该秘密不会传播到数据库。所以之后,当我更新的ECS服务尝试连接数据库时,它使用了错误的密码,因此无法稳定,然后一切都必须回滚。
为什么即使我没有配置密码,我的密码也会轮换?有没有办法避免这种情况?如果不能,我应该添加 AWS::SecretsManager::SecretTargetAttachment 以至少将更改传播到数据库吗?
DBSecret:
Type: "AWS::SecretsManager::Secret"
Properties:
Name: !Join ['', [!Ref ProductName, '-', !Ref EnvironmentName, '-', !Ref DBName, '-db-secret']]
Description: Secret to be used for the database
KmsKeyId: !Ref KmsKeyId
GenerateSecretString:
SecretStringTemplate: !Join ['', ['{"username": "', !Ref DBUser , '"}']]
GenerateStringKey: "password"
PasswordLength: 30
ExcludeCharacters: '"@/\'
Tags:
- Key: Name
Value: !Join ['', [!Ref ProductName, '-', !Ref EnvironmentName, '-', !Ref DBName, '-db-secret']]
PostgresDb:
Type: AWS::RDS::DBInstance
Properties:
AllocatedStorage: !Ref DBAllocatedStorage
AutoMinorVersionUpgrade: 'true'
VPCSecurityGroups:
- Ref: SecurityGroup
DBName: !Ref DBName
DBInstanceClass: !Ref DBInstanceClass
DBSubnetGroupName: !Ref DBSubnetGroup
Engine: postgres
EngineVersion: !Ref DBVersion
MasterUsername: !Join ['', ['{{resolve:secretsmanager:', !Ref DBSecret , ':SecretString:username}}']]
MasterUserPassword: !Join ['', ['{{resolve:secretsmanager:', !Ref DBSecret , ':SecretString:password}}']]
MultiAZ: !Ref DBMultiAZ
StorageType: gp2
BackupRetentionPeriod: 7
StorageEncrypted: !Ref DBEncrypted
# Only add the KMS key if the db is going to be encrypted
KmsKeyId: !If [IsEncrypted, !Ref KmsKeyId, !Ref "AWS::NoValue"]
MonitoringInterval: !If [HasEnhancedMonitoring, !Ref DBEnhancedMonitoringInterval, "0"]
MonitoringRoleArn: !If [HasEnhancedMonitoring, !Ref DBMonitoringRoleARN, !Ref "AWS::NoValue"]
Port: 5432
Tags:
- Key: Name
Value: !Ref DBIdentifier
解决方案
您需要将数据库和数据库配置分开在单独的堆栈中。数据库基础设施和数据库密码不是您会经常更新的东西,而您的代码将处于不断变化的生命周期中。您的 ECS 服务可以使用 Fn::ImportValue 从其他堆栈引用您的密码。在此处查看文档:
推荐阅读
- r - 跟踪表中最接近的值 Shiny r
- react-native - 由于 React Native 使用像素或百分比作为单位,我们如何处理大文本输入的可访问性
- jenkins - 在詹金斯的shell命令中处理字符串插值
- angular - 如何在 Angular 中使用多个 API 调用从数据库中查询嵌套数据?
- flutter - 在 audio_service v18 中使用扩展的 MediaItem
- c# - 如何使用 Mapster 创建可重复使用的映射配置文件?
- excel - 从 Visual Basic 程序 yChart.SeriesCollection.Count 调用的 Excel 对象不会给我计数对象
- angular - 未从 Geocoding API (OpenWeather) 获取数据
- python - 无法构建Whylabs-datasketches
- recursion - 使用返回布尔值的递归函数时的指导?