Skip to content

fix(idtoken): avoid double impersonation in tokenSourceFromBytes#3576

Open
quartzmo wants to merge 4 commits intogoogleapis:mainfrom
quartzmo:auth-id-token-bugs
Open

fix(idtoken): avoid double impersonation in tokenSourceFromBytes#3576
quartzmo wants to merge 4 commits intogoogleapis:mainfrom
quartzmo:auth-id-token-bugs

Conversation

@quartzmo
Copy link
Copy Markdown
Member

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: #2301

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
@quartzmo quartzmo requested a review from a team as a code owner April 22, 2026 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

golang SA impersonation requires permission iam.serviceAccounts.getOpenIdToken whereas other clients do not

2 participants