fix(idtoken): avoid double impersonation in tokenSourceFromBytes#3576
Open
quartzmo wants to merge 4 commits intogoogleapis:mainfrom
Open
fix(idtoken): avoid double impersonation in tokenSourceFromBytes#3576quartzmo wants to merge 4 commits intogoogleapis:mainfrom
quartzmo wants to merge 4 commits intogoogleapis:mainfrom
Conversation
This PR fixes a parallel double impersonation bug in the `idtoken` package. The library incorrectly does not use the `source_credentials` subfield in the JSON struct when constructing the inner client, and instead passes the entire credential JSON. This causes the lower layers (`htransport.NewClient`) to correctly (but unexpectedly for this context) build an authenticated HTTP client that is already impersonated, leading to self-impersonation when calling `generateIdToken`. This PR fixes the issue by extracting or recreating non-impersonated credentials before calling `impersonate.IDTokenSource`, avoiding the double wrap. Note: This PR does not add new unit tests for the call sequence because `impersonate.IDTokenSource` hardcodes the IAM credentials endpoint, making it impossible to intercept with a mock client or server without modifying that package. The existing unit tests in this package only cover type validation and do not successfully execute the full impersonation flow due to this same limitation. closes: googleapis#2301
hongalex
approved these changes
Apr 27, 2026
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.
This PR fixes a parallel double impersonation bug in the
idtokenpackage. The library incorrectly does not use thesource_credentialssubfield in the JSON struct when constructing the inner client, and instead passes the entire credential JSON. This causes the lower layers (htransport.NewClient) to correctly (but unexpectedly for this context) build an authenticated HTTP client that is already impersonated, leading to self-impersonation when callinggenerateIdToken.This PR fixes the issue by extracting or recreating non-impersonated credentials before calling
impersonate.IDTokenSource, avoiding the double wrap.Note: This PR does not add new unit tests for the call sequence because
impersonate.IDTokenSourcehardcodes the IAM credentials endpoint, making it impossible to intercept with a mock client or server without modifying that package. The existing unit tests in this package only cover type validation and do not successfully execute the full impersonation flow due to this same limitation.closes: #2301