fix(utils): swallow ssl.SSLError from empty/corrupt CA bundle#187
Draft
marceloneppel wants to merge 1 commit into
Draft
fix(utils): swallow ssl.SSLError from empty/corrupt CA bundle#187marceloneppel wants to merge 1 commit into
marceloneppel wants to merge 1 commit into
Conversation
load_verify_locations raises FileNotFoundError when the CA bundle file is absent (already suppressed), but ssl.SSLError (NO_CERTIFICATE_OR_CRL_FOUND) when the file exists yet holds no certificates. The suppress(FileNotFoundError) guard did not catch the latter, so the error escaped parallel_patroni_get_request -> cluster_status -> get_primary (which only catches RetryError) and crashed the storage-detaching hook during scale-down, leaving the unit in error and the data storage attached. An empty CA bundle can arise at storage-detaching time because the charm touches an empty /tmp/peer_ca_bundle.pem on _on_start and rewrites it from get_peer_ca_bundle(), which returns "" while the unit's TLS material is being torn down. Treat a missing OR certless bundle as "cannot verify this endpoint" and degrade to an unreachable request (returns None) rather than propagating. Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
Scaling down a
postgresql-k8sunit fails thestorage-detachinghook with an uncaught exception:The unit is left in
errorand thedatastorage stays attached.Solution
load_verify_locationsraisesFileNotFoundErrorwhen the CA bundle file is missing (already suppressed), butssl.SSLError(NO_CERTIFICATE_OR_CRL_FOUND) when the file exists yet holds no certificates. Thesuppress(FileNotFoundError)guard did not catch the latter, so the error escapedparallel_patroni_get_request→cluster_status→get_primary(which only catchesRetryError) and crashed thestorage-detachinghook.An empty CA bundle can arise at storage-detaching time: the charm touches an empty
/tmp/peer_ca_bundle.pemon_on_startand rewrites it fromget_peer_ca_bundle(), which returns""while the unit's TLS material is being torn down.Broaden the guard to also swallow
ssl.SSLError, so a missing OR certless bundle degrades to an unreachable request (returnsNone) instead of propagating — matching the degradation the originalsuppresswas reaching for. Adds a regression test asserting an empty CA bundle no longer crashesparallel_patroni_get_request.Checklist