Certopolis

AWS Certified Solutions Architect – Associate

Cognito user pools vs identity pools: which do you need

A user pool answers who the user is. It is a user directory and OpenID Connect identity provider that signs users in and issues JSON web tokens. An identity pool answers which AWS resources the user may reach. It exchanges a trusted token for temporary, limited-privilege AWS credentials. Use both when users sign in and then call AWS services such as S3 directly.

User pools

A user pool stores user profiles and authenticates users. Users can sign in directly, or federate through social providers such as Google and Apple, or through enterprise SAML 2.0 and OIDC providers. Whatever the provider, the user pool issues your app one standard set of tokens, so the app handles one token format.

User pools also provide managed sign-in pages, MFA with SMS or TOTP, groups, custom user attributes and token customization. The ID token tells your app who signed in. The access token authorizes calls to your own APIs, for example through an API Gateway authorizer.

A user pool does not need an identity pool. If your app only calls your own API, the user pool's tokens are enough.

Identity pools

An identity pool takes proof of sign-in and returns temporary AWS credentials from AWS STS. It accepts tokens from a user pool, from social providers, from SAML and OIDC providers, and from your own developer-authenticated identities. It can also give limited credentials to guest users who have not signed in.

It controls permissions in two ways. With role-based access control, Cognito picks the IAM role from a default role, from rules over the user's claims, or from the user's group in a user pool. With attributes for access control, it maps claims to session tags, and your policies check aws:PrincipalTag. For example, a session tagged Department: marketing can read a bucket whose policy requires that tag, with no extra role per department.

An identity pool does not need a user pool. It can broker credentials for a provider you already have.

Using both together

The documented flow has three steps. The user signs in through the user pool and receives tokens. The app exchanges a user pool token at the identity pool for temporary AWS credentials. The app uses those credentials to call services such as Amazon S3 and DynamoDB directly from the device.

Where the exam catches people

  • Believing a user pool token can sign requests to S3: AWS credentials come from an identity pool, so exchange the token there first.
  • Believing an identity pool is a user directory: the user pool stores profiles, and the identity pool issues AWS credentials.
  • Believing an app that only calls its own API needs an identity pool: the user pool's tokens can authorize that API.
  • Believing per-department access needs one IAM role per department: attributes for access control map a claim to a session tag that policies can check.
  • Believing every identity pool user must sign in: an identity pool can issue limited credentials to unauthenticated guests.

Written from Amazon Web Services's documentation

Try 3 questions on this

Pick an answer to see why each option is right or wrong.

  1. A mobile app signs users in against an Amazon Cognito user pool and now needs those users to upload directly to Amazon S3 from the device, under permissions that differ by department. The team has the user pool's JSON web tokens and no AWS credentials. Which solution meets these requirements?

    Right. In the game that’s Renown for your Design Secure Architectures building.

    Not that one: B is right. In the game your Design Secure Architectures building would lose a little Renown, and this question would come back later.

  2. A web application authenticates users against a Cognito user pool and calls only its own API, which runs behind Amazon API Gateway. No client code touches an AWS service directly. An architect proposes adding an identity pool so that every user has AWS credentials. The company needs each user's API calls authorized with the least operational overhead. Which solution meets these requirements?

    Right. In the game that’s Renown for your Design Secure Architectures building.

    Not that one: D is right. In the game your Design Secure Architectures building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    An identity pool exists to "sign API requests to AWS services like Amazon Simple Storage Service (Amazon S3) and Amazon DynamoDB", by exchanging a token for credentials. A user pool already produces what this application needs: it "is a user directory for web and mobile app authentication and authorization" and, to the app, "an OpenID Connect (OIDC) identity provider", whose JSON web tokens an API Gateway authorizer validates.

    Written from docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools.html

  3. A company wants its staff to sign in to a new customer-facing app with the corporate SAML 2.0 identity provider, while external customers sign in with Google, and the app itself should see one consistent token format. Which approach will meet these requirements?

    Right. In the game that’s Renown for your Design Secure Architectures building.

    Not that one: C is right. In the game your Design Secure Architectures building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    AWS describes a user pool as "an intermediate service provider (SP) to third-party providers of workforce and customer identities": it can provide SSO "for your organization's workforce identities in SAML 2.0 and OIDC IdPs" and "for your organization's customer identities in the public OAuth 2.0 identity stores Amazon, Google, Apple and Facebook". The normalising is stated outright: "Amazon Cognito user pools accept tokens and assertions from third-party IdPs, and collect the user attributes into a JWT that it issues to your app. You can standardize your app on one set of JWTs while Amazon Cognito handles the interactions with IdPs, mapping their claims to a central token format."

    Written from docs.aws.amazon.com/cognito/latest/developerguide/what-is-amazon-cognito.html