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

· Original article ↗

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

Products

Related Articles