Keeping Agent Searches Scoped to the Right User
Companies increasingly share one AI agent and one document store across many employees or customers, and the agent writes its own search queries. In a normal app, code decides who the user is; in an agent, the LLM picks the tool arguments at runtime, so a prompt injection or a model mistake could make it search as someone else. The author's example: an employee in department A asks for a comparison and ends up seeing department B's business plan.
Companies increasingly share one AI agent and one document store across many employees or customers, and the agent writes its own search queries. In a normal app, code decides who the user is; in an agent, the LLM picks the tool arguments at runtime, so a prompt injection or a model mistake could make it search as someone else. The author's example: an employee in department A asks for a comparison and ends up seeing department B's business plan.
The design principle is simple: never let the LLM produce a value that affects authorization. The author exposes Amazon Bedrock Managed Knowledge Base as MCP tools through AgentCore Gateway, then has a Lambda request interceptor overwrite the userContext argument on every tools/call with the email taken from the JWT the gateway already validated. The knowledge base's ACL awareness then returns only documents that user may view. Two optional layers back this up: a Cedar policy in AgentCore denies any request whose userContext doesn't match the token's email claim, and a resource-based policy blocks direct knowledge base calls from principals other than the gateway role. The author is candid about identity plumbing: Cognito access tokens lack an email claim by default, so a pre-token-generation trigger adds it, which requires the Essentials or Plus plan; alternatives like GetUser, userInfo, or an ID token each carry extra scopes or validation work, and Microsoft Entra ID's email claim isn't guaranteed correct or immutable. Because ACL matching is an exact email match, the sample disables self sign-up and makes email immutable. In the demo, user-a asks the agent to search as user-b; the spoofed argument appears in the UI, but only user-a's documents come back.
If you build multi-tenant agents, treat identity as something trusted code injects, not something the model chooses, and add independent checks where a bypass is plausible. The pattern is AWS-specific, but the principle applies to any tool argument that controls access.