Skip to content

Is it possible to tell Cognito to use the role of a user group instead of the default role using CDK?

0

Is it possible to tell Cognito to use the role of a user group instead of the default role using CDK?

Using CDK I have created an API Gateway, a Cognito User Pool and an Identity Pool. The cognito user pool has several groups, each group has a role with specific policy to grant access to API Gateway routes. Now I need to tell Cognito to use those group roles to evaluate the access to those API gateway routes.
In the console I see this option which I believe is the one that can make the identity pool use the group role.

Enter image description here

I found in [1] this information.

If you set roles for groups in an Amazon Cognito user pool, those roles are passed through the user's ID token. To use these roles, you must also set Choose role from token for the authenticated role selection for the identity pool. You can use the Role resolution setting in the console and the RoleMappings parameter of the SetIdentityPoolRoles API to specify what the default behavior is when the correct role cannot be determined from the token.

I don't see a way in CDK to create this relationship.

I tried the following but it doesn't work.

        CfnIdentityPoolRoleAttachment : {
          roleMappings: {
            roleMappingsKey: {
              type: 'Token', 
              ambiguousRoleResolution: "Deny"
            }
          }
        }

[1] https://docs.aws.amazon.com/cognito/latest/developerguide/role-based-access-control.html#using-tokens-to-assign-roles-to-users

1 Answer
0

Yes, you can configure AWS Cognito to use the roles of user groups for access evaluation using CDK. First, create a Cognito User Pool and add groups, each with a specific IAM role. Then, create a Cognito Identity Pool and associate it with the User Pool, configuring it to use the group roles.

EXPERT

answered 2 years ago

  • Do yo have a CDK code example for this use case ?

  • Can you elaborate on how to configure it to use the group roles? I suspect it has something to do with roleMappings but I have not found a clear example

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.