gpt4 book ai didi

amazon-web-services - 在 CloudFormation 模板中引用 AWS Parameter Store 的安全字符串

转载 作者:行者123 更新时间:2023-12-03 14:16:55 35 4
gpt4 key购买 nike

一直在使用 AWS Parameter Store 中的 SecureString。我试图将数据库密码称为:

DatabasePassword:
Type: AWS::SSM::Parameter::Value<SecureString>
NoEcho: 'true'
Default: /environment/default/database_password
Description: The database admin account password

这会引发错误:

An error occurred (ValidationError) when calling the CreateStack operation: Template format error: Unrecognized parameter type: SecureString

但是,如果我将此参数引用为 String 而不是 SecureString ,则会引发不同的错误:

An error occurred (ValidationError) when calling the CreateStack operation: Parameters [/environment/default/database_password] referenced by template have types not supported by CloudFormation.

我确实尝试使用'{{resolve:ssm-secure:parameter-name:version}}'并且它适用于数据库配置:

MasterUsername: !Ref DatabaseUsername
MasterUserPassword: '{{resolve:ssm-secure:/environment/default/database_password:1}}'

但是,我使用 AWS Fargate docker 容器,在其中提供这些值作为环境变量:

Environment:
- Name: DATABASE_HOSTNAME
Value: !Ref DatabaseHostname
- Name: DATABASE_USERNAME
Value: !Ref DatabaseUsername
- Name: DATABASE_PASSWORD
Value: '{{resolve:ssm-secure:/environment/default/database_password:1}}'

这会引发错误:

An error occurred (ValidationError) when calling the CreateStack operation: SSM Secure reference is not supported in: [AWS::ECS::TaskDefinition/Properties/ContainerDefinitions/Environment]

无法在我的实现中使用安全字符串。这个问题有什么解决办法吗? AWS 去年宣布支持 SecureString,但找不到文档。我发现的只是使用 resolve ,它仅在某些情况下有效。

引用文献:

1

2

最佳答案

CloudFormation 不支持 SecureString 作为模板参数类型。你可以在下面的文档中确认一下,我引用一下。

In addition, AWS CloudFormation does not support defining template parameters as SecureString Systems Manager parameter types. However, you can specify Secure Strings as parameter values for certain resources by using dynamic parameter patterns.

引用:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html#aws-ssm-parameter-types

正如您提到的,您“可以”使用动态参数模式解决它,但只有有限的资源支持它。 ECSFargate 没有。

引用:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html

也许您可以使用Secrets Manager来解决这个问题,而不是将密码设置为容器的环境变量,您的应用程序在运行时从Secrets Manager获取密码,这还提高了您的安全性,密码在容器内不会以明文形式显示。

下面您可以看到此解决方案的一个示例,它不适用于容器,但使用环境变量和 Secrets Manager 的“工作方式”是相同的。

引用:https://aws.amazon.com/blogs/security/how-to-securely-provide-database-credentials-to-lambda-functions-by-using-aws-secrets-manager/

关于amazon-web-services - 在 CloudFormation 模板中引用 AWS Parameter Store 的安全字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56891180/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com