Repository navigation
Conversation
…_account credentials
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to derive AIP-4111 self-signed JWT audiences from outbound request URLs for unscoped service account credentials in non-default universe domains. It implements a thread-safe, async-safe per-audience LRU cache to store these JWTs, preventing memory bloat and redundant RSA signing, and updates both synchronous and asynchronous credentials as well as various transport layers. The review feedback highlights a missing CRED_TYPE_SA_JWT metric header in the asynchronous before_request implementation, which should be added to match the synchronous counterpart's telemetry behavior.
This was referenced Nov 30, 2026
google-auth: add x-goog-api-client metric headers across async before_request implementations
#19281
Open
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_derive_self_signed_jwt_audience(url)onservice_account.Credentialsto derive an AIP-4111 audience (https://{hostname}/) from the outbound request URL whenalways_use_jwt_access=Trueand no scopes, default scopes, subject, or explicit JWT audience (e.g.,default_host) are configured. Handles port stripping, hostname normalization, IPv6 bracket notation, and returnsNoneon relative or malformed URLs.LRUCache(_url_jwt_credentials_cache) without mutatingself.tokenorself._jwt_credentials, keeping shared credentials thread- and async-safe across multiple hosts.__getstate__/__setstate__onservice_account.Credentialsto exclude the lock and cache during pickling and reinitialize them on unpickle.before_request()onservice_account.Credentials(applyingCRED_TYPE_SA_JWTmetric header) and_service_account_async.Credentialsto mint and apply per-audience JWTs on demand._SyncCredentialsAdapter.before_request()ingoogle/auth/aio/transport/sessions.pyto skip_refresh_shared()when the wrapped credentials derive a URL-based self-signed JWT, avoiding a prematurerefresh()call without the request URL.Stacked on #19279.