首页 > 解决方案 > 不允许:no-auth-role/CognitoIdentityCredentials 无权执行:geo:ListGeofences on resource:xxxxx

问题描述

我正在尝试使用 SDK 本身(位置)中的一些新的 Amazon 位置服务端点,但遇到了一些不一致的错误。

即使 IAM 角色中允许的所有内容geo:*(每个资源都相同),我总是发现诸如locationClient.listGeofences.

随意,其他一些函数,如getMapStyleDescriptor,searchPlaceIndexForTextcalculateRoute不给出问题。这些函数在 中使用它们各自的策略geo:...,因此看到它如何检测到某些策略而其他策略不让我感到非常困惑。

该错误很常见,它显示以下内容以及已允许的策略:

Uncaught (in promise) AccessDeniedException: User: arn:aws:sts::xxxx:assumed-role/AmazonLocationTestRole/CognitoIdentityCredentials is not authorized to perform: geo:ListGeofences on resource: arn:aws:geo:eu-west-1:xxxx:*

请注意,该访问权限适用于在 Cognito 中具有身份池的未经身份验证的用户,但这不应该是问题。

                const client = new AWS.Location({
                    credentials: credentials,
                    region: AWS.config.region
                });

                console.log(await client.listGeofences({
                    CollectionName: "explore.geofence-collection"
                }).promise())

                console.log(await client.getMapStyleDescriptor({
                    MapName: mapName
                }).promise());

以防万一,IAM 角色中的信任关系如下所示:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": {
        "Federated": "cognito-identity.amazonaws.com"
      },
      "Action": "sts:AssumeRoleWithWebIdentity",
      "Condition": {
        "StringEquals": {
          "cognito-identity.amazonaws.com:aud": "eu-west-1:xxxx"
        },
        "ForAnyValue:StringLike": {
          "cognito-identity.amazonaws.com:amr": "unauthenticated"
        }
      }
    }
  ]
}

并且已经允许针对 Amazon Location Service 中的每个资源的每个策略。

你知道会发生什么吗?

非常感谢!

标签: amazon-web-servicesaws-sdkamazon-cognitoamazon-iam

解决方案


根据https://docs.aws.amazon.com/location/latest/developerguide/authenticating-using-cognito.html#cognito-create-user-pool未经身份验证的身份只能访问以下操作:

  1. 地理:获取地图*
  2. 地理:SearchPlaceIndex*
  3. 地理:BatchUpdateDevicePosition
  4. 地理:计算路线

推荐阅读