Skip to content

fix: retry a failed CA bundle update and compare the bundle byte for byte - #65

Merged
nsklikas merged 1 commit into
mainfrom
retry-ca-bundle-update
Nov 23, 2026
Merged

nsklikas merged 1 commit into
mainfrom
retry-ca-bundle-update

Conversation

@nsklikas

Copy link
Copy Markdown
Collaborator

What

Two gaps in how the charm applies the CA bundle of receive-ca-cert (_ensure_tls). Nothing has to merge before this, and nothing waits for it.

A failed update was not always tried again. The charm keeps a copy of the bundle and acts only when the bundle differs from it. It wrote the copy before it ran update-ca-certificates and pushed the result to the workload, and it handled only a failure of the first step, by removing the copy:

  • when the push to the workload failed (a Pebble error), the hook failed, and the retried hook found the copy equal to the bundle and did nothing: the unit ended active without the CA;
  • when the bundle was removed and either step failed, the copy was already gone, so the removal was never retried and the workload kept the removed CA.

Both steps are now in one try, a Pebble error and an OSError (a request to Pebble that times out, a missing binary) are caught too, and on failure the earlier copy is put back, so the next reconciliation sees a difference and runs both steps again.

A bundle with CRLF line endings never equalled its copy. The copy was read as text, which turns \r\n into \n, so every hook wrote the copy again, ran update-ca-certificates and pulled the workload's file to compare. The copy is now read without newline translation.

Good to know

  • The CRLF gap did not restart the service: the push happens only when the workload's file differs.
  • Not changed: a restart that fails after a successful push is not forced again on the next hook.
  • Not changed: when the workload container restarts alone, its bundle goes back to the image's while the charm's copy still equals the relation's, so nothing is pushed until the bundle changes or the pod is replaced.
  • The SSO Service's charm has the same method with the same change (feat: add the sso-service charm sso-service-operator#4), and forgets its copy at pebble-ready for the case above.

Tests

  • Unit tests, one per decision: a failed push is retried (Pebble down, and Pebble not answering in time), a failed removal is retried, an applied bundle with CRLF line endings is not applied again. Each fails without its part of the fix.
  • 150 unit tests pass. Not deployed.

@nsklikas
nsklikas force-pushed the retry-ca-bundle-update branch from 3efd2a6 to c0a8c36 Compare October 23, 2026 11:57
@nsklikas
nsklikas force-pushed the retry-ca-bundle-update branch from c0a8c36 to 2d01e16 Compare November 19, 2026 13:59
@nsklikas
nsklikas marked this pull request as ready for review November 20, 2026 10:17
@nsklikas
nsklikas requested a review from a team as a code owner November 20, 2026 10:17
…byte

The charm keeps a copy of the CA bundle and acts only when the bundle
differs from it. The copy was written before update-ca-certificates ran
and before the result was pushed to the workload, and only a failure of
the first step was handled, by removing the copy. A push that failed left
the copy equal to the bundle, so the next hook did nothing and the unit
ended active without the CA; a removal that failed was never tried again.
Both steps are now in one try, a Pebble error and an OSError (a request
that times out, a missing binary) are caught too, and on failure the
earlier copy is put back, so that the next reconciliation runs both steps
again.

The copy was also read as text, which turns CRLF into LF: a bundle with
CRLF line endings never equalled its copy, and every hook wrote the copy
and ran update-ca-certificates again. It is now read without newline
translation.
@nsklikas
nsklikas force-pushed the retry-ca-bundle-update branch from 2d01e16 to c3651bf Compare November 23, 2026 14:37
@nsklikas
nsklikas enabled auto-merge November 23, 2026 14:38
@nsklikas
nsklikas merged commit 26fa056 into main Nov 23, 2026
6 checks passed
@nsklikas
nsklikas deleted the retry-ca-bundle-update branch November 23, 2026 14:55
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.

2 participants