为什么我的 AWS 代入角色无权执行 cognito-idp:AdminGetUser?

Tha*_*han 9 amazon-cognito aws-lambda laravel-vapor

我的 Laravel 应用程序调用AdminGetUser端点。

在本地环境中,成功返回资源。

部署到 Vapor 环境后,失败并出现以下错误消息:

User: arn:aws:sts::xxxx:assumed-role/laravel-vapor-role/xxxx is not authorized to perform: **cognito-idp:AdminGetUser** on resource: arn:aws:cognito-idp:us-east-1:xxxx:userpool/us-east-1_xxxx because no identity-based policy allows the cognito-idp:AdminGetUser action
Run Code Online (Sandbox Code Playgroud)

有什么问题吗?

Erm*_*ary 15

laravel-vapor-role 无权对资源执行:cognito-idp:AdminGetUser:arn:aws:cognito-idp:us-east-1:xxxx:userpool/us-east-1_xxxx

这意味着该laravel-vapor-role角色没有附加合适的策略来为其提供执行该cognito-idp:AdminGetUser操作的权限。

您可以通过两种方式解决此问题:

  1. 将 AWS 托管AmazonCognitoReadOnly策略分配给角色
  2. 向角色添加内联策略,符合授予最小权限的安全最佳实践

如果您预计稍后需要更多只读权限,则将 AWS 托管AmazonCognitoReadOnly策略分配给该角色会更容易、更好。

它将提供对您的身份池和用户池进行只读访问的权限,包括cognito-idp:AdminGetUser以下权限(此处为cognito-idp:Get*文档,此处为直接策略链接):

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "cognito-identity:Describe*",
                "cognito-identity:Get*",
                "cognito-identity:List*",
                "cognito-idp:Describe*",
                "cognito-idp:AdminGet*",
                "cognito-idp:AdminList*",
                "cognito-idp:List*",
                "cognito-idp:Get*",
                "cognito-sync:Describe*",
                "cognito-sync:Get*",
                "cognito-sync:List*",
                "iam:ListOpenIdConnectProviders",
                "iam:ListRoles",
                "sns:ListPlatformApplications"
            ],
            "Resource": "*"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

如果您只需要 的单一权限cognito-idp:AdminGetUser,则创建内联策略并将其分配给角色,该角色仅向特定 Cognito 用户池授予该权限。

下面的图片应该是不言自明的:

在此输入图像描述

在此输入图像描述

在此输入图像描述