Lambda 轮换函数的执行角色权限 Amazon Secrets Manager - Amazon Secrets Manager
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

Lambda 轮换函数的执行角色权限 Amazon Secrets Manager

因为通过 Lambda 函数进行旋转,当 Secrets Manager 使用 Lambda 函数轮换密钥时,Lambda 将担任 IAM 执行角色并将这些证书提供给 Lambda 函数代码。有关如何设置自动旋转的说明,请参阅:

以下示例显示了适用于 Lambda 轮换函数执行角色的内联策略。要创建执行角色并附加权限策略,请参阅 Amazon Lambda 执行角色

适用于 Lambda 轮换函数执行角色的策略

以下示例策略允许轮换函数:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "secretsmanager:DescribeSecret", "secretsmanager:GetSecretValue", "secretsmanager:PutSecretValue", "secretsmanager:UpdateSecretVersionStage" ], "Resource": "SecretARN" }, { "Effect": "Allow", "Action": [ "secretsmanager:GetRandomPassword" ], "Resource": "*" }, { "Action": [ "ec2:CreateNetworkInterface", "ec2:DeleteNetworkInterface", "ec2:DescribeNetworkInterfaces", "ec2:DetachNetworkInterface" ], "Resource": "*", "Effect": "Allow" } ] }

适用于客户托管密钥的策略语句

如果密钥使用 Amazon 托管式密钥 aws/secretsmanager 以外的 KMS 密钥进行加密,则您需要向 Lambda 执行角色授予使用该密钥的权限。您可以使用 SecretARN 加密上下文 来限制解密函数的使用,从而确保轮换函数角色只能解密其负责轮换的密钥。以下示例演示了要添加到执行角色策略中,以使用 KMS 密钥将密钥解密的语句。

{ "Effect": "Allow", "Action": [ "kms:Decrypt", "kms:DescribeKey", "kms:GenerateDataKey" ], "Resource": "KMSKeyARN" "Condition": { "StringEquals": { "kms:EncryptionContext:SecretARN": "SecretARN" } } }

要对使用客户托管密钥加密的多个密钥使用轮换函数,请添加如下示例所示的语句以允许执行角色解密该密钥。

{ "Effect": "Allow", "Action": [ "kms:Decrypt", "kms:DescribeKey", "kms:GenerateDataKey" ], "Resource": "KMSKeyARN" "Condition": { "StringEquals": { "kms:EncryptionContext:SecretARN": [ "arn1", "arn2" ] } } }

适用于交替用户策略的策略语句

有关交替用户轮换策略的信息,请参阅 Lambda 函数轮换策略

对于包含 Amazon RDS 凭证的密钥,如果您使用的是交替用户策略并且超级用户密钥由 Amazon RDS 管理,则还须允许轮换函数调用 Amazon RDS 上的只读 API,以便其获取数据库的连接信息。我们建议您附上 Amazon 托管政策 AmazonRDS ReadOnlyAccess

以下示例策略允许函数:

  • SecretARN 运行 Secrets Manager 操作。

  • 在超级用户密钥中检索凭证。Secrets Manager 会使用超级用户密钥中的凭证更新轮换密钥中的凭证。

  • 创建新密码。

  • 如果数据库或服务在 VPC 中运行,则设置所需的配置。有关更多信息,请参阅配置 Lambda 函数以访问 VPC 中的资源

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "secretsmanager:DescribeSecret", "secretsmanager:GetSecretValue", "secretsmanager:PutSecretValue", "secretsmanager:UpdateSecretVersionStage" ], "Resource": "SecretARN" }, { "Effect": "Allow", "Action": [ "secretsmanager:GetSecretValue" ], "Resource": "SuperuserSecretARN" }, { "Effect": "Allow", "Action": [ "secretsmanager:GetRandomPassword" ], "Resource": "*" }, { "Action": [ "ec2:CreateNetworkInterface", "ec2:DeleteNetworkInterface", "ec2:DescribeNetworkInterfaces", "ec2:DetachNetworkInterface" ], "Resource": "*", "Effect": "Allow" } ] }