Skip to content

feat(google-auth): rotate requests.Request mTLS adapters via _MtlsCertManager - #19226

Draft
nbayati wants to merge 3 commits into
grpc_phase1_pr1from
grpc_phase1_pr2a
Draft

nbayati wants to merge 3 commits into
grpc_phase1_pr1from
grpc_phase1_pr2a

Conversation

@nbayati

@nbayati nbayati commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Adds an optional cert_manager parameter to google.auth.transport.requests.Request so long-lived request transports rotate their mTLS HTTPS adapter whenever the shared _MtlsCertManager from #18925 advances to a new certificate generation.

When a cert_manager is provided, Request tracks the certificate generation its mounted _MutualTlsAdapter was built from and atomically swaps in a new adapter across every contacted mTLS origin on rotation, leaving caller-mounted custom adapters and sub-path mounts untouched. Shallow and deep copies keep sharing the same cert_manager (and session-scoped lock and adapter state on shallow copies) so background refresh and Regional Access Boundary copies continue rotating, while pickling drops the manager and adapter so unpickled instances rediscover mTLS cleanly.

When cert_manager is omitted, Request keeps its existing static mTLS path unchanged. Reactive 401 rotation on standalone Request instances and downstream wiring into compute_engine and AuthMetadataPlugin are handled in follow-up PRs.

@nbayati
nbayati added this pull request to stack #19227 November 26, 2026 00:07

@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 a certificate manager to handle dynamic mTLS certificate rotation within the Request transport class. It encapsulates the mTLS adapter state in a new _MtlsAdapterState class to ensure thread-safe operations and correct behavior during copying. Additionally, the _replace_adapter helper was updated to support replacing previous adapter instances atomically. Comprehensive unit tests have been added to verify single and multi-origin rotation, custom adapter preservation, serialization, and concurrent rotation. I have no feedback to provide as there are no review comments.

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