在密钥管理系统 (AWS) 的 cloudformation 模板中获取 root 以外用户的 ARN)
Getting ARN of a user other than root in a cloudformation template for Key management System (AWS))
我目前正在为 KMS(密钥管理服务)编写云形成模板 (CFT),我想在其中向 root 以外的用户授予密钥管理权限和密钥使用权限。我希望通过 CFT 动态调用它。截至目前,我能够授予 root 那些权限。以下是政策:
{
"Sid": "Allow attachment of persistent resources",
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:iam::111122223333:user/KMSUser"
{
"Fn::Join": [
":",
[
"arn:aws:iam:",
{
"Ref": "AWS::AccountId"
},
"root"
]
]
}
]
},
"Action": [
"kms:CreateGrant",
"kms:ListGrants",
"kms:RevokeGrant"
],
"Resource": "*",
"Condition": {
"Bool": {
"kms:GrantIsForAWSResource": true
}
}
}
如何动态获取 arn 和用户名?
您可以使用参数。
为用户名定义一个参数
"Username": {
"Description": "Username details",
"Type": "String"
}
在角色名称定义中,指向参数而不是将其硬编码为 root
。
"Fn::Join": [
":",
[
"arn:aws:iam:",
{
"Ref": "AWS::AccountId"
},
{
"Ref": "Username"
}
]
]
我目前正在为 KMS(密钥管理服务)编写云形成模板 (CFT),我想在其中向 root 以外的用户授予密钥管理权限和密钥使用权限。我希望通过 CFT 动态调用它。截至目前,我能够授予 root 那些权限。以下是政策:
{
"Sid": "Allow attachment of persistent resources",
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:iam::111122223333:user/KMSUser"
{
"Fn::Join": [
":",
[
"arn:aws:iam:",
{
"Ref": "AWS::AccountId"
},
"root"
]
]
}
]
},
"Action": [
"kms:CreateGrant",
"kms:ListGrants",
"kms:RevokeGrant"
],
"Resource": "*",
"Condition": {
"Bool": {
"kms:GrantIsForAWSResource": true
}
}
}
如何动态获取 arn 和用户名?
您可以使用参数。
为用户名定义一个参数
"Username": {
"Description": "Username details",
"Type": "String"
}
在角色名称定义中,指向参数而不是将其硬编码为 root
。
"Fn::Join": [
":",
[
"arn:aws:iam:",
{
"Ref": "AWS::AccountId"
},
{
"Ref": "Username"
}
]
]