Fine grained access control with cognito identity and custom claims

0

I have a cognito identity pool that assigns a principal tag named home. I create credentials with fromCognitoIdentityPool (which ultimately calls AssumeRoleWithIdentity ).

Further, I use these credentials to invoke a lambda named locate which has the following policy for allowing access to only items with primary key same as the value of home:

        - Statement:
            - Action: [dynamodb:GetItem]
              Effect: Allow
              Resource: !Sub "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${PlacesTableName}"
              Condition:
                ForAllValues:StringEquals:
                  dynamodb:LeadingKeys:
                    - "${aws:PrincipalTag/home}"

However, this condition always fails and I get access denied exception: AccessDeniedException: User: arn:aws:sts::...:assumed-role/...-UserRole-.../Locate is not authorized to perform: dynamodb:GetItem on resource: arn:aws:dynamodb:...:table/Places because no identity-based policy allows the dynamodb:GetItem action

Any ideas?

Sankho
已提问 3 个月前205 查看次数
1 回答
1

The "Principal" in this context is the AWS Lambda execution role. This role determines what actions the Lambda function can perform on AWS resources. The ${aws:PrincipalTag/home} condition means the Lambda can only access specific DynamoDB items if the execution role has a matching home tag value. This setup provides targeted access control based on the execution role's tags. If your Lambda execution role doesn't have that tag it will be denied.

Resources:

profile picture
专家
已回答 3 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则