gpt4 book ai didi

amazon-web-services - 为什么通过 IAM 策略将 `ssm:sendCommand` 限制为特定文档显示拒绝访问?

转载 作者:行者123 更新时间:2023-12-02 16:02:51 26 4
gpt4 key购买 nike

我正在尝试让 IAM 用户只能对特定文档使用 SSM 运行命令。

如果我将以下策略附加到用户,则该用户确实只能在 EC2 实例上成功执行 AWS-RunShellScript(这是一个 AWS 托管的)文档。

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ssm:DescribeDocument",
"ssm:DescribeDocumentParameters",
"ssm:DescribeDocumentPermission",
"ssm:GetCommandInvocation",
"ssm:GetDocument",
"ssm:ListCommandInvocations",
"ssm:ListCommands",
"ssm:ListDocumentMetadataHistory",
"ssm:ListDocuments",
"ssm:ListDocumentVersions"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "ssm:SendCommand",
"Resource": "arn:aws:ssm:us-west-2:999999999999:document/AWS-RunShellScript"
}
]
}

但是,如果我将策略中的资源项替换为我创建的自定义文档 ARN(例如 arn:aws:ssm:us-west-2:999999999999:document/CustomDocument),我收到“拒绝访问”

enter image description here

最佳答案

文档中不是很清楚但是为了限制ssm:SendCommand,你必须使用Resource字段来指定IAM是什么文档允许用户运行您允许在哪些实例上运行命令

用户在尝试运行命令时会看到所有实例,但只能针对 IAM 策略中指定的 EC2 实例 ID 执行命令。

如果需要,您可以指定允许任何实例的策略,或者根据授予 least privilege 的标准安全建议指定有限的实例 ID 列表。在 IAM 政策中。

至于 AWS 托管文档为何有效,这可能是一些内部魔法 🤷‍♂️

这应该有效:

{
"Version":"2012-10-17",
"Statement":[
{
"Effect":"Allow",
"Action":"ssm:SendCommand",
"Resource":[
"arn:aws:ec2:us-west-2:999999999999:instance/*",
"arn:aws:ssm:us-west-2:999999999999:document/AWS-RunShellScript"
]
}
]
}

关于amazon-web-services - 为什么通过 IAM 策略将 `ssm:sendCommand` 限制为特定文档显示拒绝访问?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70190926/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com