API Gateway 资源策略:将 IAM 角色指定为 AWS 委托人

Igo*_*sky 8 amazon-web-services aws-api-gateway

我正在尝试使用资源策略设置 API 网关端点,该策略允许访问我的账户中的特定 IAM 角色。IAM 角色是跨账户的,使用信任策略设置,允许 AssumeRole 从另一个账户到特定的 IAM 用户主体。

在 API Gateway 资源策略中,当我将 AWS 委托人设置为角色 ARN: 时arn:aws:iam::********:role/myRole,调用 API 时收到以下 403 错误:

User: arn:aws:sts::********:assumed-role/myRole/mySession is not authorized to perform: execute-api:Invoke on resource: arn:aws:execute-api:us-west-2:********:********/test/POST/echo
Run Code Online (Sandbox Code Playgroud)

但是,如果我将 AWS 委托人更改为临时 STS 用户 ARN: arn:aws:sts::********:assumed-role/myRole/mySession,那么我可以成功调用 API。

这是不起作用的资源策略:

{
"Version": "2012-10-17",
"Statement": [
    {
        "Effect": "Allow",
        "Principal": {
            "AWS": "arn:aws:iam::********:role/myRole"
        },
        "Action": "execute-api:Invoke",
        "Resource": "arn:aws:execute-api:us-west-2:********:********/*"
    }
]
Run Code Online (Sandbox Code Playgroud)

}

这是有效的资源策略:

{
"Version": "2012-10-17",
"Statement": [
    {
        "Effect": "Allow",
        "Principal": {
            "AWS": "arn:aws:sts::********:assumed-role/myRole/mySession"
        },
        "Action": "execute-api:Invoke",
        "Resource": "arn:aws:execute-api:us-west-2:********:********/*"
    }
]
Run Code Online (Sandbox Code Playgroud)

}

IAM 角色可以用作 API Gateway 资源策略的 AWS 委托人吗?

小智 0

根据文档https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-control-access-policy-language-overview.html

\n
\n

主体 \xe2\x80\x93 被允许访问语句中的操作和资源的帐户或用户。在资源策略中,委托人是\n作为此权限接收者的 IAM 用户或账户。

\n
\n

看起来角色无法添加为主体。

\n

PS:花了两天时间尝试使用角色限制访问,但无法使其发挥作用。

\n