DynamoDB - Fine grain control scoped to Cognito User

1

I have a table that will contain rows of data for all users of the app. But I only want User A to access rows added by User A, User B to access User B's rows, etc. So its essentially a user-scoped database.

IAM Policy

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "dynamodb:PutItem",
                "dynamodb:GetItem",
                "dynamodb:DeleteItem",
                "dynamodb:Query",
                "dynamodb:Scan"
            ],
            "Resource": "arn:aws:dynamodb:us-east-1:0000000:table/my-table",
            "Condition": {
                "ForAllValues:StringEquals": {
                    "dynamodb:LeadingKeys": [
                        "${cognito-identity.amazonaws.com:sub}"
                    ]
                }
            }
        }
    ]
}

I believe the "cognito-identity.amazonaws.com:sub" for my user is: us-east-1:XXXXX

My id for rows is us-east-1:XXXXX#uuid1 but us-east-1:XXXXX cant access it. I get: AccessDeniedException

However, the following condition worked:

"Condition": {
  "ForAllValues:StringEquals": {
    "cognito-identity.amazonaws.com:sub": [
      "us-east-1:XXXXX"
    ]
  }
}
  • Can you pull the error out of CloudTrail? That should hopefully give more info.

  • CloudTrail just shows DescribeTable but not PutItem calls.

1개 답변
0

Hi. From a quick glance, the policy looks to be correct.

Have you done the following as well:

  • Use the Cognito ID as the hash key for DynamoDB
  • Validated proper access to the KMS Key (If used) for the User.

How are you connecting the users to access the DynamoDB Table? Are you using a role that grants access to a Cognito Identity Provider and do you have a user pool group set up for your Cognito users in Cognito?

jsonc
답변함 2년 전
  • Use the Cognito ID as the hash key for DynamoDB

    hash key? The id field (Partition key) has CognitoID#ItemUUID

    How are you connecting the users to access the DynamoDB Table?

    IdentityPool group has IAM policy mentioned in question.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠