How to Enforce Per-User Elasticsearch Access in Amazon Bedrock AgentCore

Summary
Elastic's guide configures an OAuth MCP connection between Amazon Bedrock AgentCore and Elasticsearch so queries use each signed-in user's permissions, with steps to test role-based access and revoke a user's connection.
Key points
- A shared API key makes agent users query Elasticsearch as the same Elastic identity; the guide instead uses an OAuth MCP client so calls run with the signed-in user's roles.
- The integration connects Elastic Cloud Serverless and Agent Builder to AgentCore Identity and Gateway; OAuth MCP clients are available only for Serverless projects.
- The walkthrough covers OAuth client setup, AgentCore outbound authentication, gateway configuration, and an optional local HTTPS callback server and test scripts.
- A test using a limited Elastic role returns only the permitted visible-index-only-test index, not the dummy-data index.
- AgentCore Gateway supports an aggregated MCP target with a manually refreshed tool-list cache or a passthrough target that fetches the list from Elastic each time.
- Revoking a user's OAuth connection takes effect on the Elastic side immediately, but existing gateway calls can fail until the stored token expires, for up to one hour; reauthorization can be forced.
Article Details
- Defense Focus
- Enforce per-user Elasticsearch access for AgentCore agents through OAuth so each tool call uses the signed-in user's permissions, and revoke an individual user's connection without changing other users' access.
- Detection Methods
- Test with a limited Elastic user and confirm that search results include only indices allowed by that user's role.
- After revoking a connection, verify that a request using its revoked token is rejected; the article says the rejection takes effect immediately on the Elastic side.
- Data Sources
- Elasticsearch tool-call results and rejected-token responses
- The WWW-Authenticate header or response body containing a reauthorization link
- Defensive Actions
- Use an OAuth MCP client and configure AgentCore Gateway for authorization-code grant rather than sharing a single Elasticsearch API key across users.
- Assign users roles with only the required index and Agent Builder permissions.
- Revoke an individual user's OAuth connection when they no longer need agent access; revoke all connections or delete selected individual connections.
- Account for the gateway continuing to send a stored token until it expires, for up to one hour; use forceAuthentication to prompt for reauthorization sooner.
Vendors
Amazon Web ServicesAn AWS account with access to Amazon Bedrock AgentCore in a Region where it's available, plus permission to use AgentCore Identity, AgentCore Gateway, Amazon Cognito, and AWS Secrets Manager.ElasticGet started with an Elastic Cloud Trial, and check out the documentation for Agent Builder here.
Products
Amazon Bedrock AgentCoreMost Amazon Bedrock AgentCore agents serve more than one person, and those people rarely have access to the same data. A support engineer needs customer tickets, while a contractor should only see the public docs. IfAmazon CognitoAn AWS account with access to Amazon Bedrock AgentCore in a Region where it's available, plus permission to use AgentCore Identity, AgentCore Gateway, Amazon Cognito, and AWS Secrets Manager.AWS Secrets ManagerAn AWS account with access to Amazon Bedrock AgentCore in a Region where it's available, plus permission to use AgentCore Identity, AgentCore Gateway, Amazon Cognito, and AWS Secrets Manager.Elastic Agent BuilderRead access to Elastic Agent Builder in that project (required for creating the MCP client).Elastic Cloud ServerlessIn this post, I connect AgentCore Gateway to an Elastic Cloud Serverless (Serverless) project through an OAuth Model Context Protocol (MCP) client instead. Each user signs in to Elastic once and authorizes the gateway.Elasticsearchneeds customer tickets, while a contractor should only see the public docs. If your agent connects to Elasticsearch with a single API key, both of these users query as the same Elastic identity, and the agent could
