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

AWS DescribeStacks action - can I limit to specific resources?

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

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

这是我尝试过的:

1 -

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

1 有效,returns 所有堆栈。

2 -

 {
    "Effect": "Allow",
    "Action": [
        "cloudformation:DescribeStacks"
    ],
    "Resource": "*",
    "Condition": {
        "StringLike": {
            "aws:ResourceTag/my-tag": "*"
        }
    }
}

2 出现以下错误:调用 DescribeStacks 操作时发生错误 (AccessDenied):用户:arn:aws:iam::xxxx:user/yyyy 无权执行:cloudformation:DescribeStacks

3 -

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

3 - 得到与 2

相同的错误

4 -

{
    "Effect": "Allow",
    "Action": [
        "cloudformation:DescribeStacks"
    ],
    "Resource": "*",
    "Condition": {
        "ForAnyValue:StringLike": {
            "aws:TagKeys": "my-tag*"
        }
    }
}

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

是否完全可以做我正在尝试做的事情,或者 DescribeStacks 是否仅适用于“资源”:“*”?如果是后者,说明文档很混乱。

谢谢

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

来自同一个 table,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>

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