【发布时间】:2021-10-26 22:53:19
【问题描述】:
我需要一些有关创建 AWS 策略的帮助。
我需要一个链接到 EC2 实例的策略,以便能够只为 AWS SSM 参数存储中的特定参数提供 get-parameters-by-path,而不能更改 Delete、Create 等任何内容,并且应该只能获取值。
此政策的特殊性将通过标签给出。
这是我尝试使用的策略:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["ssm:*"],
"Resource": ["*"]
},
{
"Effect": "Deny",
"Action": [
"ssm:PutParameter",
"ssm:GetParameter",
"ssm:GetParameters",
"ssm:DeleteParameter",
"ssm:GetParameterHistory",
"ssm:DeleteParameters",
"ssm:GetParametersByPath"
],
"Resource": ["*"],
"Condition": {
"StringNotEquals": {
"ssm:resourceTag/env": "development-1"
}
}
}
]
}
使用AWS Policy Simulator 它会通知您,当尝试使用View、Create、Modify、Delete 参数时,"ssm:resourceTag/env": "development-2" 会通知拒绝消息,而使用"ssm:resourceTag/env": "development-1" 的其他项目会收到通知可以修改、查看等。
但是,当将同一策略绑定到 EC2 实例时,该策略会阻止在拒绝中添加的任何操作。
EC2 通知消息:
/development-1/project-1
aws --region us-east-2 ssm get-parameters-by-path --path /development-1/project-1/ --recursive --with-decryption --output text --query "Parameters[].[Value]"
An error occurred (AccessDeniedException) when calling the GetParametersByPath operation: User: arn:aws:sts::111111111:assumed-role/rule-ec2/i-11111111111 is not authorized to perform: ssm:GetParametersByPath on resource: arn:aws:ssm:us-east-2:11111111111:parameter/development-1/project-1/ with an explicit deny
/development-2/project-2
aws --region us-east-2 ssm get-parameters-by-path --path /development-2/project-2/ --recursive --with-decryption --output text --query "Parameters[].[Value]"
An error occurred (AccessDeniedException) when calling the GetParametersByPath operation: User: arn:aws:sts::11111111111:assumed-role/rule-ec2/i-11111111111 is not authorized to perform: ssm:GetParametersByPath on resource: arn:aws:ssm:us-east-2:11111111111:parameter/development-2/project-2/ with an explicit deny
使用的标签:
键=值
/development-1/project-1:
env=development-1
/development-2/project-2:
env=development-2
我做错了什么?
【问题讨论】:
-
您关于您的策略应该“仅将 get-parameters-by-path 提供给特定 Parameter Store [路径]”的声明与您在显示的策略中实施的内容不匹配我们。实施一个在相关资源路径上简单地允许 ssm:GetParametersByPath 的策略不是更合适吗?
标签: amazon-web-services amazon-ec2 parameters terraform aws-systems-manager