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

red*_*888 6 amazon-ec2 amazon-web-services amazon-iam

看看这篇文章,这个人使用了一个策略(应用于角色)让一个实例标记自己.

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

我不能使用$ {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}"
                }
            }
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

小智 6

对于 ec2 仅自我操作策略,您可以放弃此策略。我们利用它让主机只能自我终止、自我标记等。

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

我写了一个小的powershell测试验证来确认。它尝试自我标记、删除标记,然后尝试标记严格存在的主机,以验证“自我”领域之外的 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~
Run Code Online (Sandbox Code Playgroud)

删除条件:

Create Tags for self: PASS!
Remove Tags from self: PASS!
Validation falure! I am able to modify other instance's tags!
Run Code Online (Sandbox Code Playgroud)

  • 在应用该策略之前您是否测试过“红色”(失败)状态?应该有其他策略允许您查询标签,因为该条件无效。 (2认同)