Securing AI agent tool calls on Amazon Bedrock AgentCore Gateway with Ping Identity
On this page
- When to use it
- Design principles
- Architecture
- Tokens on each hop
- How each exchange works
- Delegation or impersonation at the Gateway
- Policy at the Gateway
- Approvals with CIBA
- Approval records
- Protocol and clients
- MCP server requirements
- Variant: PingFederate
- Security checklist
- Timing and limits
- Lessons from the demo
- Verify a deployment
- Related resources
This reference architecture puts identity and fine-grained authorization around the tools an AI agent uses. The signed-in user's identity travels with every call, a central PingOne Authorize policy decides each MCP tool call at AgentCore Gateway, and sensitive calls wait for the user's approval on another device through CIBA.
It's distilled from a working demo: a user-admin agent on AgentCore Runtime that manages accounts in business systems through MCP servers. For step-by-step setup of the same deployment, see the setup guide. This page covers the design: the components, the trust between them, the decisions you'll make, and what we learned building it.
Architects and security engineers designing agentic applications on AWS with Ping Identity. It assumes working knowledge of OAuth 2.0, OpenID Connect and the Model Context Protocol (MCP).
When to use it
Use this pattern when:
- An agent acts for a signed-in user against business systems that you expose as MCP servers.
- Whether a call may run depends on who the user is, which tool the agent picked, and the tool's arguments, not only on whether the agent can reach the server.
- Some actions are sensitive enough that the user must confirm each one outside the chat.
- Several MCP servers, often owned by different teams, should share one authorization policy without each server implementing it.
Consider something else when the agent works with no user at all (a client credentials token has no user to carry forward, and the Gateway's targets list no tools for it), or when each MCP server must make its own authorization decisions.
Design principles
- The user's identity on every hop.Tokens are exchanged, never passed along. Each hop gets a new token that is valid only at the next hop, names the user in
sub, and names who is acting for them inact(RFC 8693 token exchange). - One decision point for every tool call.Authorization lives in PingOne Authorize, outside the agent and the MCP servers. The security team changes rules without redeploying either, and a tool nobody wrote a rule for is refused.
- The model never holds the approval.The policy asks for approvals and the Gateway's authorizer runs them. The agent, and anything that can inject a prompt into it, can't start, skip or fake one.
- Approvals are bound.An approval covers one user, one exact request, one use, for a limited time.
- Standard protocols and stock clients.OAuth 2.0 Token Exchange, OpenID CIBA, and MCP 2026-07-28 multi round-trip requests. Stock MCP clients complete approvals with no approval code in the agent.
- Refusals explain themselves.Every denial carries the policy's reason in plain words, and the agent shows it to the user.
- Fail closed.When the authorizer can't reach a decision, the call is refused.
Architecture
- The user signs in.The chat app signs the user in with PingOne (authorization code with PKCE). The token is valid only at the agent runtime.
- The agent gets a Gateway token and calls a tool.The agent exchanges the user's token through AgentCore Identity for one valid only at the Gateway, with
actnaming the agent, and sendstools/callto AgentCore Gateway. - The authorizer asks PingOne Authorize.The Gateway runs the authorizer Lambda as its request interceptor. The Lambda sends the MCP request to PingOne Authorize API Access Management, which applies the policy: permit, deny with a reason, or ask for approval.
- A sensitive call waits for approval.The Lambda starts a CIBA request with PingOne, which reaches the user on another channel, and holds the call while it polls. The agent's MCP client retries the same call until the user answers.
- The approved call goes ahead once.The Lambda checks the approval belongs to this user and this request, asks PingOne Authorize again with a trusted approval header, and records the approval as used in DynamoDB.
- The MCP server gets its own token.The Gateway's target exchanges the Gateway token through AgentCore Identity for a token valid only at that MCP server, then forwards the call.
| Component | Service | Role |
|---|---|---|
| Chat app | Your frontend | Signs the user in and sends prompts to the agent with the user's token. |
| Agent | AgentCore Runtime | Validates the user's token with its inbound JWT authorizer, gets a Gateway token through AgentCore Identity, and calls tools over MCP. |
| Token exchange | AgentCore Identity | OAuth credential providers run the on-behalf-of token exchanges with PingOne, one for the agent and one for the Gateway's targets, and keep their client secrets. |
| Tool gateway | AgentCore Gateway | One MCP endpoint for every tool. Validates the Gateway token, runs the authorizer on each request and response, and gets a new token for each target. |
| Authorizer | AWS Lambda | Sends each MCP request to PingOne Authorize, runs CIBA approvals when the policy asks, and enforces approval binding and single use. |
| Approval records | Amazon DynamoDB | Binds approvals to requests and records each use. Items expire on their own. |
| Identity provider | PingOne SSO | Signs users in, runs the token exchanges, and issues audience-restricted tokens that carry the user's application permissions. |
| Policy decision point | PingOne Authorize (API Access Management) | Decides every MCP request from the token's permissions and the request body. |
| Approvals | PingOne CIBA with a DaVinci flow | Asks the user to approve or decline on another channel, such as email. |
| MCP servers | Your services | Validate their own tokens and run the tools. |
Tokens on each hop
Three tokens carry the user through the system. Each is minted for one audience, so a token stolen from one hop is useless at the next.
| Sign-in token | Gateway token | MCP server token | |
|---|---|---|---|
| Issued | To the chat app at sign-in | By exchange, for the agent | By exchange, for the Gateway's target |
| Audience | The agent runtime | AgentCore Gateway | That MCP server's URL |
sub | The user | The user, from the subject token | The user, from the subject token |
act | None | The agent | The Gateway acting for the agent, or the agent alone (see the Gateway hop) |
| Scopes | agent:invoke | mcp:tools | The scopes that server checks, for example crm:users.read |
| User's permissions | p1.permissions | p1.permissions, read by the policy | Not needed |
| Validated by | AgentCore Runtime's JWT authorizer | The Gateway's JWT authorizer, then PingOne Authorize | The MCP server itself |
The user's permissions come from PingOne application roles (in the demo, help-desk with read and write, iam-admin adding delete). They reach tokens as p1.permissions, so the role check happens in PingOne and in the policy, never in the agent.
How each exchange works
Both exchanges use AgentCore Identity OAuth credential providers configured for on-behalf-of token exchange. Neither the agent nor the Gateway handles client secrets or talks to PingOne's token endpoint directly.
- Agent to Gateway. The agent calls
GetWorkloadAccessTokenForJWTwith the user's token, thenGetResourceOauth2Tokenwithoauth2Flowset toON_BEHALF_OF_TOKEN_EXCHANGEand the Gateway's scopes. - Gateway to MCP server. Each target's credential provider configuration has
grantTypeTOKEN_EXCHANGEand the server's scopes. The Gateway runs the exchange for every call, with the Gateway token as the subject.
In both, the credential provider first gets an actor token: a client credentials token for its own PingOne application, for a dedicated actor scope. It then sends PingOne a token exchange request with the user's token as subject_token, the actor token as actor_token, the requested scopes, and its own client authentication. PingOne picks the audience from the scopes and builds the new token's claims with attribute mappings on that resource: sub from the subject token, act from the actor token.
{
"name": "agent-obo",
"credentialProviderVendor": "CustomOauth2",
"oauth2ProviderConfigInput": {
"customOauth2ProviderConfig": {
"oauthDiscovery": { "discoveryUrl": "<DISCOVERY_URL>" },
"clientId": "<AGENT_APP_ID>",
"clientSecret": "<AGENT_APP_SECRET>",
"clientAuthenticationMethod": "CLIENT_SECRET_BASIC",
"onBehalfOfTokenExchangeConfig": {
"grantType": "TOKEN_EXCHANGE",
"tokenExchangeGrantTypeConfig": {
"actorTokenContent": "M2M",
"actorTokenScopes": ["actor"]
}
}
}
}
}
AgentCore Identity sends the generic JWT token type as subject_token_type by default, and PingOne rejects it. Send subject_token_type urn:ietf:params:oauth:token-type:access_token as a custom parameter on both exchanges: in the agent's GetResourceOauth2Token call and in each target's credential provider configuration.
Limiting who can exchange
- Resource access. Give each resource's scopes only to the application that should exchange for them: the Gateway's scopes to the agent's application, each MCP server's scopes to the Gateway's exchange application.
- A required
act. Mark theactattribute mapping as required. When its expression returns null, PingOne refuses the token instead of issuing one withoutact. Use this to refuse an exchange with no actor token, or one whose actor isn't the application you expect. - Actor tokens that open nothing. Give the
actorresource an audience that no service accepts and no scope butactor, so an actor token works only inside an exchange.
PingOne details that shape the design
- PingOne picks the resource, and so the audience, from the requested scopes. It ignores the RFC 8707
resourceparameter, and a token covers one resource. Keep scope names unique across resources, for example by prefixing each MCP server's scopes (crm:users.read). - Resource audiences must be https URIs. They don't have to resolve, but PingOne and AWS must use the same value.
- The Gateway's allowed scopes mean "any of": a token with one of them is accepted.
Delegation or impersonation at the Gateway
The first exchange is always delegation: the agent presents an actor token, and the Gateway token names the agent in act. At the second exchange you choose whether the Gateway presents its own actor token.
| Delegation | Impersonation | |
|---|---|---|
| Actor token at the Gateway's exchange | Yes: actorTokenContent M2M | No: actorTokenContent NONE |
MCP server token's act | The Gateway, acting for the agent (nested, RFC 8693 section 4.1) | The agent, carried over from the Gateway token |
| What the MCP server can see | User, agent and Gateway | User and agent |
| What limits the exchange | The exchange application's scope access, plus the act mapping | The exchange application's scope access |
| Actor resource used at this hop | Yes | No |
| Choose it when | Downstream services audit or authorize on the full chain, or must know a call came through the Gateway | You treat the Gateway as infrastructure rather than an actor, and want the simpler configuration |
In this architecture the MCP servers don't authorize on act; the policy at the Gateway does. So the choice changes what the server's token records, not what is enforced. AgentCore Identity also accepts AWS_IAM_ID_TOKEN_JWT as actor token content, which this architecture hasn't evaluated.
Policy at the Gateway
AgentCore Gateway runs a Lambda interceptor on every MCP request and response. The authorizer Lambda sends each request to PingOne Authorize API Access Management through its sideband API, so the Gateway is protected the way any other API behind PingOne Authorize is. In API Access Management, the Gateway is one API service with one operation, POST /mcp, because every MCP request goes there. The policy reads the rest from the request.
| The policy reads | From | Example |
|---|---|---|
| The user's permissions | The validated Gateway token | users:read, users:delete |
| JSON-RPC method | Body, $.method | tools/call |
| Tool | Body, $.params.name, as <target>___<tool> | crm___delete_user |
| Tool arguments | Body, $.params.arguments | user_name, email |
| Approval | Header x-ciba-approval, which only the authorizer can set | approved |
A policy shaped like this covers most tool sets. Order matters: rules are checked first to last.
| # | When | Effect |
|---|---|---|
| 1 | The request isn't a tool call (initialize, tools/list) | Permit |
| 2 | The tool's operation (read, write or delete) isn't in the user's permissions | Deny, with reason |
| 3 | The arguments name something the user may not touch, such as an account outside the managed set | Deny, with reason |
| 4 | A sensitive tool, and x-ciba-approval isn't approved | Ask for approval |
| 5 | A known tool that passed the checks above | Permit |
| 6 | Anything else, including tools added later | Deny, with reason |
- Match tools by suffix (
ends with ___delete_user): the Gateway prefixes each tool with its target's name. - Give every deny an auth-challenge statement whose
errorDescriptionis the reason. That's how the reason reaches the user. - Ask for approval with an unconditional deny whose auth-challenge asks for the
ciba-approvalACR. The authorizer runs CIBA instead of passing the challenge on. - Keep every deny ahead of the approval rule, so nobody approves a call the policy would refuse anyway.
What the agent receives
| Outcome | Response to the MCP client |
|---|---|
| Permit | The tool's result |
| Policy denial | HTTP 200, JSON-RPC error -32081; message is the rule's reason |
| Approval pending | HTTP 200, result input_required with a sealed requestState |
| Authorizer refusal | HTTP 200, JSON-RPC error -32080 with data.reason, such as approval_denied, approval_expired, approval_mismatch or approval_already_used |
| No decision possible | HTTP 5xx, -32603: the authorizer fails closed |
Refusals travel in-band as HTTP 200 JSON-RPC errors on purpose. A transport-level 401 or 403 ends a stock MCP client's session, and most clients pass the model only the error's message, so the reason goes there in plain words.
Approvals with CIBA
If the agent started approvals, the model would be in the loop, and a prompt injection could skip the step or get something else approved. So the policy decides when an approval is needed, and the authorizer runs OpenID CIBA (Client-Initiated Backchannel Authentication) itself. The user answers on another channel, such as an email link or a push notification, and the call goes ahead only after that.
The authorizer returns the MCP 2026-07-28 input_required result, the protocol's multi round-trip request, with only an opaque requestState. It means "not yet, call again". This suits CIBA:
- Nothing to ask in the chat. The user answers on their other channel. An in-chat question such as an elicitation would route the approval through the agent's own client, where the model sits.
- The interceptor can answer.
input_requiredis an ordinary result, so the authorizer returns it before the call reaches a target, and the Gateway passes it through. - Every retry is checked again. Each round is a new request through the authorizer and, once approved, through PingOne Authorize.
- Stock clients do the waiting. MCP SDK 2.x and Strands Agents 1.64 retry on their own; the agent needs no approval code.
| Guarantee | How it's enforced |
|---|---|
| The same user | The approver's sub must equal the caller's. requestState names the caller and is refused for anyone else. |
| The same request | requestState carries a SHA-256 fingerprint of the method and parameters. The approval is also bound to the request in DynamoDB before it's redeemed (with PingFederate, through authorization_details). |
| Once | A conditional write of a spent record in DynamoDB. A second use is refused with approval_already_used. |
| For a limited time | The CIBA request's expiry, and an expiry inside requestState. |
| Only the authorizer marks a call approved | The trusted x-ciba-approval and x-ciba-approver headers are stripped from every client request; the authorizer sets them only after checking the approval. |
| No tampering | requestState is sealed with HMAC-SHA256 and a secret key. It's readable, so it never carries secrets. |
The authorizer removes requestState, inputResponses and the trusted headers before it forwards the call, so MCP servers never see the approval machinery. The user sees the approval code (such as APR-4821) in the approval request. Stock clients don't expose it to the app; an agent that drives the rounds itself (allow_input_required=True in MCP SDK 2.x) can show it in the chat after the first round.
Approval records
The authorizer is stateless, and the identity provider records that an approval was given, not which request used it. A small DynamoDB table fills that gap.
| Record | Written | Purpose |
|---|---|---|
request#… | When the CIBA request starts (PingOne) | Binds the approval to the exact request. Checked before the approval is redeemed, so a mismatched request can't use it up. |
spent#… | When an approved call is forwarded, as a conditional put | Makes each approval usable once. |
- One table: partition key
pk(string), TTL onttl, on-demand capacity. Items expire after a day by default, never sooner than the approval. - The authorizer needs only
dynamodb:GetItemanddynamodb:PutItemon it. - Records hold hashes and markers, no tokens or secrets.
- The table stays with PingFederate too:
authorization_detailsreplaces therequestrecord, not thespentrecord.
Protocol and clients
Approvals rely on MCP 2026-07-28 multi round-trip requests, so the Gateway offers only that version. Older clients can't connect, rather than connecting and failing at their first approval.
"protocolType": "MCP",
"protocolConfiguration": {
"mcp": { "supportedVersions": ["2026-07-28"] }
},
"authorizerType": "CUSTOM_JWT",
"authorizerConfiguration": {
"customJWTAuthorizer": {
"discoveryUrl": "<DISCOVERY_URL>",
"allowedAudience": ["<GATEWAY_AUD>"],
"allowedScopes": ["mcp:tools"]
}
}
- Agents: MCP Python SDK 2.0 or later, or Strands Agents 1.64 or later with its
MCPClient. An MCP SDK 1.x client fails with "Unsupported protocol version from the server: 2026-07-28". - MCP servers keep their own protocol versions. The Gateway negotiates with each target separately.
update-gatewayreplaces the whole configuration. SendprotocolConfigurationand the interceptors with every update; without them the Gateway falls back to its default versions and approvals stop working.
AgentCore Gateway currently passes the client's 2026-07-28 fields in params._meta on to MCP servers it talks to at an older version. A server that ignores them works. A server that checks them against the request's headers refuses every request. The authorizer can't remove them, because the Gateway requires them in its output. Test each MCP server behind the Gateway before you rely on it.
MCP server requirements
- Reachable over HTTPS with streamable HTTP.
- Validate every token: signature against PingOne's keys, issuer, audience equal to the server's own URL, expiry, and the scope each tool needs. The token is minted for that server alone.
- Tools that act on a person take that person's username as an argument (the demo uses
user_name), so the policy can read it. Avoid internal IDs the policy can't reason about. - Keep your own guard rails. The demo's servers also refuse to change accounts outside a managed email domain, whatever the policy says.
- Optionally publish RFC 9728 protected resource metadata, so MCP clients can discover PingOne and the scopes.
Variant: PingFederate
Organizations that run PingFederate can keep it as the authorization server and still use PingOne MFA for approvals and PingOne Authorize for decisions.
| Reference (PingOne) | PingFederate variant | |
|---|---|---|
| Sign-in and token exchange | PingOne SSO | PingFederate, self-managed, for example on Amazon EC2 |
| Approval channel | PingOne CIBA with a DaVinci flow (email in the demo) | PingFederate CIBA with the PingOne MFA Integration Kit's CIBA authenticator, pushing to the PingOne MFA app |
| Authorizer setting | CIBA_PROVIDER=pingone | CIBA_PROVIDER=pingfederate |
| Binding message | Up to 8 characters | Up to 20 characters |
| Binding the approval to the request | request record in DynamoDB | authorization_details (PingFederate 11.2 or later) |
| Single use | spent record in DynamoDB | spent record in DynamoDB |
| Policy | PingOne Authorize | PingOne Authorize |
Points to design for in this variant:
- Where the user's permissions come from. PingOne application roles fill
p1.permissions; with PingFederate, issue the permissions as a claim (for example from directory groups) and point the policy at it. - How PingOne Authorize validates PingFederate's access tokens for the Gateway's API service.
- The
actmappings move into PingFederate's token exchange configuration.
Security checklist
- Every token is audience-restricted to one hop. The user's sign-in token never reaches the Gateway or an MCP server.
- Role checks happen in PingOne and in the policy, not in the agent's prompt or code.
- The policy denies by default, and every deny carries a reason.
- Only the authorizer can mark a call approved. Approvals are bound to one user and one request, usable once, and expire.
- The authorizer never returns the caller's
Authorizationheader. AgentCore would send it to the target in place of the target's exchanged token. - The
requestStatekey is at least 32 random bytes, kept secret (for example in AWS Secrets Manager), and stable across deployments; changing it voids approvals in progress. - Least-privilege IAM: the Gateway's role reaches only its credential providers, their secrets and the authorizer; the authorizer's role reaches only its logs and its table; the runtime's role reaches only the agent's credential provider.
- Log decisions and approval outcomes, never tokens.
- The authorizer fails closed when PingOne Authorize, the CIBA provider or DynamoDB can't be reached.
Timing and limits
An approval has to fit inside the client's patience and the Lambda's timeout. These values work together; change them together.
| Setting | Demo value | Constraint |
|---|---|---|
Hold per round (CIBA_HOLD_SECONDS) | 20 s | Well under the Lambda timeout, and under the client's read timeout |
| Client retries | 10 | Fixed in MCP SDK 2.x and Strands Agents, almost no pause between rounds |
| Client's total wait | About 220 s | The first call plus 10 retries, each held up to 20 s |
Approval lifetime (CIBA_REQUESTED_EXPIRY) | 180 s | Below the client's total wait, so the user gets approval_expired instead of a generic error. PingOne allows up to 300 (default 120). |
| Lambda timeout | 60 s | The hold plus a sideband call, a provider poll and two DynamoDB calls |
| Binding message | APR-4821 | PingOne: up to 8 characters. PingFederate: up to 20. |
| Approval records | 24 h | Never shorter than the approval lifetime |
| Forwarded header size | 4 KB | An AgentCore limit. Response-phase authorization passes about 6 KB of state in a header, so the demo turns it off. |
Other limits of the authorizer as built for the demo: streaming responses pass through without response-phase authorization, batched JSON-RPC requests can't be approved, and the header that carries a denial's reason from the request phase to the response phase isn't signed.
Lessons from the demo
- Don't echo the Authorization header. When an interceptor returns one, AgentCore sends it to the target instead of the token the target's exchange would mint. Every user saw an empty tool list until the authorizer stopped returning it.
- Pass unchanged responses through explicitly. If the response interceptor returns nothing, AgentCore sends the client an empty
{}. - Set the subject token type on every exchange. AgentCore's default generic JWT type is rejected by PingOne.
- Return refusals as HTTP 200 JSON-RPC errors. A 403 ends a stock client's session, and clients drop error data the model never sees.
- Give people time to find the approval, but less than the client waits. Email approvals need more than PingOne's 120-second default; 180 seconds still ends before the client gives up.
- Test with real users. Targets list their tools by exchanging the user's token, so a client credentials token sees no tools, and a smoke test with one proves little.
- Try every MCP server behind 2026-07-28 before you rely on it (see the known issue under Protocol and clients).
- Resend the full Gateway configuration on every update. A partial
update-gatewaysilently drops the protocol version list and the interceptors. - Mind the CA bundle. MCP SDK 2.x uses httpx2, which trusts the operating system's certificate store rather than certifi. Runtime images without one need
verify=ssl.create_default_context(cafile=certifi.where()).
Verify a deployment
| As | Try | Expect |
|---|---|---|
| A user who may read | A look-up | The tool runs. The MCP server receives a token with its own audience, the user as sub, and act. |
| A user who may not delete | A delete | -32081 with the rule's reason. The MCP server is never called. |
| A user who may delete | A delete, then approve | An approval request with a code. The client retries on its own, and the delete runs once. |
| A user who may delete | A delete, then decline | -32080 with approval_denied. The MCP server is never called. |
| Any user | Replay an approved call's requestState, or change its arguments | -32080. The MCP server is never called. |
| Any | Connect with an MCP SDK 1.x client | The client can't connect: the Gateway offers only 2026-07-28. |
Related resources
- Setup guide: the same deployment, step by step.
- An AI agent that asks before it deletes: the story of the demo.
- Securing Amazon Bedrock AgentCore Identity with Ping Identity
- PingOne: OAuth 2.0 token exchange
- PingOne Authorize: API Access Management
- PingOne MFA Integration Kit: CIBA setup for PingFederate
- Amazon Bedrock AgentCore Gateway
- RFC 8693: OAuth 2.0 Token Exchange and OpenID CIBA Core