Skip to content

feat: [grpc] Add retry logic when certificate mismatch for existing credentials & Agent Identity workloads - #18019

Open
agrawalradhika-cell wants to merge 11 commits into
googleapis:mainfrom
agrawalradhika-cell:grpc-cert-rotation
Open

feat: [grpc] Add retry logic when certificate mismatch for existing credentials & Agent Identity workloads #18019
agrawalradhika-cell wants to merge 11 commits into
googleapis:mainfrom
agrawalradhika-cell:grpc-cert-rotation

Conversation

@agrawalradhika-cell

Copy link
Copy Markdown
Contributor

feat: [grpc] Add retry logic when certificate mismatch for existing credentials & Agent Identity workloads

This PR introduces mTLS certificate rotation and encrypted private key passphrase handling to the gRPC transport. It implements an interceptor and a refreshing channel to automatically reload client certificates upon authentication failures when certificates rotate. It also updates tests and mock return values across all transports.

See go/grpc-cert-rotation-in-pythonsdk-for-x509 for details.

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - b/497848161
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

feat: Add passphrase handling to client cert callback
feat: Add cert rotation handling support
chore: Add passphrase in _mtls_helper for requests
…rase

chore: Modify _mtls_helper call to include additional variable passphrase
Updated mock return values in test cases to include None for additional parameters.
Updated mock callback to return an additional None value.
Updated mock call_client_cert_callback to include a None value in the return tuple.
chore: Add unit tests for cert rotation handling for grpc
chore: Add tests for grpc cert roatation handling changes
@agrawalradhika-cell
agrawalradhika-cell requested review from a team as code owners August 6, 2026 21:03

@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 mTLS certificate rotation and automatic retry capabilities for gRPC transport by implementing a refreshing channel wrapper and call interceptors. It also updates helper utilities to support key passphrases. The review feedback suggests handling potential CancelledError exceptions gracefully when checking futures to prevent thread crashes, and recommends removing several redundant getattr checks for attributes that are guaranteed to be initialized in their respective class constructors.

Comment thread packages/google-auth/google/auth/transport/grpc.py
Comment on lines +600 to +602
if len(self._parent._buffer) > getattr(
self._parent, "_max_items", 10000
):

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

Do not use defensive 'getattr' checks for attributes that are guaranteed to be initialized in the class's 'init' method. Since '_max_items' is always initialized in '_ReplayableIterator.init', you can access it directly.

                    if len(self._parent._buffer) > self._parent._max_items:
References
  1. Do not use defensive getattr(self, 'attribute', None) checks for attributes that are guaranteed to be initialized in the class's init method, as it adds unnecessary complexity.

Comment thread packages/google-auth/google/auth/transport/grpc.py
Comment thread packages/google-auth/google/auth/transport/grpc.py Outdated
Comment thread packages/google-auth/google/auth/transport/grpc.py Outdated
fix: Refactor gRPC call handling and state management
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