Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(bedrock): grant sts:GetWebIdentityToken and sts:TagGetWebIdentityToken in web identity session policy for claude_platform (#46670)

David Bochenskif0724983044a
diff --git a/litellm/llms/bedrock/base_aws_llm.py b/litellm/llms/bedrock/base_aws_llm.py
index 848120150cd..f1426aa9375 100644
--- a/litellm/llms/bedrock/base_aws_llm.py
+++ b/litellm/llms/bedrock/base_aws_llm.py
@@ -99,11 +99,16 @@ def _assume_role_params(
)
-_SecureTransportBool = TypedDict("_SecureTransportBool", {"aws:SecureTransport": ReadOnly[Literal["true"]]})
+_SecureTransportBool: Final = TypedDict("_SecureTransportBool", {"aws:SecureTransport": ReadOnly[Literal["true"]]})
+
+_CalledViaLastEquals: Final = TypedDict(
+ "_CalledViaLastEquals", {"aws:CalledViaLast": ReadOnly[Literal["aws-external-anthropic.amazonaws.com"]]}
+)
-class _SecureTransportCondition(TypedDict):
+class _SessionPolicyCondition(TypedDict):
Bool: ReadOnly[_SecureTransportBool]
+ StringEquals: NotRequired[ReadOnly[_CalledViaLastEquals]]
class _SessionPolicyStatement(TypedDict):
@@ -111,7 +116,7 @@ class _SessionPolicyStatement(TypedDict):
Effect: ReadOnly[Literal["Allow"]]
Action: ReadOnly[tuple[str, ...]]
Resource: ReadOnly[Literal["*"]]
- Condition: ReadOnly[_SecureTransportCondition]
+ Condition: ReadOnly[_SessionPolicyCondition]
class WebIdentitySessionPolicy(TypedDict):
@@ -147,11 +152,24 @@ _WEB_IDENTITY_SESSION_POLICY_ACTIONS: Final[Mapping[str, tuple[str, ...]]] = Map
"aws-external-anthropic:Get*",
"aws-external-anthropic:List*",
),
+ "ClaudePlatformOutboundIdentityLiteLLM": (
+ "sts:GetWebIdentityToken",
+ "sts:TagGetWebIdentityToken",
+ ),
"BedrockMantleLiteLLM": ("bedrock-mantle:CreateInference",),
}
)
-_SECURE_TRANSPORT_ONLY: Final = _SecureTransportCondition(Bool=_SecureTransportBool({"aws:SecureTransport": "true"}))
+_SECURE_TRANSPORT_ONLY: Final = _SessionPolicyCondition(Bool=_SecureTransportBool({"aws:SecureTransport": "true"}))
+
+_WEB_IDENTITY_SESSION_POLICY_CONDITIONS: Final[Mapping[str, _SessionPolicyCondition]] = MappingProxyType(
+ {
+ "ClaudePlatformOutboundIdentityLiteLLM": _SessionPolicyCondition(
+ Bool=_SecureTransportBool({"aws:SecureTransport": "true"}),
+ StringEquals=_CalledViaLastEquals({"aws:CalledViaLast": "aws-external-anthropic.amazonaws.com"}),
+ ),
+ }
+)
def build_web_identity_session_policy() -> WebIdentitySessionPolicy:
@@ -163,7 +181,7 @@ def build_web_identity_session_policy() -> WebIdentitySessionPolicy:
Effect="Allow",
Action=actions,
Resource="*",
- Condition=_SECURE_TRANSPORT_ONLY,
+ Condition=_WEB_IDENTITY_SESSION_POLICY_CONDITIONS.get(sid, _SECURE_TRANSPORT_ONLY),
)
for sid, actions in _WEB_IDENTITY_SESSION_POLICY_ACTIONS.items()
),
diff --git a/tests/unit/llms/bedrock/test_web_identity_session_policy.py b/tests/unit/llms/bedrock/test_web_identity_session_policy.py
index cbb69b4ceed..332e1258e9c 100644
--- a/tests/unit/llms/bedrock/test_web_identity_session_policy.py
+++ b/tests/unit/llms/bedrock/test_web_identity_session_policy.py
@@ -176,6 +176,44 @@ class TestClaudePlatformActionsCovered:
)
+class TestClaudePlatformOutboundIdentityCovered:
+ """Claude Platform on AWS calls ``sts:GetWebIdentityToken`` with the
+ caller's session before serving inference, and tags the token it
+ requests (``sts:TagGetWebIdentityToken``). Without either in the ceiling,
+ every claude_platform request via OIDC auth denies with "no session
+ policy allows the sts:<action> action" even when the role's identity
+ policy grants it."""
+
+ @pytest.mark.parametrize("action", ["sts:GetWebIdentityToken", "sts:TagGetWebIdentityToken"])
+ def test_outbound_identity_action_present(self, action: str):
+ assert action in _granted_actions(_captured_policy()), (
+ f"{action} missing from session policy, so bedrock/claude_platform/* requests will 403 on OIDC auth"
+ )
+
+ @pytest.mark.parametrize("action", ["sts:GetWebIdentityToken", "sts:TagGetWebIdentityToken"])
+ def test_outbound_identity_action_is_granted_only_via_claude_platform(self, action: str):
+ granting: Final = tuple(stmt for stmt in _captured_policy()["Statement"] if action in stmt["Action"])
+ assert granting, f"{action} missing from session policy"
+ assert all(
+ stmt["Condition"].get("StringEquals") == {"aws:CalledViaLast": "aws-external-anthropic.amazonaws.com"}
+ and stmt["Condition"]["Bool"] == {"aws:SecureTransport": "true"}
+ for stmt in granting
+ ), f"{action} must only be usable over TLS when Claude Platform on AWS calls STS for the session"
+
+ def test_outbound_identity_statement_is_scoped(self):
+ policy = _captured_policy()
+ stmt = _statement_by_sid(policy, "ClaudePlatformOutboundIdentityLiteLLM")
+ assert stmt["Effect"] == "Allow"
+ assert tuple(stmt["Action"]) == ("sts:GetWebIdentityToken", "sts:TagGetWebIdentityToken"), (
+ "the outbound identity statement must grant only the two outbound identity actions"
+ )
+
+ def test_no_sts_wildcard(self):
+ assert "sts:*" not in _granted_actions(_captured_policy()), (
+ "session policy must not grant sts:*, only the two outbound identity actions are needed"
+ )
+
+
class TestBedrockMantleActionsCovered:
"""LIT-3859: bedrock_mantle inference authorizes against the
``bedrock-mantle`` action namespace, so the session-policy ceiling
@@ -306,6 +344,15 @@ class TestPolicyTransportConditions:
"to keep parity with the bedrock statement"
)
+ def test_only_the_outbound_identity_statement_requires_a_claude_platform_caller(self):
+ directly_called: Final = tuple(
+ stmt for stmt in _captured_policy()["Statement"] if stmt["Sid"] != "ClaudePlatformOutboundIdentityLiteLLM"
+ )
+ assert directly_called
+ assert all("StringEquals" not in stmt["Condition"] for stmt in directly_called), (
+ "statements LiteLLM calls directly must not require aws:CalledViaLast, or OIDC auth 403s on those routes"
+ )
+
_STS_SESSION_POLICY_PLAINTEXT_LIMIT: Final = 2048