Skip to content

fix(auth): support universe_domain in jwt and _jwt_async credentials - #19133

Merged
nbayati merged 7 commits into
mainfrom
support_universe_domain_jwt_credentials
Nov 21, 2026
Merged

nbayati merged 7 commits into
mainfrom
support_universe_domain_jwt_credentials

Conversation

@nbayati

@nbayati nbayati commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Add universe_domain support and implement CredentialsWithUniverseDomain (with_universe_domain()) on google.auth.jwt.Credentials, google.auth.jwt.OnDemandCredentials, and their google.auth._jwt_async subclasses, matching the other credential types in google-auth.

universe_domain is read from service account key info/files and signing credentials (defaulting to googleapis.com when omitted, such as in direct constructor calls) and preserved across credential cloning methods, while keeping Regional Access Boundary state scoped to the default universe domain.

Add `universe_domain` support and implement `CredentialsWithUniverseDomain` (`with_universe_domain()`) on `google.auth.jwt.Credentials`, `google.auth.jwt.OnDemandCredentials`, and their `google.auth._jwt_async` subclasses, matching the other credential types in `google-auth`.

`universe_domain` is read from service account key info/files and signing credentials (defaulting to `googleapis.com` when omitted, such as in direct constructor calls) and preserved across credential cloning methods, while keeping Regional Access Boundary state scoped to the default universe domain.
@nbayati
nbayati requested review from a team as code owners November 19, 2026 07:47
@nbayati
nbayati requested review from daniel-sanche and removed request for a team November 19, 2026 07:48

@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 support for universe_domain to both Credentials and OnDemandCredentials classes in google/auth/jwt.py, aligning them with the CredentialsWithUniverseDomain interface. This includes adding the universe_domain parameter to constructors, factory methods, and cloning methods, along with comprehensive unit and async tests to verify behavior such as regional access boundary lookups and impersonation. The review feedback highlights a consistent issue across several cloning methods (with_claims and with_quota_project for both standard and on-demand credentials) where the token_lifetime parameter is not preserved during cloning, causing it to revert to the default value. Implementing the suggested changes to preserve self._token_lifetime will ensure consistency and correctness.

Comment thread packages/google-auth/google/auth/jwt.py Resolved
Comment thread packages/google-auth/google/auth/jwt.py Resolved
Comment thread packages/google-auth/google/auth/jwt.py Resolved
Comment thread packages/google-auth/google/auth/jwt.py Resolved
@nbayati
nbayati requested a review from macastelaz November 19, 2026 18:01
Comment thread packages/google-auth/google/auth/jwt.py Resolved
Comment thread packages/google-auth/google/auth/jwt.py Resolved
Comment thread packages/google-auth/google/auth/jwt.py Resolved
)
assert jwt_creds.universe_domain == FAKE_UNIVERSE_DOMAIN

def test_with_universe_domain(self, signer):

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.

nit: This only asserts universe_domain, _rab_manager, and _token_lifetime == 600. Because self.credentials uses issuer == subject, additional_claims={}, and quota_project_id=None, omitting additional_claims, quota_project_id, audience, or distinct subject in Credentials.with_universe_domain would leave the test suite passing.

Consider configuring custom_lifetime_creds with non-default subject=self.SUBJECT, additional_claims=self.ADDITIONAL_CLAIMS, and quota_project_id="project-foo", and assert that the cloned instance preserves _signer, _issuer, _subject, _audience, _additional_claims, _token_lifetime, and _quota_project_id.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, updated test_with_universe_domain with non-default subject, additional_claims, token_lifetime, and quota_project_id and asserted all cloned fields are preserved.

)
assert credentials.universe_domain == auth_credentials.DEFAULT_UNIVERSE_DOMAIN

def test_with_universe_domain(self, signer):

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.

nit: This only asserts isinstance, universe_domain, and _token_lifetime == 600. Even though TestOnDemandCredentials.credentials_fixture configures max_cache_size=2, the test never verifies non_default._cache.maxsize == 2, non_default._cache is not self.credentials._cache, or preservation of non-default subject, additional_claims, and quota_project_id—so dropping max_cache_size=self._cache.maxsize, additional_claims, or quota_project_id from OnDemandCredentials.with_universe_domain would not fail any test. Populate non-default subject, additional_claims, quota_project_id, and max_cache_size=2 on the source credential and assert all cloned fields along with _cache.maxsize == 2 and cloned._cache is not source._cache.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, updated test_with_universe_domain to populate non-default fields and assert all cloned attributes along with _cache.maxsize == 2 and cache instance isolation.

self.credentials, auth_credentials.CredentialsWithUniverseDomain
)

def test_universe_domain(self):

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.

nit: This only exercises jwt_async.Credentials.from_signing_credentials(sa_creds, ...) and self.credentials.with_universe_domain(...) with FAKE_UNIVERSE_DOMAIN, where _copy_regional_access_boundary_manager is skipped. Add a default-universe check calling jwt_async.Credentials.from_signing_credentials(gdu_sa_creds, audience=self.AUDIENCE) (where gdu_sa_creds is a sync service_account.Credentials with _rab_manager._data = mock.sentinel.rab_data) and self.credentials.with_universe_domain(auth_credentials.DEFAULT_UNIVERSE_DOMAIN) to verify that _copy_regional_access_boundary_manager copies _data while preserving _AsyncRegionalAccessBoundaryRefreshManager on refresh_manager.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, added default-universe checks for both from_signing_credentials and with_universe_domain in test_jwt_async.py verifying RAB data is copied while keeping _AsyncRegionalAccessBoundaryRefreshManager.

@nbayati
nbayati merged commit a2b9b8f into main Nov 21, 2026
148 checks passed
@nbayati
nbayati deleted the support_universe_domain_jwt_credentials branch November 21, 2026 05:04
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.

3 participants