Skip to content

propagate X-Amz-Bedrock-AgentCore-Identity-WAT on outbound calls - #607

Open
Sudip2403 wants to merge 1 commit into
aws:mainfrom
Sudip2403:feat/identity-wat-propagation
Open

propagate X-Amz-Bedrock-AgentCore-Identity-WAT on outbound calls#607
Sudip2403 wants to merge 1 commit into
aws:mainfrom
Sudip2403:feat/identity-wat-propagation

Conversation

@Sudip2403

Copy link
Copy Markdown

…gation

Add support for workload identity chain propagation across service hops:

  • Add IDENTITY_WAT_HEADER constant and allowlist it in is_forwardable_header
  • Add identity_wat context variable to BedrockAgentCoreContext
  • Extract the WAT header from inbound requests in _build_request_context
  • Auto-propagate on outbound Runtime/Gateway boto3 calls via event handler
  • Add @requires_wat decorator for explicit WAT minting and propagation
  • Register WAT propagation on Runtime data plane client only (Identity is excluded as it is the WAT issuer)
  • Document manual Gateway MCP call propagation pattern
  • Add comprehensive tests for all new functionality

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@Sudip2403
Sudip2403 requested a review from a team July 29, 2026 14:19
@github-actions github-actions Bot added the size/m PR size: M label Jul 29, 2026
@Sudip2403
Sudip2403 force-pushed the feat/identity-wat-propagation branch from d9530c0 to 69d2b34 Compare July 29, 2026 23:43
@github-actions github-actions Bot added size/m PR size: M and removed size/m PR size: M labels Jul 29, 2026

@jariy17 jariy17 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. We already store the workload access token in the context. Can we use that instead?

Args:
client: A boto3 client instance (e.g., bedrock-agentcore data plane client).
"""
client.meta.events.register(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of filtering on Line 52, we should call this register for every WAT allowlisted operation (InvokeAgentRuntime).

for op in ("InvokeAgentRuntime", ...):
      self.dp_client.meta.events.register(
          f"before-sign.bedrock-agentcore.{op}",
          _add_identity_wat_header,
          unique_id=f"identity-wat-{op}",
      )

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of filtering on Line 52, we should call this register for every WAT allowlisted operation (InvokeAgentRuntime).

for op in ("InvokeAgentRuntime", ...):
      self.dp_client.meta.events.register(
          f"before-sign.bedrock-agentcore.{op}",
          _add_identity_wat_header,
          unique_id=f"identity-wat-{op}",
      )

│ Done. Now registers per-operation with unique_id:

for op in _WAT_PROPAGATION_OPERATIONS:
client.meta.events.register(
f"before-sign.bedrock-agentcore.{op}",
_inject_identity_wat_header,
unique_id=f"identity-wat-{op}",
)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

request.headers[IDENTITY_WAT_HEADER] = identity_wat


def register_identity_wat_propagation(client: Any) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please scope this client's type to botocore.client.BaseClient.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

│ Done. Changed to client: BaseClient with import from botocore.client.

"""Unified context manager for Bedrock AgentCore."""

_workload_access_token: ContextVar[Optional[str]] = ContextVar("workload_access_token")
_identity_wat: ContextVar[Optional[str]] = ContextVar("identity_wat", default=None)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are already store WAT in _workload_access_token. Can this PR just use this variable instead of creating a whole new one?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@Sudip2403
Sudip2403 force-pushed the feat/identity-wat-propagation branch from 69d2b34 to 5bad65e Compare July 31, 2026 18:44
@github-actions github-actions Bot added size/m PR size: M and removed size/m PR size: M labels Jul 31, 2026
@Sudip2403 Sudip2403 changed the title feat(identity): Add X-Amz-Bedrock-AgentCore-Identity-WAT header propa… feat(runtime): propagate X-Amz-Bedrock-AgentCore-Identity-WAT on outbound calls Aug 3, 2026
@github-actions github-actions Bot added size/m PR size: M and removed size/m PR size: M labels Aug 3, 2026
@Sudip2403 Sudip2403 changed the title feat(runtime): propagate X-Amz-Bedrock-AgentCore-Identity-WAT on outbound calls propagate X-Amz-Bedrock-AgentCore-Identity-WAT on outbound calls Aug 3, 2026
@github-actions github-actions Bot added size/m PR size: M and removed size/m PR size: M labels Aug 3, 2026
jariy17
jariy17 previously approved these changes Aug 3, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 53.48837% with 20 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@5d23292). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/bedrock_agentcore/identity/auth.py 4.76% 20 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #607   +/-   ##
=======================================
  Coverage        ?   88.37%           
=======================================
  Files           ?      113           
  Lines           ?     9450           
  Branches        ?     1435           
=======================================
  Hits            ?     8351           
  Misses          ?      731           
  Partials        ?      368           
Flag Coverage Δ
unittests 88.37% <53.48%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…ound calls

Enable automatic workload identity chain propagation for agent code
running on AgentCore Runtime.

## Flow

```
Caller → Gateway1 (mints WAT) → Runtime1 (receives WAT) → Agent Code
                                                              ↓
                                              ┌───────────────┴───────────────┐
                                              ↓                               ↓
                                    Gateway3 (getRefund)          Gateway4 (doTransaction)
                                    WAT auto-propagated           WAT auto-propagated
```

## Changes

The Runtime platform mints a WAT (with chain extension) and delivers it
to the agent via the X-Amz-Bedrock-AgentCore-Identity-WAT header. This
PR adds SDK support to:

1. Extract the WAT from inbound requests (falls back to WorkloadAccessToken)
2. Auto-attach it as X-Amz-Bedrock-AgentCore-Identity-WAT on outbound
   boto3 calls to Runtime/Gateway (InvokeAgentRuntime, InvokeHarness, etc.)
3. Expose @requires_wat decorator for reading the WAT from context
4. Allowlist the header in is_forwardable_header()

For Gateway MCP calls (raw HTTP), developers read the WAT via
BedrockAgentCoreContext.get_workload_access_token() and attach manually.
@Sudip2403
Sudip2403 force-pushed the feat/identity-wat-propagation branch from 7717471 to 81201cd Compare August 3, 2026 23:29
@github-actions github-actions Bot added size/m PR size: M and removed size/m PR size: M labels Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants