简体   繁体   English

AWS IAM SSM-限制实例可以运行的文档

[英]AWS IAM SSM - Restrict Documents that Instances can run

Is there a way to restrict the IAM policy for an EC2 instance st it can only run a short list of Documents - I tried restricting access to ssm:GetDocument like this: 有没有办法限制EC2实例的IAM策略,它只能运行文档的简短列表-我尝试像这样限制对ssm:GetDocument的访问:

{
  "Version": "2012-10-17",
  "Statement": [
    {
        "Effect": "Allow",
        "Action": [
            "ssm:GetDocument"
        ],
        "Resource": [
            "arn:aws:ssm:ap-southeast-2:*:document/MyCommand"
        ]
    }
 ]}

But I can run any command on the instance still including the AWS-RunPowershellScript document. 但是我可以在仍然包含AWS-RunPowershellScript文档的实例上运行任何命令。

This link shows how users can be restricted with respect to ssm:sendCommand: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/delegate-commands.html 此链接显示了如何限制用户使用ssm:sendCommand: http ://docs.aws.amazon.com/AWSEC2/latest/UserGuide/delegate-commands.html

I have not found a way to restrict SendCommand based on document. 我还没有找到一种基于文档来限制SendCommand的方法。 If a user does not have access, you get an error like this: 如果用户没有访问权限,则会收到如下错误:

User: arn:aws:iam::123456789012:user/username is not authorized to perform: ssm:SendCommand on resource: arn:aws:ec2:us-east-1:123456789012:instance/i-01234567890abcdef 用户:arn:aws:iam :: 123456789012:用户/用户名无权执行:ssm:资源上的SendCommand:arn:aws:ec2:us-east-1:123456789012:instance / i-01234567890abcdef

This indicates that the Resource in SendCommand can be limited based on instance ids. 这表明可以根据实例ID限制SendCommand中的Resource。 It would be nice if one of the Conditions was a Document ARN, but so far I haven't found any way to do it (it's not a condition in the policy generator wizard). 如果条件之一是文档ARN,那就太好了,但是到目前为止,我还没有找到任何方法(在策略生成器向导中不是条件)。

Update: I posted this question on the AWS forums, hopefully I'll get a response: https://forums.aws.amazon.com/thread.jspa?threadID=249039 更新:我在AWS论坛上发布了这个问题,希望我会得到答复: https : //forums.aws.amazon.com/thread.jspa?threadID=249039

Update 2: I got a response and the solution is that to accomplish this you must use Resource to specify both what instances you allow commands to be run on, and what document the user is allowed to run. 更新2:我得到了答复,解决方案是要实现此目的,您必须使用Resource来指定允许在哪些实例上运行命令以及允许用户运行哪些文档。 For example, this is what I ended up with: 例如,这就是我最终得到的结果:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ssm:SendCommand"
            ],
            "Resource": [
                "arn:aws:ec2:*:123456789012:instance/*",
                "arn:aws:ssm:*:123456789012:document/RestartServices"
            ]
        }
    ]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM