只给一个实例访问标签本身?

时间:2016-11-09 17:52:30

标签: amazon-web-services amazon-ec2 amazon-iam

查看this post这个人使用了一个策略(应用于角色)让一个实例标记自己。

我完全想要同样的事情。我可以使用这个策略,但如果实例只能标记自己而不是其他实例,那就太好了。

我不能使用$ {ec2:SourceInstanceARN}作为资源,因此我尝试使用与策略变量评估的arn匹配的条件。

此政策不会验证:(Syntax errors in policy

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "ec2:CreateTags",
                "ec2:DescribeTags",
                "ec2:DescribeInstances"
            ],
            "Effect": "Allow",
            "Resource": [
                "*"
            ],
            "Condition": {
                "ArnEquals": {
                    "ec2:SourceInstanceARN": "${ec2:SourceInstanceARN}"
                }
            }
        }
    ]
}

2 个答案:

答案 0 :(得分:2)

您不能使用DescribeTags"ec2:SourceInstanceARN"调用限制为实例本身:

aws iam policy visual editor showing you can not apply that condition key

https://docs.aws.amazon.com/IAM/latest/UserGuide/list_amazonec2.html#amazonec2-policy-keys上,DescribeTags没有显示任何要限制的资源,所以我敢打赌,您不能限制该API调用任何资源。

答案 1 :(得分:1)

对于仅适用于ec2自我行动的政策,您可以不这样做。我们将其用于主机,使其只能自我终止,自我标记等。

    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "SelfTaggingOnly",
            "Effect": "Allow",
            "Action": [
                "ec2:CreateTags",
                "ec2:DeleteTags",
                "ec2:DescribeTags"
            ],
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "aws:ARN": "${ec2:SourceInstanceARN}"
                }
            }
        }
    ]
}

我写了一个小的powershell测试验证来确认。它尝试自标记,删除标记,然后尝试标记严格存在的主机,以验证“ self”领域之外的ec2操作尝试。在下面的验证结果中,第一次运行使用了上面的策略,第二次运行我删除了条件。

已制定上述政策:

Create Tags for self: PASS!
Remove Tags from self: PASS!
Unable to modify another instance's tags: PASS!
You are not authorized to perform this operation. Encoded authorization failure message: b9KG8BIyxQs~truncated_encoded_output~

已删除条件:

Create Tags for self: PASS!
Remove Tags from self: PASS!
Validation falure! I am able to modify other instance's tags!
相关问题