fix(bedrock): sign rerank requests with the shared header-filtered SigV4 helper (internal copy of #36462) - #38093
Conversation
…igV4 helper BedrockRerankHandler._prepare_request duplicated ad-hoc SigV4 signing instead of using BaseAWSLLM.get_request_headers, the helper every other Bedrock handler (embeddings, converse, invoke, image) already uses. The duplicate skipped header filtering before signing, so any forwarded header (e.g. x-forwarded-for) got included in the signed set and could invalidate the signature if rewritten downstream between signing and delivery, the same class of bug fixed for the invoke path in #19111.
Pass static AWS credentials through optional_params so the real credential-resolution path runs locally instead of patching BedrockRerankHandler._get_boto_credentials_from_optional_params.
Routing rerank through get_request_headers also picked up its AWS_BEARER_TOKEN_BEDROCK branch. Bedrock API keys are only valid for Bedrock and Bedrock Runtime actions, not for Agents for Amazon Bedrock Runtime ones, and rerank is served by bedrock-agent-runtime, so AWS rejects a bearer-signed rerank call. Opt the rerank handler out of the bearer path so it keeps signing with SigV4.
…itellm_lit5458_rerank_sigv4_bearer_fix
Greptile SummaryThe PR routes Bedrock rerank request signing through the shared header-filtered SigV4 helper while explicitly retaining SigV4 authentication for the agent-runtime endpoint.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| litellm/llms/bedrock/base_aws_llm.py | Adds an opt-out for bearer-token authentication while preserving the existing default for all other callers. |
| litellm/llms/bedrock/rerank/handler.py | Replaces inline rerank signing with the shared filtered-header SigV4 preparation path and disables unsupported bearer authentication. |
| tests/test_litellm/llms/bedrock/rerank/test_bedrock_rerank_header_forwarding.py | Adds focused tests confirming forwarded headers remain unsigned and rerank continues using SigV4 when a Bedrock bearer token is configured. |
Reviews (3): Last reviewed commit: "Merge branch 'litellm_internal_staging' ..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit ed8480a. Configure here.
…itellm_lit5458_rerank_sigv4_bearer_fix
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit ec03baa. Configure here.
…/litellm into litellm_lit5458_rerank_sigv4_bearer_fix # Conflicts: # tests/test_litellm/llms/bedrock/rerank/test_bedrock_rerank_header_forwarding.py
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit e47e989. Configure here.
|
this will be in 1.100.0.rc1 this sat |
Internal copy of #36462 by @noahnistler (fork head
d80608eca6), whose organization-owned fork maintainers cannot push to. It carries both original commits with authorship preserved, plus one commit fixing a bearer-token regression review found there: full credit for the diagnosis and the fix approach goes to the original authorTLDR
Problem this solves:
How it solves it:
get_request_headershelper other Bedrock handlers useUser Flow
Before: an admin whose proxy forwards client headers to backend LLM APIs gets every Bedrock rerank call rejected by AWS
forward_client_headers_to_llm_api: trueand adds a Bedrock rerank deployment, e.g.bedrock/cohere.rerank-v3-5:0X-Forwarded-ForAfter: the same call returns ranked results
forward_client_headers_to_llm_api: trueand adds the same Bedrock rerank deploymentresultsarray of index and relevance-score pairs, and setups that authenticate with a Bedrock API key (AWS_BEARER_TOKEN_BEDROCK) keep working unchangedRelevant issues
Linear ticket
Resolves LIT-5458
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Live before/after against real AWS Bedrock in us-west-2, no mocks. Each side boots a proxy with 2 uvicorn workers from that exact commit, with all egress routed through a header-rewriting hop (mitmdump with an addon that appends its own address to any
X-Forwarded-Forit forwards, the standard behavior of a real corporate egress proxy, wired in viaHTTPS_PROXY), which is the exact condition that breaks the old signing. Config on both sides:Shared request bodies:
Before (bb27bfd)
rerank with X-Forwarded-For through the egress hop
curl -sS -w '\nHTTP %{http_code}\n' -X POST http://127.0.0.1:45600/v1/rerank -H 'Authorization: Bearer sk-lit5458-qa' -H 'Content-Type: application/json' -H 'X-Forwarded-For: 10.1.2.3' -d "$RERANK"{"error": {"message": "{\"message\":\"The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. ...\"}. Received Model Group=bedrock-rerank ...", "code": "403"}}with HTTP 403unversioned /rerank with X-Forwarded-For through the egress hop
http://127.0.0.1:45600/rerankrerank with AWS_BEARER_TOKEN_BEDROCK set in the proxy env
curl -sS -w '\nHTTP %{http_code}\n' -X POST http://127.0.0.1:45600/v1/rerank -H 'Authorization: Bearer sk-lit5458-qa' -H 'Content-Type: application/json' -d "$RERANK"with a valid Bedrock API key exported asAWS_BEARER_TOKEN_BEDROCK{"results": [{"index": 1, "relevance_score": 0.8750309944152832}], "usage": null}with HTTP 200: the old inline signing ignored the bearerAWS_BEARER_TOKEN_BEDROCK=bedrock-api-key-deliberately-invalidinstead, rerank still returns the same 200, confirming the bearer never reaches rerank's signingchat completions and embeddings ride the same shared helper
curl ... -X POST http://127.0.0.1:45600/v1/chat/completions -H 'X-Forwarded-For: 10.1.2.3' -d "$CHAT"returns{"content": "Pong"}HTTP 200, andcurl ... -X POST http://127.0.0.1:45600/v1/embeddings -H 'X-Forwarded-For: 10.1.2.3' -d "$EMBED"returns a 1024-dim embedding, HTTP 200{"Message":"Invalid API Key format: Base64 decoding failed"}, proving they authenticate with the bearer when it is setAfter (e47e989)
rerank with X-Forwarded-For through the egress hop
curl -sS -w '\nHTTP %{http_code}\n' -X POST http://127.0.0.1:47755/v1/rerank -H 'Authorization: Bearer sk-lit5458-qa' -H 'Content-Type: application/json' -H 'X-Forwarded-For: 10.1.2.3' -d "$RERANK"{"results": [{"index": 1, "relevance_score": 0.8750309944152832}], "usage": null}with HTTP 200unversioned /rerank with X-Forwarded-For through the egress hop
http://127.0.0.1:47755/rerankrerank with AWS_BEARER_TOKEN_BEDROCK set in the proxy env
d80608eca6(the original fork commits without the follow-up bearer commit), this exact request instead fails HTTP 403 with AWS's{"message":"Authorization header requires 'Credential' parameter. ..."}, because the shared helper sentAuthorization: Bearer ...tobedrock-agent-runtime, which rejects Bedrock API keys. The follow-up commit'ssupports_bearer_token=Falseis what keeps bearer-token setups workingchat completions and embeddings ride the same shared helper
Invalid API Key formatfailure with the invalid bearer, so bearer precedence on every other Bedrock path is unchangedType
🐛 Bug Fix
Caveats (if any)
extra_headersAuthorization over SigV4, now for rerank too (parity with converse and embeddings; header forwarding never reaches it, as the proof shows)Final Attestation
The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR
e47e989341passes /live-pr-risk: the only contract change is a new defaultedsupports_bearer_tokenparam onget_request_headers, whose only override lives inbase_aws_llm.pyitself; converse and embedding callers were driven live on both sides above, and image generation and image edit keep the default, leaving their behavior byte-identicalNote
Medium Risk
Changes AWS auth and SigV4 signing for rerank only; incorrect header filtering or bearer handling could break proxy rerank deployments, but scope is isolated and covered by new tests.
Overview
Fixes Bedrock rerank failing with SigV4 signature mismatches when the proxy forwards client headers (e.g.
X-Forwarded-For), by routing request prep through the sharedget_request_headershelper used elsewhere on Bedrock instead of signing every header inline.The helper only includes AWS-relevant headers in the signature and re-attaches forwarded headers unsigned, matching the invoke-path fix. Rerank calls
get_request_headers(..., supports_bearer_token=False)because rerank hitsbedrock-agent-runtime, which rejects Bedrock API-key bearer auth—soAWS_BEARER_TOKEN_BEDROCKno longer overrides SigV4 for rerank only; chat/embed/converse behavior stays on the default bearer path.Adds unit tests that
x-forwarded-foris present on the request but excluded fromSignedHeaders, and that rerank still usesAWS4-HMAC-SHA256when the bearer env var is set.Reviewed by Cursor Bugbot for commit e47e989. Bugbot is set up for automated code reviews on this repo. Configure here.