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

AWS published a reference architecture and sample CDK stack showing how to give a shared internal assistant fine-grained, per-user access to documents in Amazon Bedrock Managed Knowledge Base. The setup uses AgentCore Gateway to expose the knowledge base to an agent as Model Context Protocol (MCP) tools, and Amazon Cognito for sign-in. The central design rule is that the language model should never decide who the user is; trusted code derives identity from the token the identity provider already validated.
The problem being solved is a familiar one for anyone building multi-tenant retrieval agents. In a conventional application, the server looks up the signed-in user and queries with that user's permissions. In an agent, the model chooses at runtime which tool to call and with what arguments. If the search tool accepts a "search as this user" parameter, the model fills it in, and a prompt injection or a simple model error can make it search as somebody else. AWS's fictional example is an internal assistant where one department's business plan could otherwise surface in another department's answer, or, in a SaaS deployment, one customer's data in another customer's response.
Managed Knowledge Base offers ACL awareness. Search requests carry a top-level userContext object with an email in userId, and the service returns only chunks from documents that user may view. Permissions are captured at ingestion: for an S3 data source, either a global ACL file per prefix or a metadata file stored alongside each document. The sample uses per-document metadata, with fields such as department and year plus an accessControlList array of entries naming a user, a type of USER, and ALLOW. Two search APIs are exposed through the gateway connector: Retrieve, which runs a hybrid search, and AgenticRetrieveStream, which decomposes a query into subqueries and searches iteratively across knowledge bases.
Several ingestion behaviors are worth knowing before adapting the pattern. A document with no ACL entry is not ingested at all. Editing the global ACL file requires reindexing the affected prefix, while per-document metadata reindexes only the changed documents and takes precedence over the global file. ACL changes apply after the next sync rather than in real time, and mistakes fail silently, leaving documents out of results without any error. Queries without userContext return nothing from an ACL-enabled data source, whereas documents in a data source without ACLs are returned to everyone.
Exposed as an MCP tool, userContext becomes just another argument, and neither the gateway nor the knowledge base checks that it belongs to the authenticated caller. So the build adds four layers. Two are primary: a gateway request interceptor, a Lambda function that resolves the email from the validated JWT and overwrites arguments.userContext on every tools/call request, and ACL awareness in the knowledge base, which filters on the injected value. Two are secondary: a Policy in AgentCore evaluation against a Cedar policy that denies a request when userContext.userId does not match the token's email claim, and a resource-based policy on the knowledge base that refuses searches from any principal other than the gateway's execution role.
Details of the interceptor matter for anyone copying it. It fails closed: request bodies that are not a single JSON-RPC object, such as batches, are rejected, as are calls whose token has no email claim and malformed arguments. It writes userContext unconditionally, discarding whatever the client or model sent. Because Cognito access tokens do not include email by default, a pre token generation Lambda trigger (event version V2_0) adds the claim only when the address is verified; that requires an Essentials or Plus user pool, and on a Lite pool every tool call would be denied. AWS lists alternatives, such as the GetUser API, the userInfo endpoint or an ID token, and notes the scope and validation trade-offs of each.
The sample also narrows what the model can control. On the connector target the administrator pins the knowledge base ID in parameterValues, and only fields declared with parameterOverrides are settable as tool arguments, so userContext has to be exposed there even though clients should not set it. AgenticRetrieveStream is configured with generateResponse false, returning raw results so the agent writes the final answer.
Deployment is a single CDK stack in the agentcore-access-control directory of the sample-managed-knowledge-base-patterns repository, which installs aws-cdk-lib 2.274.0 or later. It also deploys a CloudFront-hosted web app and runs the agent, built with Strands Agents, on AgentCore runtime, using Claude Sonnet 5.5 through the global.anthropic.claude-sonnet-5-5 inference profile by default. Prerequisites include Node.js 22 or later, uv, an AWS Region where all four services are available, and IAM rights to create the resources.
The caveats are as substantial as the features. ACL awareness is described as filtering rather than authorization on its own, since the knowledge base trusts whatever userContext it receives, so the resource-based policy should be added if other principals in the account hold bedrock:Retrieve. Matching is by exact email, which means identity providers must keep addresses unique and immutable; the sample disables self sign-up and freezes the email attribute. The post also cautions that Microsoft does not guarantee the correctness of an optional email claim in Entra ID tokens and advises against using it for authorization, and that tokens should never be logged by the interceptor.
Why it matters: teams putting customer-facing or department-scoped agents on Bedrock now have a concrete, deployable pattern that pushes identity resolution out of the model and into token-verified code, which is the kind of control security reviews look for. The silent-failure behavior of ACL mistakes and the reindex-on-sync lag are likely to be the operational pain points in production. A reasonable inference is that this architecture, rather than any single feature, becomes the template enterprises expect from agent gateways that front shared knowledge stores.
Based on reporting from the original publisher. Visit the source for full context and later updates.
Publisher excerpt
Learn how to expose an Amazon Bedrock Managed Knowledge Base to AI agents as MCP tools through Amazon Bedrock AgentCore Gateway while keeping per-user access control. A request interceptor injects verified identity, Policy in AgentCore validates it independently, and a resource-based policy restricts direct access to the knowledge base.