Fine-grained access control for Amazon Bedrock Managed Knowledge Base tools

In one sentence

AWS demonstrates how to implement fine-grained access control for AI agents using Amazon Bedrock Managed Knowledge Base and AgentCore Gateway to prevent unauthorized data access.

Key points

  • Exposing a knowledge base as an MCP tool lets the LLM construct the user context, creating risks of prompt injection or errors.
  • The solution injects verified user attributes at the tool layer (AgentCore Gateway) and scopes searches via ACL awareness at the resource layer.
  • A request interceptor (AWS Lambda) on the gateway extracts the email from a validated Amazon Cognito JWT and overwrites the userContext argument.
  • Secondary defenses include using Cedar policies in AgentCore to verify token-context alignment and a resource-based policy restricting searches to the gateway execution role.

In depth

An AI-written overview of the original article, not the article itself.

AWS Machine Learning Blog details how to implement fine-grained access control for AI agents searching internal documents via Amazon Bedrock Managed Knowledge Base and AgentCore Gateway. Because large language models (LLMs) decide tool arguments at runtime, relying on the model to specify user identity risks data leaks through prompt injection or errors.

The Challenge with Agent Access Control

In traditional applications, backend code determines the signed-in user and scopes searches accordingly. In an AI agent, however, the LLM constructs tool arguments dynamically.

When Managed Knowledge Base is exposed as Model Context Protocol (MCP) tools through AgentCore Gateway, userContext becomes a tool argument. If the LLM sets this value, an error or prompt injection could cause the agent to search as another employee or tenant.

A Four-Layer Defense Architecture

The article's core principle is that trusted code, not the LLM, must determine user identity. It combines primary and secondary defenses across two layers.

At the tool layer (AgentCore Gateway), a request interceptor Lambda function serves as the primary defense by extracting the verified email from the Amazon Cognito JWT and overwriting userContext. As a secondary defense, Policy in AgentCore evaluates a Cedar policy to deny requests where userContext.userId does not match the token's email claim.

At the resource layer (Managed Knowledge Base), ACL awareness acts as the primary defense by returning only documents the userContext user can view. A resource-based policy provides secondary defense by blocking search requests from any principal other than the gateway execution role.

Key Implementation Details

Since Cognito access tokens omit the email claim by default, the architecture uses a pre-token generation Lambda trigger (event version V2_0) to add verified emails, requiring a Cognito Essentials or Plus plan.

For Amazon S3 data sources, ACLs are defined via per-document metadata files or global ACL files, and updates take effect after the next sync. The sample stack is deployable via AWS CDK and uses Strands Agents with Claude Sonnet 5.5.

Read originalOpens aws.amazon.com

This summary was generated by AI from the original article and may contain errors; the original is authoritative. Copyright belongs to the original author.

Recent stories from this source