Skip to content

fix(oauth2): verify universe domain for UserAccessTokenCredentials - #19249

Open
parthea wants to merge 6 commits into
mainfrom
fix/verify-user-token-universe
Open

parthea wants to merge 6 commits into
mainfrom
fix/verify-user-token-universe

Conversation

@parthea

@parthea parthea commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Resolve and validate the active Cloud SDK universe domain in UserAccessTokenCredentials.

This PR includes the following changes:

  • Expose get_universe_domain() in google/auth/_cloud_sdk.py, checking GOOGLE_CLOUD_UNIVERSE_DOMAIN first and falling back to gcloud config get core/universe_domain.
  • Add a lazily resolved and cached universe_domain property on UserAccessTokenCredentials (in google/oauth2/credentials.py, inherited by _credentials_async.UserAccessTokenCredentials) that validates the resolved domain via _helpers.validate_universe_domain(), updates self._universe_domain, and preserves cached state across with_account() and with_quota_project().
  • Ensure UserAccessTokenCredentials.refresh() resolves and validates self.universe_domain before calling _cloud_sdk.get_auth_access_token(), reusing the cached value on subsequent refreshes.

@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 adds support for retrieving and validating the active Cloud SDK universe domain in UserAccessTokenCredentials. It introduces a get_universe_domain helper in _cloud_sdk.py to fetch the domain from the environment or via the gcloud CLI, and updates the credentials refresh process to validate and verify that the resolved universe domain matches the default universe domain. A critical issue was identified in _cloud_sdk.py where the use of the unimported _helpers module will cause a NameError at runtime; it is recommended to decode the bytes directly instead.

@parthea
parthea marked this pull request as ready for review November 27, 2026 16:54
@parthea
parthea requested review from a team as code owners November 27, 2026 16:54

This branch has not been deployed

No deployments
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