propagate X-Amz-Bedrock-AgentCore-Identity-WAT on outbound calls - #607
propagate X-Amz-Bedrock-AgentCore-Identity-WAT on outbound calls#607Sudip2403 wants to merge 1 commit into
Conversation
d9530c0 to
69d2b34
Compare
jariy17
left a comment
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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}",
)
There was a problem hiding this comment.
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}",
)
| request.headers[IDENTITY_WAT_HEADER] = identity_wat | ||
|
|
||
|
|
||
| def register_identity_wat_propagation(client: Any) -> None: |
There was a problem hiding this comment.
Please scope this client's type to botocore.client.BaseClient.
There was a problem hiding this comment.
│ 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) |
There was a problem hiding this comment.
We are already store WAT in _workload_access_token. Can this PR just use this variable instead of creating a whole new one?
69d2b34 to
5bad65e
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #607 +/- ##
=======================================
Coverage ? 88.37%
=======================================
Files ? 113
Lines ? 9450
Branches ? 1435
=======================================
Hits ? 8351
Misses ? 731
Partials ? 368
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
8113624 to
7717471
Compare
…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.
7717471 to
81201cd
Compare
…gation
Add support for workload identity chain propagation across service hops:
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.