fix(mcp): Preserve existing auth in mTLS transport#6201
Open
h-tsuboi918 wants to merge 2 commits into
Open
Conversation
HTTP header names are case-insensitive, but the mTLS auth bridge only checked for an exact Authorization key before adding ADC credentials. httpx can pass the existing header as lowercase authorization, causing the user token to be missed. Fixes google#6200
564cbe6 to
c637b5f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
N/A
Problem:
The MCP mTLS auth bridge checked only for an exact
Authorizationheader key before adding ADC credentials.httpx.Request.headerscan be converted into a plain dict with lowercaseauthorization, so the existing user / 3LO Authorization header could be missed.When that happens, ADK may inject ADC / runtime Service Account credentials into the same MCP request, causing the MCP server to observe the runtime principal instead of the intended user principal.
Solution:
Make
_RefreshableAsyncCredentials.before_request()check for an existing Authorization header case-insensitively before refreshing and injecting credentials.This matches HTTP header semantics and preserves existing behavior for correctly cased
Authorizationheaders while also handling lowercaseauthorizationfrom thehttpxrequest path.Testing Plan
Unit Tests:
Passed locally:
Additional checks:
Manual End-to-End (E2E) Tests:
Not run. This is covered by a focused unit test for the credential injection guard. The changed behavior is isolated to preserving an existing lowercase
authorizationheader before ADC refresh/injection.Checklist
Additional context
The issue is specific to the MCP mTLS transport path where ADK bridges
httpxrequests intogoogle-auth-aioAsyncAuthorizedSession. The existing Authorization header may originate from MCP auth credential handling or a header provider, including user / 3LO token propagation.No new code comments were added because the code change is limited to the existing Authorization header guard. There are no dependent downstream changes.