Lesson 6 of 6 Identity Federation and Cross-Account Access

Authenticating and Authorising Application Users and Workloads

This lesson explains how Cognito user pools and identity pools authenticate users and services, how Verified Permissions authorises application actions, and how EKS Pod Identity gives pods IAM permissions.

Learning outcomes

After completing this lesson, you will be able to:

  • Distinguish Cognito user pools from identity pools and the OAuth 2.0 flows they support.
  • Explain when application authorisation belongs in Verified Permissions rather than IAM.
  • Describe how EKS Pod Identity gives pods least-privilege IAM credentials.

Authenticating users with Amazon Cognito

A Cognito user pool is a user directory and OpenID Connect provider. It handles sign-up, sign-in, MFA and account recovery, federates with social identity providers and with enterprise SAML 2.0 or OIDC providers (routing users to their provider, for example by email domain), and issues ID, access and refresh tokens through OAuth 2.0 flows: the authorisation code grant with PKCE for web and mobile apps, and the client credentials grant with custom scopes on a resource server for machine-to-machine access. API Gateway and ALB validate the tokens without custom code.

A Cognito identity pool exchanges a token for temporary AWS credentials mapped to IAM roles, so a mobile or web client can call S3 or DynamoDB directly; policy variables such as the identity ID restrict each user to their own prefix or items.

Sort into groups

User pool or identity pool?

Exam skills 2.1.2

Decide which Cognito component provides each capability.

Log in to try this activity Interactive activities are free with an account.

Authorising inside the application

IAM authorises AWS API calls, not actions on an application's own objects, such as approving an invoice or viewing a patient record. Amazon Verified Permissions is a managed authorisation service for these decisions: rules are written as Cedar policies over principals, actions, resources and context (for example 'managers may approve invoices up to their limit for their own cost centre'), the application calls IsAuthorized for each action, and policies change without redeploying code. Identity sources connect it to Cognito or OIDC tokens, and decisions can be logged for audit.

Scenario questions

Fine-grained authorisation

Exam skills 2.1.2

Choose where application authorisation rules belong.

Log in to try this activity Interactive activities are free with an account.

Workload identity on Kubernetes

Pods on Amazon EKS need AWS permissions without sharing the node's role. EKS Pod Identity associates an IAM role with a Kubernetes service account through the EKS API; an agent on each node supplies temporary credentials to that service account's pods. Roles trust the pods.eks.amazonaws.com service principal, so the same role works in any cluster without per-cluster OIDC providers or trust policy edits, and session tags identify the cluster and namespace. IAM roles for service accounts (IRSA) achieves the same with an OIDC provider per cluster.

The following table maps identity needs to the services that meet them.

NeedService
Customer sign-up and sign-in, social and enterprise federationCognito user pool
Machine-to-machine API access with scopesCognito client credentials grant
Clients call AWS services directly with per-user limitsCognito identity pool
Fine-grained business authorisation rulesAmazon Verified Permissions
Per-application IAM permissions for podsEKS Pod Identity

The following diagram shows how three application identity services fit together in one application for business users and partner systems.

How the three application identity services fit together. Business users sign in through their own identity providers, federated by a Cognito user pool, and partner systems use the client credentials grant. The API on EKS validates the Cognito token, asks Verified Permissions whether each action is allowed under Cedar policies, and reaches AWS resources such as DynamoDB tables with a per-service IAM role through EKS Pod Identity.
Cognito answers who the caller is, Verified Permissions answers whether the business action is allowed, and EKS Pod Identity answers what each microservice may do in AWS.
Worked example

A B2B invoicing platform

A B2B invoicing platform lets enterprise customers' employees sign in with their own identity providers, lets customers' ERP systems call its API without users, and enforces approval limits per employee.

A Cognito user pool federates each customer's SAML or OIDC provider and issues tokens with a custom tenant attribute; ERP systems use app clients with the client credentials grant and an invoices.write scope.

The API on EKS validates tokens and calls Verified Permissions with the employee, the invoice and its amount, so limits are policies rather than code. Each microservice uses its own IAM role through EKS Pod Identity to read only its own DynamoDB tables.

Check yourself

Why is IAM not the right place for a rule such as 'managers may approve expenses up to their limit'?

Show answer

IAM authorises AWS API calls, not actions on the application's own business objects. Verified Permissions evaluates such rules with Cedar policies over the application's principals, actions and resources.

Exam Tips

Remember for the exam

  • Customer sign-in with social or enterprise providers and tokens API Gateway can validate: Cognito user pool.
  • Machine-to-machine access with scopes: Cognito client credentials grant.
  • Fine-grained, policy-based application authorisation: Amazon Verified Permissions with Cedar.
  • Pods in many clusters need distinct IAM roles with least setup: EKS Pod Identity.