承担的角色不能承担另一个角色

时间:2021-03-30 20:44:34

标签: amazon-web-services spring-boot amazon-iam amazon-eks assume-role

我在使用 AWS EKS 时遇到了角色链接问题,但我无法确定链接不正确的地方。

账户 1 中的角色 A 将担任账户 2 中的角色 B。

角色 A 是 arn:aws:sts::{ACCOUNT-ID-1}:assumed-role/{ROLE-NAME}/{SESSION-NAME}

角色 B 是一个标准:arn:aws:iam::{ACCOUNT-ID-2}:role/{ROLE-NAME}

角色 A 是 assumed-role,因为在部署到 EKS 中时,该角色被假定。

角色 A 的策略是

 {
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "",
            "Effect": "Allow",
            "Action": "sts:*",
            "Resource": "*"
        }
    ]
}

B 的信任策略是

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": {
        "AWS": "*"
      },
      "Action": "sts:AssumeRole",
      "Condition": {
        "StringEquals": {
          "aws:PrincipalOrgID": "{ORD}"
        },
        "ArnLike": {
          "aws:PrincipalArn": [
            "arn:aws:sts::{ACCOUNT-ID-1}:assumed-role/{ROLE-NAME}/{SESSION-NAME}"
          ]
        }
      }
    }
  ]
}

*aws:PrincipalOrgID 在验证时正确匹配

角色假设在SpringBoot中进行

  @Bean
  public WebIdentityTokenCredentialsProvider getCredProvider() {
    return WebIdentityTokenCredentialsProvider.builder().roleSessionName("SESSION-NAME").build();
  }

  public AWSCredentialsProvider assumeRole() {
    AWSCredentialsProvider credentials = getCredProvider();
    AWSSecurityTokenService sts = AWSSecurityTokenServiceClientBuilder.standard()
            .withRegion("us-west-1")
            .withCredentials(credentials)
            .build();
    return new STSAssumeRoleSessionCredentialsProvider.Builder("arn:aws:iam::{ACCOUNT-ID-2}:role/{ROLE-NAME}", "role-b-session")
            .withStsClient(sts)
            .build();
  }

这个角色假设失败了:

com.amazonaws.services.securitytoken.model.AWSSecurityTokenServiceException: 
User: arn:aws:sts::{ACCOUNT-ID-1}:assumed-role/{ROLE-NAME}/{SESSION-NAME}
is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::{ACCOUNT-ID-2}:role/{ROLE-NAME} 
(Service: AWSSecurityTokenService; Status Code: 403; Error Code: AccessDenied;

我不确定为什么上面会根据配置的信任和权限策略以及 Java 代码返回 AccessDenied。

0 个答案:

没有答案