Skip to content

fix(auth): rebuild endpoints and reset RAB state on universe_domain cloning and wrapping - #19308

Open
parthea wants to merge 3 commits into
mainfrom
fix/auth-cloning-wrapping-universe-domain
Open

parthea wants to merge 3 commits into
mainfrom
fix/auth-cloning-wrapping-universe-domain

Conversation

@parthea

@parthea parthea commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary of Changes

  • external_account.Credentials (packages/google-auth/google/auth/external_account.py):
    • Inherit credentials.CredentialsWithUniverseDomain.
    • Default self._universe_domain to DEFAULT_UNIVERSE_DOMAIN when universe_domain=None is passed explicitly.
    • Preserve the unformatted token_url template in _raw_token_url across cloning (_copy_with, _make_copy, with_scopes, with_quota_project, with_token_uri, and with_universe_domain) and rebuild _token_url, _cloud_resource_manager_url, and _sts_client when cloning with a new universe_domain or token_uri.
    • Validate universe_domain in with_universe_domain() via _helpers.validate_universe_domain().
    • Only copy _rab_manager state when the cloned credentials target DEFAULT_UNIVERSE_DOMAIN.
  • external_account_authorized_user.Credentials (packages/google-auth/google/auth/external_account_authorized_user.py):
    • Inherit credentials.CredentialsWithUniverseDomain.
    • Preserve _raw_token_url and format {universe_domain} templates in token_url, rebuilding _sts_client in with_token_uri() and with_universe_domain().
    • Validate universe_domain in with_universe_domain() via _helpers.validate_universe_domain().
    • Clear cached token and expiry when cloning to a different universe domain.
    • Only copy _rab_manager state when the cloned credentials target DEFAULT_UNIVERSE_DOMAIN.
  • downscoped.Credentials (packages/google-auth/google/auth/downscoped.py):
    • Inherit credentials.CredentialsWithUniverseDomain and implement with_universe_domain() (propagating to source_credentials when it exposes a callable with_universe_domain method).
    • Default universe_domain to None in __init__ so source_credentials.universe_domain is inherited by default, validating against source_credentials.universe_domain via _helpers.compare_universe_domains() when explicitly supplied.
    • Preserve universe_domain=self._universe_domain in with_quota_project().
  • compute_engine.Credentials (packages/google-auth/google/auth/compute_engine/credentials.py):
    • Validate universe_domain in with_universe_domain() via _helpers.validate_universe_domain().
    • Preserve uncached universe_domain state cleanly in _copy_with() and avoid carrying cached default-universe _rab_manager state onto credentials targeting a non-default universe domain.

(Note: service_account RAB state handling on with_universe_domain() is handled separately in #19194.)

@parthea
parthea requested review from a team as code owners December 2, 2026 16:47

@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 refactors credential copying and universe domain handling across Compute Engine, Downscoped, and External Account credentials by introducing a centralized _copy_with helper. This preserves the unformatted token_url template and ensures that Regional Access Boundary (RAB) state is reset when switching to a non-default universe domain. Feedback on these changes highlights a potential TypeError in external_account.py if self._universe_domain is None during token URL formatting, suggesting the use of the self.universe_domain property instead. Additionally, it is recommended to use domain comparison utilities rather than manual .lower() checks in compute_engine/credentials.py to safely handle missing attributes.

@parthea parthea closed this Dec 2, 2026
@parthea parthea reopened this Dec 2, 2026

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.

1 participant