【问题标题】:AWS 403 Unauthorised Error while trying to create temporary credentials using IAM user尝试使用 IAM 用户创建临时凭证时出现 AWS 403 未经授权的错误
【发布时间】:2015-03-05 13:33:06
【问题描述】:

我正在尝试获取临时凭据以将文件上传到 S3 存储桶。我正在使用 IAM 用户的凭证来调用 STS 假设角色方法。该角色是通过 AWS Cognito 创建的。下面是IAM用户Policy和角色Policy,

错误信息:

POST https://sts.amazonaws.com/ 403 (Forbidden)

User: arn:aws:iam::########:user/iamUser  is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::#########:role/myRole

IAM 用户政策

{
 "Statement": [
   {
     "Effect": "Allow",
     "Action": ["s3:GetBucketLocation", "s3:ListAllMyBuckets"],
     "Resource": "arn:aws:s3:::*"
   },
   {
     "Effect": "Allow",
     "Action": ["s3:ListBucket" ],
     "Resource": [ "arn:aws:s3:::myBucket"]
   },
   {
     "Effect": "Allow",
     "Action": [ "s3:PutObject", "s3:GetObject", "s3:DeleteObject", "s3:GetObjectAcl","s3:PutObjectAcl"],
     "Resource": [ "arn:aws:s3:::myBucket/*"]
   },
   {
   "Effect": "Allow",
   "Action": "iam:PassRole",
   "Resource": ["arn:aws:iam::###########:role/myRole"]
   },
   {
   "Effect": "Allow",
   "Action": "sts:AssumeRole",
   "Resource": ["arn:aws:iam::###########:role/myRole"]
   }
 ]
} 

角色政策

{
 "Version": "2012-10-17",
 "Statement": [
   {
     "Sid": "Stmt1420643359000",
     "Effect": "Allow",
     "Action": [
       "s3:*"
     ],
     "Resource": [
       "arn:aws:s3:::myBucket"
     ]
   }
 ]
} 

【问题讨论】:

  • 角色策略授予 s3 权限,但不授予 STS 权限。它们是不同的。

标签: javascript amazon-web-services amazon-s3 amazon-iam amazon-cognito


【解决方案1】:

Cognito 角色应使用 AssumeRoleWithWebIdentity 调用,而不是 AssumeRole。

你表示这是 JavaScript,你看过JavaScript SDK docs for using Cognito吗?

【讨论】:

    【解决方案2】:

    在角色策略中添加以下行以授予 iam 角色正确的权限。

    IAM 角色和 IAM 用户没有相互共享权限。

    {
      "Sid": "Stmt1420676933473",
      "Action": [
        "sts:AssumeRole"
      ],
      "Effect": "Allow",
      "Resource": "arn:aws:iam::###########:role/myRole"
    }
    

    【讨论】:

      猜你喜欢
      • 2021-01-16
      • 1970-01-01
      • 2019-05-28
      • 2021-09-08
      • 2017-01-19
      • 1970-01-01
      • 1970-01-01
      • 2020-12-20
      • 2011-09-15
      相关资源
      最近更新 更多