Amazon Bedrock Managed Knowledge Base now supports fine‑grained, ACL‑aware retrieval when the search request includes a userContext containing the caller’s email. By moving the insertion of that email from the LLM‑generated tool call to a trusted Lambda interceptor in the AgentCore Gateway, the architecture guarantees that the search scope matches the authenticated user.
Solution Overview
The core idea is to separate identity verification from the LLM’s tool selection. A Cognito‑issued JWT carries an email claim added by a pre‑token Lambda trigger. The AgentCore Gateway validates the token, then a request interceptor overwrites the userContext argument of the tools/call request with the verified email. The Managed Knowledge Base, which is ACL‑aware, uses that email to filter results to documents the user is permitted to see.
Implementation Steps
- Configure Amazon Cognito to issue JWTs for your users. Add a pre‑token Lambda trigger that injects the user’s email address into the token as the
emailclaim. - Deploy an AgentCore Gateway with a JWT authorizer that checks the token’s signature, expiration, and client identifier.
- Attach a Lambda request interceptor to the gateway. The interceptor extracts the
emailclaim from the validated token and overwrites theuserContextfield of any incomingtools/callrequest. - Ensure the Managed Knowledge Base is configured for ACL awareness. The service will automatically limit returned documents based on the
userIdvalue supplied inuserContext. - Optionally, define a Cedar policy in AgentCore that validates the modified request before it reaches the knowledge base, providing an additional defense layer.
Operational and Security Considerations
Because the LLM no longer decides the userContext, the primary trust anchor becomes the JWT authorizer and the interceptor. Practitioners should monitor the Lambda interceptor for errors that could leave the original user‑supplied value untouched. Logging the overridden value helps detect unexpected behavior.
ACL awareness in the knowledge base is a data‑level filter, not a substitute for broader access‑control policies. It should be combined with any existing organizational policies that govern who can invoke the agent.
Deploying the interceptor as a separate Lambda function isolates the code that manipulates request payloads, simplifying updates and reducing blast radius if a bug is discovered. Ensure the Lambda execution role follows the principle of least privilege, granting only the permissions needed to read the JWT claims and modify the request payload.
Related CloudNinjas coverage: AWS.
What This Means For Practitioners
By moving user identity injection to a trusted gateway layer, engineers can rely on Managed Knowledge Base ACLs to enforce per‑user document visibility without exposing the LLM to prompt‑injection risks. The pattern introduces a clear, auditable point of control, simplifies testing, and adds a policy‑driven safety net. Teams should adopt the interceptor, verify logging, and treat the ACL filter as part of a defense‑in‑depth strategy rather than the sole authorization mechanism.

