适用于 Amazon Secrets Manager 的 Lambda 轮换函数执行角色权限
Secrets Manager 使用 Lambda 函数轮换密钥。为了运行 Lambda 函数,Lambda 会担任 IAM 执行角色并将这些凭证提供给 Lambda 函数代码。有关如何设置自动轮换的说明,请参阅:
以下示例显示了适用于 Lambda 轮换函数执行角色的内联策略。要创建执行角色并附加权限策略,请参阅 Amazon Lambda 执行角色。
适用于 Lambda 轮换函数执行角色的策略
以下示例策略允许轮换函数:
-
为
SecretARN
运行 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:GetRandomPassword" ], "Resource": "*" }, { "Action": [ "ec2:CreateNetworkInterface", "ec2:DeleteNetworkInterface", "ec2:DescribeNetworkInterfaces", "ec2:DetachNetworkInterface" ], "Resource": "*", "Effect": "Allow" } ] }
适用于客户托管密钥的策略语句
如果密钥使用 Amazon 托管式密钥 aws/secretsmanager
以外的 KMS 密钥进行加密,则您需要向 Lambda 执行角色授予使用该密钥的权限。以下示例显示了要添加到执行角色策略中以允许函数检索 KMS 密钥的语句。
{ "Effect": "Allow", "Action": [ "kms:Decrypt", "kms:GenerateDataKey" ], "Resource": "
KMSKeyARN
" }
适用于交替用户策略的策略语句
有关交替用户轮换策略的信息,请参阅 轮换策略。
以下示例策略允许函数:
-
为
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": "SeparateSecretARN
" }, { "Effect": "Allow", "Action": [ "secretsmanager:GetRandomPassword" ], "Resource": "*" }, { "Action": [ "ec2:CreateNetworkInterface", "ec2:DeleteNetworkInterface", "ec2:DescribeNetworkInterfaces", "ec2:DetachNetworkInterface" ], "Resource": "*", "Effect": "Allow" } ] }