为什么在 IAM 策略中将条件应用于 ec2:DescribeInstances 会失败?

Why does applying a condition to ec2:DescribeInstances in an IAM policy fail?

在尝试配置哪些实例可以使用策略列出时,我注意到以下问题:

包含条件示例策略:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1461235889000",
            "Effect": "Allow",
            "Action": [
                "ec2:DescribeInstances"
            ],
            "Resource": [
                "*"
            ],
            "Condition": {
                "StringEquals": {
                    "ec2:InstanceType": "r3.xlarge"
                }
            }
        }
    ]
}

这里有什么问题?

ec2:DescribeInstances 操作 does not support resource-level permissions 或应用条件。

来自上面的链接文档:

...to use these actions in an IAM policy, you must grant users permission to use all resources for the action by using a * wildcard for the Resource element in your statement. You cannot use Amazon EC2 condition keys for these actions.

因此,您在没有条件的情况下使用 * 通配符是有效的,但不幸的是,应用任何条件(截至撰写本文时)都无法按预期工作。

进一步阅读: