【问题标题】:AWS Assume role with EC2 instance IAM role not workingAWS Assume 角色与 EC2 实例 IAM 角色不起作用
【发布时间】:2016-11-21 18:57:40
【问题描述】:

在我们的应用程序中,我们使用自定义角色访问 aws API。在开发者环境中,我们在 app.config 中提供了 access Key 和 secret key,效果很好。

在 prod 环境中,我们设置了一个对自定义角色具有必要权限的 IAM 角色,并且使用该 IAM 角色启动了 EC2 实例。当我们尝试使用代码切换角色时,我们会遇到以下错误

消息:用户:arn:aws:sts::XXXXXXXXX:assumed-role//i-0490fbbb5ea7df6a8 无权执行:sts:AssumeRole on resource:arn:aws:iam::XXXXXXXXXX:role/

代码:

AmazonSecurityTokenServiceClient stsClient = new AmazonSecurityTokenServiceClient();
AssumeRoleResponse assumeRoleResponse = await stsClient.AssumeRoleAsync(new AssumeRoleRequest
  {
     RoleArn = roleArn,
     RoleSessionName = sessionName
  });

var sessionCredentials = new SessionAWSCredentials(assumeRoleResponse.Credentials.AccessKeyId, assumeRoleResponse.Credentials.SecretAccessKey, assumeRoleResponse.Credentials.SessionToken);

AmazonS3Client s3Client = new AmazonS3Client(sessionCredentials);

政策详情:

"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "arn:aws:iam::account_id:role/role-name"

对此的任何帮助都会很棒。提前致谢。

【问题讨论】:

    标签: amazon-web-services amazon-iam


    【解决方案1】:

    我们通过在自定义角色的受信任关系中添加以下策略解决了该问题。

    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "<ARN of role that has to assume the custom role>"
      },
      "Action": "sts:AssumeRole"
    }
    

    【讨论】:

    猜你喜欢
    • 2019-06-14
    • 1970-01-01
    • 2018-11-10
    • 2018-01-07
    • 2018-07-09
    • 2019-10-26
    • 1970-01-01
    • 2016-08-27
    • 1970-01-01
    相关资源
    最近更新 更多