Repository navigation
fix(auth): support universe_domain in jwt and _jwt_async credentials - #19133
Conversation
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.
There was a problem hiding this comment.
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.
| ) | ||
| assert jwt_creds.universe_domain == FAKE_UNIVERSE_DOMAIN | ||
|
|
||
| def test_with_universe_domain(self, signer): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
…main_jwt_credentials
…n and document RAB scoping
Add
universe_domainsupport and implementCredentialsWithUniverseDomain(with_universe_domain()) ongoogle.auth.jwt.Credentials,google.auth.jwt.OnDemandCredentials, and theirgoogle.auth._jwt_asyncsubclasses, matching the other credential types ingoogle-auth.universe_domainis read from service account key info/files and signing credentials (defaulting togoogleapis.comwhen 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.