impersonate: build the IAM and OAuth2 URLs from the universe domain impersonate: use the universe domain for the default audience too impersonate: assert the request host in the token source tests by rootkiller6788 · Pull Request #3741 · googleapis/google-api-go-client · GitHub
Skip to content

impersonate: build the IAM and OAuth2 URLs from the universe domain impersonate: use the universe domain for the default audience too impersonate: assert the request host in the token source tests - #3741

Open
rootkiller6788 wants to merge 3 commits into
googleapis:mainfrom
rootkiller6788:fix-impersonate-universe-domain-endpoints
Open

rootkiller6788 wants to merge 3 commits into
googleapis:mainfrom
rootkiller6788:fix-impersonate-universe-domain-endpoints

Conversation

@rootkiller6788

Copy link
Copy Markdown

Fixes #3739.

The iamcredentials and oauth2 hosts were package vars, so option.WithUniverseDomain (and GOOGLE_CLOUD_UNIVERSE_DOMAIN) never reached them and impersonation always went to googleapis.com. I hit this pointing impersonation at a non-GDU universe.

What I did: replaced the two vars with helpers that take the universe domain, read it once from the client options, and threaded it through the access token, ID token and DWD token sources. The default audience the base credentials get pointed at googleapis.com as well, so that now uses the same universe - otherwise the base token would not be accepted where we send the request.

For the Google universe the endpoint strings come out identical to before, so nothing changes there.

On the tests: both token source tests used a fake transport that ignored the URL, which is why this slipped through. They now record the request host and check it, with a case for a custom universe domain. I verified they fail if I hardcode the host back.

The iamcredentials and oauth2 hosts were baked in as package vars, so
option.WithUniverseDomain had no effect on them and impersonation always
went to googleapis.com. Turn them into helpers that take the universe
domain and thread it through the token sources.

The DWD flow only runs in the Google universe (it errors out otherwise),
but it gets the same treatment so there is one place that decides hosts.
The base credentials get their default audience from this package, and it
was hardcoded to googleapis.com as well. Point it at the same universe as
the endpoint we call, otherwise the base token is not usable there.
Both tests used a fake transport that ignored the URL, so a wrong host
went unnoticed. Record the host and check it, with a case for a custom
universe domain.
@rootkiller6788
rootkiller6788 requested review from a team as code owners September 21, 2026 10:13
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.

impersonate: iamcredentials endpoint is hardcoded to googleapis.com, ignores universe_domain

1 participant