【问题标题】:An error occurred (AccessDenied) when calling the AssumeRole operation调用 AssumeRole 操作时发生错误 (AccessDenied)
【发布时间】:2020-07-08 01:28:31
【问题描述】:

我在 Account-A

角色名称lambdarole

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "logs:CreateLogGroup",
                "logs:CreateLogStream",
                "logs:PutLogEvents"
            ],
            "Resource": "arn:aws:logs:*:*:*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "config:PutEvaluations",
                "ec2:DescribeImages",
                "sts:AssumeRole"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

相同的 IAM 角色名称 (lambdarole) 在不同的帐户中创建,例如 Account-B

现在 Account-A 的 lambda 函数需要从 Account-B 获取详细信息,例如( AMI 列表),我们收到以下错误

"errorMessage": "An error occurred (AccessDenied) when calling the AssumeRole operation: User: arn:aws:sts::Account-A:assumed-role/lambdarole/lambda-get-details is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::Account-B:role/lambdarole

谁能帮我解决上述问题。

任何帮助将不胜感激

谢谢

【问题讨论】:

  • 您是否将Account-A 添加为Account-B 中角色的受信任帐户?
  • @franklinsijo 不,我没有将 Account-A 添加为 Account-B 中角色的受信任帐户
  • 错误消息说用户:arn:aws:sts::Account-A:assumed-role/lambdarole/lambda-get-details 无权执行:sts:AssumeRole on resource:arn:aws :iam::Account-B:role/lambdarole
  • 账户之间没有建立信任关系,没有它就无法完成AssumeRole。

标签: amazon-web-services aws-lambda amazon-iam assume-role


【解决方案1】:

Account-A 中,lambdarole 的政策允许对 ARN 的任何角色(包括 Account-B 中的角色)担任角色。此声明已处理此问题

       {
            "Action": [
                "sts:AssumeRole"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }

类似地,在 Account-B 中,lambdarole 角色应包含允许从 Account-A 承担角色的信任策略。

Account-AAccountIDlambdarole Role ARN 添加为 Account-Blambdarole 的 AssumeRolePolicyDocument 中的 Principal。

AssumeRolePolicyDocument 看起来像这样(如果帐户 ID 用作 Principal),

"AssumeRolePolicyDocument": {
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect" : "Allow",
            "Action": "sts:AssumeRole",
            "Principal": {
                "AWS" : "<Account-ID-of-Account-A>"                                
            }
        }
    ]
}

您可以参考here 了解如何使用 IAM 角色建立跨账户访问。

【讨论】:

  • 感谢您提供解决方案。 (lambdarole) 部署在所有帐户上。如果我们使用您建议的 (AssumeRolePolicyDocument) 修改我们的角色 (lambdarole),它将被部署到所有帐户以及部署 lambda 的 Account-A。如果它恰好也部署在 Account-A 上,您是否发现任何问题?
  • AssumeRolePolicyDocument 必须根据部署的帐户进行相应的修改。如果它被部署在 Account-A 上没有问题,如果允许一个帐户信任自己来承担角色,它不会增加任何伤害。
  • 快速提问:AssumeRolePolicyDocument 是否有效,因为我们没有在其中定义任何服务?
  • 它有帐户而不是服务。
  • 谢谢。有没有参考文档链接,我可以浏览一下。
猜你喜欢
  • 1970-01-01
  • 2020-01-16
  • 1970-01-01
  • 1970-01-01
  • 2020-05-06
  • 2017-09-28
  • 1970-01-01
  • 2021-04-13
  • 2018-07-12
相关资源
最近更新 更多