Ale*_*tos 5 aws-cloudformation aws-secrets-manager
我正在尝试在 CloudFormation 中创建一个 AWS 堆栈,该堆栈在 JSON 中有一个秘密。
我不希望参数中显示机密的值,也不希望我的实例(fargate 或 ec2)访问机密管理器。我希望 CloudFormation 从秘密管理器中检索值并在运行时将其注入模板。
这就是我所做的:
创建一个秘密
使用 Designer 创建模板
阅读秘密并创建资源。在这种情况下,我正在创建一个将秘密标记为标签的存储桶。我知道这不安全,但存储桶仅用作概念证明。
验证存储桶是否包含带有秘密的标签
这是我的模板:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "create a single S3 bucket",
"Resources": {
"SampleBucket": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketName": "asantostestbucket",
"Tags" : [
{
"Key" : "keyname",
"Value" : "{{resolve:secretsmanager:dev/learning:SecretString:hello}}"
}
]
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这给了我错误One or more tags are not valid。
我如何向 CloudFormation 表明我希望它读取机密,而不是尝试将标签作为文本读取?换句话说,将“{{resolve:secretsmanager:dev/learning:SecretString:hello}}”替换为值,而不是将其作为文本阅读。
为了重现这种情况,我执行了以下操作:
hellosurprisedev/learning这是输出:
aws secretsmanager get-secret-value --secret-id dev/learning
{
"ARN": "arn:aws:secretsmanager:ap-southeast-2:123456789012:secret:dev/learning-kCxSK3",
"Name": "dev/learning",
"VersionId": "...",
"SecretString": "{\"hello\":\"surprise\"}",
"VersionStages": [
"AWSCURRENT"
],
"CreatedDate": 1560925072.106
}
Run Code Online (Sandbox Code Playgroud)
结果:我收到消息One or more tags are not valid
所以,我得到了和你一样的结果。
然后我尝试使用秘密创建不同类型的资源:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
"SecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "{{resolve:secretsmanager:dev/learning:SecretString:hello}}"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这工作成功:
aws ec2 describe-security-groups --group-id sg-03cfd71f4539a4b7e
{
"SecurityGroups": [
{
"Description": "surprise",
...
Run Code Online (Sandbox Code Playgroud)
所以,看起来它的{{resolve}}行为是正确的,但出于某种原因,S3 标签不喜欢它。
底线:这是可能的,但不可取。
| 归档时间: |
|
| 查看次数: |
4541 次 |
| 最近记录: |