Skip to content

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

Open
nbayati wants to merge 1 commit into
mainfrom
support_universe_domain_jwt_credentials
Open

nbayati wants to merge 1 commit 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 on lines 566 to 570
audience=audience if audience is not None else self._audience,
additional_claims=new_additional_claims,
quota_project_id=self._quota_project_id,
universe_domain=self._universe_domain,
)

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.

medium

When cloning credentials using with_claims, the token_lifetime parameter is currently not preserved, causing it to revert to the default value. Since with_universe_domain correctly preserves self._token_lifetime, we should also preserve it here for consistency and correctness.

Suggested change
audience=audience if audience is not None else self._audience,
additional_claims=new_additional_claims,
quota_project_id=self._quota_project_id,
universe_domain=self._universe_domain,
)
audience=audience if audience is not None else self._audience,
additional_claims=new_additional_claims,
token_lifetime=self._token_lifetime,
quota_project_id=self._quota_project_id,
universe_domain=self._universe_domain,
)

Comment on lines 580 to 584
audience=self._audience,
additional_claims=self._additional_claims,
quota_project_id=quota_project_id,
universe_domain=self._universe_domain,
)

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.

medium

When cloning credentials using with_quota_project, the token_lifetime parameter is currently not preserved, causing it to revert to the default value. We should preserve self._token_lifetime here as well.

Suggested change
audience=self._audience,
additional_claims=self._additional_claims,
quota_project_id=quota_project_id,
universe_domain=self._universe_domain,
)
audience=self._audience,
additional_claims=self._additional_claims,
token_lifetime=self._token_lifetime,
quota_project_id=quota_project_id,
universe_domain=self._universe_domain,
)

Comment on lines 859 to 863
additional_claims=new_additional_claims,
max_cache_size=self._cache.maxsize,
quota_project_id=self._quota_project_id,
universe_domain=self._universe_domain,
)

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.

medium

When cloning on-demand credentials using with_claims, the token_lifetime parameter is currently not preserved, causing it to revert to the default value. We should preserve self._token_lifetime here as well.

Suggested change
additional_claims=new_additional_claims,
max_cache_size=self._cache.maxsize,
quota_project_id=self._quota_project_id,
universe_domain=self._universe_domain,
)
additional_claims=new_additional_claims,
token_lifetime=self._token_lifetime,
max_cache_size=self._cache.maxsize,
quota_project_id=self._quota_project_id,
universe_domain=self._universe_domain,
)

Comment on lines 871 to +875
additional_claims=self._additional_claims,
max_cache_size=self._cache.maxsize,
quota_project_id=quota_project_id,
universe_domain=self._universe_domain,
)

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.

medium

When cloning on-demand credentials using with_quota_project, the token_lifetime parameter is currently not preserved, causing it to revert to the default value. We should preserve self._token_lifetime here as well.

Suggested change
additional_claims=self._additional_claims,
max_cache_size=self._cache.maxsize,
quota_project_id=quota_project_id,
universe_domain=self._universe_domain,
)
additional_claims=self._additional_claims,
token_lifetime=self._token_lifetime,
max_cache_size=self._cache.maxsize,
quota_project_id=quota_project_id,
universe_domain=self._universe_domain,
)

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