Skip to content

fix(auth): recompute default tokenUrl when universeDomain changes via toBuilder - #15150

Merged
lqiu96 merged 5 commits into
googleapis:mainfrom
lqiu96:fix/auth-external-account-tobuilder-token-url
Dec 5, 2026
Merged

lqiu96 merged 5 commits into
googleapis:mainfrom
lqiu96:fix/auth-external-account-tobuilder-token-url

Conversation

@lqiu96

@lqiu96 lqiu96 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Updates ExternalAccountCredentials.Builder(ExternalAccountCredentials) to clear tokenUrl when it matches the default STS URL for the credential's current universe domain so toBuilder().setUniverseDomain(...) recomputes the default STS URL for the updated universe domain. Custom tokenUrl values and explicit setTokenUrl(...) overrides always take precedence over the universe domain default.

@lqiu96
lqiu96 requested review from a team as code owners November 23, 2026 15:46

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a helper method defaultTokenUrlForUniverse to resolve the default token URL based on the universe domain, and updates the Builder constructor to reset tokenUrl to null if it matches the default URL. It also adds comprehensive unit tests to verify this behavior. The review comments correctly identify potential NullPointerException risks if universeDomain is null or if defaultTokenUrlForUniverse returns null during the equality check in the builder.

@lqiu96
lqiu96 force-pushed the fix/auth-external-account-tobuilder-token-url branch 2 times, most recently from 9d67db5 to f67d00e Compare November 23, 2026 17:26
… toBuilder

When cloning an ExternalAccountCredentials instance via toBuilder(), clear tokenUrl if it equals the default STS URL for the credential's current universe domain so build() recomputes https://sts.<universeDomain>/v1/token for the updated universe domain. Non-default custom token URLs and explicit setTokenUrl() overrides on the builder are preserved regardless of setter ordering.
@lqiu96
lqiu96 force-pushed the fix/auth-external-account-tobuilder-token-url branch from f67d00e to 42390b7 Compare November 23, 2026 17:39
@lqiu96
lqiu96 requested a review from nbayati November 23, 2026 17:45
@lqiu96 lqiu96 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 23, 2026
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 23, 2026
@lqiu96 lqiu96 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 30, 2026
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 30, 2026
// default STS URL for credentials.getUniverseDomain() (from builder defaults or gcloud JSON).
// Clear tokenUrl to null when it equals that universe default so the configured
// universeDomain
// on toBuilder() can recompute it. Any non-default tokenUrl (e.g. mTLS STS or proxy) stays

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because defaultTokenUrlForUniverse() only matches the non-mTLS URL, an mTLS credential (https://sts.mtls.googleapis.com/v1/token) gets treated as a custom override and stays pointed at sts.mtls.googleapis.com if someone calls toBuilder().setUniverseDomain(...) without also overriding tokenUrl. Is leaving the mTLS STS URL pinned intentional, or should it also recompute to https://sts.mtls.<universe>/v1/token?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since STS is supported in multiple universes, https://sts.mtls.<universe>/v1/token is also valid. I don't think it should be pinned when changing universes.

nbayati
nbayati previously approved these changes Dec 1, 2026

@nbayati nbayati left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM on the changes and test updates. Leaving the mTLS STS endpoint question open while we verify whether non-default universes support it.

@lqiu96
lqiu96 requested a review from nbayati December 2, 2026 21:53
@lqiu96
lqiu96 dismissed nbayati’s stale review December 2, 2026 21:54

Added some new changes. Re-requesting new approval

@lqiu96
lqiu96 enabled auto-merge (squash) December 2, 2026 21:54
@lqiu96
lqiu96 merged commit 0696c28 into googleapis:main Dec 5, 2026
325 of 328 checks passed
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.

4 participants