Skip to content

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

Open
agrawalradhika-cell wants to merge 25 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 25 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 thread packages/google-auth/google/auth/transport/grpc.py Outdated
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
@nbayati
nbayati self-requested a review August 7, 2026 18:41
@parthea

parthea commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

The github status checks are stuck. You could try closing and re-opening this PR to re-trigger them

@agrawalradhika-cell
agrawalradhika-cell marked this pull request as ready for review August 11, 2026 16:06
Comment thread packages/google-auth/google/auth/transport/_mtls_helper.py Outdated
Comment thread packages/google-auth/google/auth/transport/_mtls_helper.py Outdated
Comment thread packages/google-auth/google/auth/transport/grpc.py Outdated
Comment thread packages/google-auth/google/auth/transport/grpc.py Outdated
Comment thread packages/google-auth/google/auth/transport/grpc.py Outdated
Comment thread packages/google-auth/google/auth/transport/grpc.py Outdated
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
Comment thread packages/google-auth/google/auth/transport/grpc.py Outdated
…mments and fix doctrings

chore: Update Refactor mTLS gRPC client interceptor logic based on comments and fix doctrings
…ype hint for passphrase.

chore: Refactor error handling for certificate retrieval and update type hint for passphrase.
fix: Refactor deadline error handling in grpc.py

@daniel-sanche daniel-sanche 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.

I left some comments after a first pass, but I need to spend more time reviewing some of these wrappers.

First though, are you sure this is the right layer? I don't have much context on this change, but IIRC, gapic libraries use a different channel type. So I just want to make sure this is accomplishing what you want it to

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
Comment thread packages/google-auth/google/auth/transport/grpc.py
"client_cert_callback": client_cert_callback,
"_is_recreation": True, # Hidden flag to stop recursion
**kwargs,
}

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.

Instead of passing through all these arguments, it could be better to create a create_channel_fn partial here, and pass that in instead (we did something similar for bigtable)

Comment thread packages/google-auth/google/auth/transport/grpc.py
Comment thread packages/google-auth/google/auth/transport/grpc.py
Comment thread packages/google-auth/google/auth/transport/grpc.py
return self._is_mtls


class _MTLSCallInterceptor(

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.

It might be worth creating a new file for these new classes? There are a bunch of them that seem pretty tightly coupled, without much integration with other classes in this file

Signed-off-by: Radhika Agrawal <agrawalradhika@google.com>
chore: Refactor gRPC call handling with base wrapper class
chore: Include Wrapper in CertRotationInterceptor initialization
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.

4 participants