AWS DescribeStacks 操作 - 我可以限制为特定资源吗?

问题描述

我想创建一个允许 cloudformation:DescribeStacks 但仅限于描述特定堆栈而不是所有堆栈的策略。我的偏好是限制为具有特定标签的堆栈,如果不可能,则限制为名称以特定前缀开头的堆栈。

根据https://docs.aws.amazon.com/service-authorization/latest/reference/list_awscloudformation.html#awscloudformation-stack,我认为这应该是可能的。然而,我尝试的一切都不起作用,我得到了许可被拒绝的回应。

这是我尝试过的:

1 -

{
    "Effect": "Allow","Action": [
        "cloudformation:DescribeStacks"
    ],"Resource": "*",}

1 有效,返回所有堆栈。

2 -

 {
    "Effect": "Allow","Condition": {
        "StringLike": {
            "aws:ResourceTag/my-tag": "*"
        }
    }
}

2 收到以下错误调用 DescribeStacks 操作时发生错误 (AccessDenied):用户:arn:aws:iam::xxxx:user/yyyy 未获授权执行:cloudformation:DescribeStacks

3 -

{
    "Effect": "Allow","Resource": "my-specific-stack-id (ARN)" (tried also with just prefix and *)
}

3 - 得到与 2 相同的错误

4 -

{
    "Effect": "Allow","Condition": {
        "ForAnyValue:StringLike": {
            "aws:TagKeys": "my-tag*"
        }
    }
}

4 也得到与 2 和 3 相同的错误

这完全可以做我正在尝试做的事情还是 DescribeStacks 仅适用于 "Resource" : "*"?如果是后者,则文档令人困惑。

谢谢

解决方法

遗憾的是,您不能这样做。根据您的linkDescribeStacks 不支持任何条件:

enter image description here

在同一个表中,aws:RequestTag/${TagKey} 仅适用于某些操作,例如 UpdateStack

更新

您使用完整资源的政策正确

"Resource": "arn:aws:cloudformation:eu-west-1:xxxxxxxxxxxx:stack/sandbox-noe3kx0sbw02bb/952c2af0-71d3-11eb-832b-06f0a0237781"

但是,要使用 DescribeStacks 操作,您必须指定堆栈名称 sandbox-noe3kx0sbw02bb,例如

aws cloudformation describe-stacks  --stack-name sandbox-noe3kx0sbw02bb --region <region-of-stack>

不能使用没有堆栈名称的操作:

aws cloudformation describe-stacks --region <region-of-stack>

因为您无权描述所有堆栈。您只能描述一个特定的堆栈。