-
Notifications
You must be signed in to change notification settings - Fork 341
feat: Add retry logic when certificate mismatch for existing credentials & Agent Identity workloads #1841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: Add retry logic when certificate mismatch for existing credentials & Agent Identity workloads #1841
Conversation
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>
… from mTLS configuration Signed-off-by: Radhika Agrawal <agrawalradhika@google.com>
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) |
There was a problem hiding this comment.
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?
_mtls_helper.get_client_ssl_credentials(generate_encrypted_key=True) | ||
) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
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 |
There was a problem hiding this comment.
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
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.