使用条件 ec2:ResourceTag 的 IAM 政策无效
IAM Policy using Condition ec2:ResourceTag not working
我有 n x EC2 实例,我希望将 ec2 操作限制为具有相同 key/value 标签(即平台=dev)的实例。
我正在考虑使用附加到其默认 IAM 用户所在组的 IAM 策略来执行此操作。
政策:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "ec2:*",
"Resource": "*",
"Condition": {
"StringEquals": {
"ec2:ResourceTag/tag:platform": "dev"
}
}
}
]}
我根据在线 AWS 文档进行设置:Example Policies for Working With the AWS CLI or an AWS SDK
我在 Policy Simulator 中对其进行了检查,它按预期工作(传入 dev 并允许,否则被拒绝)。
然后在其中一台带有标签 key/pair 的平台=dev 的服务器上,我 运行 aws ec2 describe-instances
我得到响应:
An error occurred (UnauthorizedOperation) when calling the DescribeInstances operation: You are not authorized to perform this operation.
但如果我删除条件,它就会起作用。我不明白我做错了什么。如有任何帮助,我们将不胜感激!
这个问题我之前就运行了,它与组合通配符和条件有关。为我们解决问题的是在操作(例如 ["ec2:DescribeInstances"]
)和资源(arn:aws:ec2:region:accountid:instance/*
)上更加明确。
问题是并非每个 API 操作和资源都会接受条件中的 ec2:ResourceTag/tag。
我认为您授予的权限可能过于宽泛(操作:ec2:*),因此请弄清楚您的实例需要执行哪些操作,然后决定如何限制它们。
可在 Supported Resource-Level Permissions for Amazon EC2 API Actions.
找到操作、资源和条件键的列表
我有 n x EC2 实例,我希望将 ec2 操作限制为具有相同 key/value 标签(即平台=dev)的实例。
我正在考虑使用附加到其默认 IAM 用户所在组的 IAM 策略来执行此操作。
政策:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "ec2:*",
"Resource": "*",
"Condition": {
"StringEquals": {
"ec2:ResourceTag/tag:platform": "dev"
}
}
}
]}
我根据在线 AWS 文档进行设置:Example Policies for Working With the AWS CLI or an AWS SDK
我在 Policy Simulator 中对其进行了检查,它按预期工作(传入 dev 并允许,否则被拒绝)。
然后在其中一台带有标签 key/pair 的平台=dev 的服务器上,我 运行 aws ec2 describe-instances
我得到响应:
An error occurred (UnauthorizedOperation) when calling the DescribeInstances operation: You are not authorized to perform this operation.
但如果我删除条件,它就会起作用。我不明白我做错了什么。如有任何帮助,我们将不胜感激!
这个问题我之前就运行了,它与组合通配符和条件有关。为我们解决问题的是在操作(例如 ["ec2:DescribeInstances"]
)和资源(arn:aws:ec2:region:accountid:instance/*
)上更加明确。
问题是并非每个 API 操作和资源都会接受条件中的 ec2:ResourceTag/tag。
我认为您授予的权限可能过于宽泛(操作:ec2:*),因此请弄清楚您的实例需要执行哪些操作,然后决定如何限制它们。
可在 Supported Resource-Level Permissions for Amazon EC2 API Actions.
找到操作、资源和条件键的列表