【问题标题】:Give an instance only access to tag itself?仅授予实例对标签本身的访问权限?
【发布时间】:2017-03-23 15:03:01
【问题描述】:

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}"
                }
            }
        }
    ]
}

【问题讨论】:

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


    【解决方案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 测试验证来确认。它尝试自我标记,删除标记,然后尝试标记严格存在的主机,以验证“自我”领域之外的 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!
    

    【讨论】:

    • 您是否在应用策略之前测试了“红色”(FAIL) 状态?应该有其他策略允许您查询标签,因为该条件无效。
    • 这不再有效。不接受“aws:ARN”。
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2014-03-06
      • 1970-01-01
      • 2016-09-05
      • 1970-01-01
      • 1970-01-01
      • 2020-01-17
      • 1970-01-01
      • 1970-01-01
      • 2021-03-07
      相关资源
      最近更新 更多