Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

agrawalradhika-cell
Copy link

@agrawalradhika-cell agrawalradhika-cell commented Oct 16, 2025

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

This change introduces retry support when requests are created for existing credentials and Agent Identities on GKE and Cloud Run Workloads. When 401(Unauthorized) error is created, due to certificate at time of configuration of mTLS channel being different from the current certificate, a retry is added to the request by configuring the mTLS channel with the current certificate.

This change introduces retry support when requests are created for AgentIdentities on GKE and Cloud Run Workloads.

Signed-off-by: Radhika Agrawal <agrawalradhika@google.com>
…ion and request

Signed-off-by: Radhika Agrawal <agrawalradhika@google.com>
@agrawalradhika-cell agrawalradhika-cell changed the title Cert rotation x509 feat: Add retry logic when certificate mismatch for Agent Identity Oct 16, 2025
@agrawalradhika-cell agrawalradhika-cell marked this pull request as ready for review October 17, 2025 01:17
@agrawalradhika-cell agrawalradhika-cell requested review from a team as code owners October 17, 2025 01:17
@agrawalradhika-cell agrawalradhika-cell marked this pull request as draft October 17, 2025 01:17
… from mTLS configuration

Signed-off-by: Radhika Agrawal <agrawalradhika@google.com>
@agrawalradhika-cell agrawalradhika-cell marked this pull request as ready for review October 17, 2025 19:54
@lsirac
Copy link
Contributor

lsirac commented Oct 18, 2025

Is the description accurate? This will apply to existing X509 workloads too?

@agrawalradhika-cell agrawalradhika-cell changed the title feat: Add retry logic when certificate mismatch for Agent Identity feat: Add retry logic when certificate mismatch for existing credentials & Agent Identity workloads Oct 20, 2025
@agrawalradhika-cell
Copy link
Author

Is the description accurate? This will apply to existing X509 workloads too?

Updated the description


if self._is_mtls:
mtls_adapter = _MutualTlsAdapter(cert, key)
self._cached_cert = lambda: (cert)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you intend to put this line under the if condition?

Comment on lines +627 to +628
_mtls_helper.get_client_ssl_credentials(generate_encrypted_key=True)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent right?

if cached_fingerprint != current_cert_fingerprint:
try:
_LOGGER.info("Client certificate has changed, reconfiguring mTLS channel.")
self.configure_mtls_channel(self.call_client_cert_callback)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.call_client_cert_callback is called twice, once to check and once to set. can you reuse from the check?

Comment on lines +494 to +511
def call_client_cert_callback(self):
"""Calls the current client cert callback and returns the certificate and key."""
_, cert_bytes, key_bytes, passphrase = (
_mtls_helper.get_client_ssl_credentials(generate_encrypted_key=True)
)
return cert_bytes, key_bytes

def get_cached_cert_fingerprint(self):
"""Returns the fingerprint of the cached certificate."""
if self._cached_cert:
cached_cert_fingerprint = (
_agent_identity_utils.calculate_certificate_fingerprint(
self._cached_cert()
)
)
else:
raise ValueError("mTLS connection is not configured.")
return cached_cert_fingerprint
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these 2 methods are same as in requests.py. can you put them in some utils or modify existing utils to take in the value of self._cached_cert

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.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.