Skip to content

Add agentcore-identity-cognito-multi-tenant-cdk pattern#3249

Open
sudhansuamz wants to merge 1 commit into
aws-samples:mainfrom
sudhansuamz:sudhansuamz-feature-agentcore-identity-cognito-multi-tenant
Open

Add agentcore-identity-cognito-multi-tenant-cdk pattern#3249
sudhansuamz wants to merge 1 commit into
aws-samples:mainfrom
sudhansuamz:sudhansuamz-feature-agentcore-identity-cognito-multi-tenant

Conversation

@sudhansuamz

Copy link
Copy Markdown

Description

Adds a new serverless pattern: Multi-tenant Amazon Bedrock AgentCore Runtime with Amazon Cognito (agentcore-identity-cognito-multi-tenant-cdk, Python / AWS CDK).

The pattern demonstrates multi-tenant authentication and tenant isolation for an AgentCore Runtime agent using Amazon Cognito as the OAuth 2.0 / JWT identity provider:

  • AgentCore Identity validates the inbound Cognito JWT via a custom JWT authorizer before the request reaches the agent.
  • Two Cognito groups (tenant-acme, tenant-globex) represent tenants. The agent resolves the caller's tenant from the validated cognito:groups claim, requiring exactly one tenant group.
  • A no-argument DynamoDB tool is bound to that tenant's partition, so the model cannot be prompted into reading another tenant's data (pool multi-tenancy model).

What's included

  • CDK infra: Cognito user pool with tenant groups, DynamoDB table, AgentCore Runtime (HTTP) with Authorization header forwarding, scoped IAM execution role.
  • Containerized Strands agent enforcing per-tenant isolation from the validated token.
  • test/ scripts (token minting, data seeding, HTTPS invocation) and README + example-pattern.json.
  • README security section documenting the enforced boundaries and production hardening (dynamodb:LeadingKeys with per-tenant scoped credentials).

Testing

Deployed to a personal AWS account (us-west-2) and validated end to end:

  • acme user -> only acme records; globex user -> only globex records.
  • Prompt-injection asking for another tenant's data -> refused, no leak.
  • Tampered group claim (re-signed payload) -> 401 Invalid Signature at the edge.
  • Invalid token -> 403. User in zero or multiple tenant groups -> rejected, no data.

Stack cleans up fully with cdk destroy.

Add a serverless pattern demonstrating multi-tenant authentication and tenant isolation for an Amazon Bedrock AgentCore Runtime agent using Amazon Cognito as the OAuth 2.0 / JWT identity provider. AgentCore Identity validates the inbound Cognito JWT via a custom JWT authorizer. The agent resolves the caller's tenant from the validated cognito:groups claim (requiring exactly one tenant group) and exposes a no-argument DynamoDB tool bound to that tenant, giving prompt-injection- resistant isolation in the pool multi-tenancy model. Includes CDK infra (Cognito user pool with tenant groups, DynamoDB table, AgentCore Runtime with Authorization header forwarding, scoped IAM role), containerized Strands agent, test/seed scripts, README with a security section and IAM LeadingKeys hardening guidance, and example-pattern.json.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants