无法承担访问 AWS 中的 EC2 实例的角色

时间:2021-07-28 16:02:45

标签: amazon-web-services amazon-iam aws-sts

我正在使用使用 AWS Control Tower 和 AWS Organization 的多账户架构。我有一个主账户,其中有一个名为 agent 的 IAM 用户(没有附加策略,只有 CLI 访问权限),然后我有另一个名为 dev 的 AWS 账户,我在其中创建了一个名为工作负载部署的新角色(ARN -> arn :aws:iam::809348927750:role/workload-deployer) 具有以下信任关系:-

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::185288728304:user/agent"
      },
      "Action": "sts:AssumeRole",
      "Condition": {}
    }
  ]
}

当我尝试担任此角色时,出现以下错误:-

An error occurred (AccessDenied) when calling the AssumeRole operation: User: arn:aws:iam::185288728304:user/agent is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::809348927750:role/workload-deployer

我正在运行以承担角色的命令:-

aws sts assume-role --role-arn arn:aws:iam::809348927750:role/workload-deployer --role-session-name "RoleSession1" --duration-seconds 900  --profile zm

1 个答案:

答案 0 :(得分:2)

为了承担一个角色,您需要在 2 个地方存在权限:

  1. 您开始的角色需要获得担任角色的权限。因此,它必须具有授予 sts:AssumeRole 权限的策略。
  2. 您要代入的角色必须具有授予调用角色代入该角色权限的信任策略。

听起来您没有获得 #1 的权限。