首页 > 解决方案 > 如何为 IAM 角色策略模板使用 Cognito 自定义属性

问题描述

在多租户设置中,我需要根据 Congito 自定义属性限制对 S3 存储桶的访问custom:orgId

到目前为止完成:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Federated": "cognito-identity.amazonaws.com"
      },
      "Action": [
        "sts:AssumeRoleWithWebIdentity",
        "sts:TagSession"
      ],
      "Condition": {
        "StringEquals": {
          "cognito-identity.amazonaws.com:aud": "us-east-1:3498beea-a45e-4b5a-xxx-yyy"
        },
        "ForAnyValue:StringLike": {
          "cognito-identity.amazonaws.com:amr": "authenticated"
        }
      }
    }
  ]
}
{
            "Effect": "Allow",
            "Action": "s3:ListBucket",
            "Resource": "arn:aws:s3:::restricted",
            "Condition": {
                "StringLike": {
                    "s3:prefix": [
                        "${aws:PrincipalTag/orgId}/*"
                    ]
                }
            }
}

我代表经过身份验证的用户(使用 Amplify)获取 STS 会话并尝试列出存储桶。我收到 403 错误。

  1. 我在这个设置中缺少什么?
  2. 如何调试/确保 STS 会话请求包含aws:PrincipalTag/orgId

标签: amazon-web-servicesamazon-cognitoamazon-iam

解决方案


推荐阅读