Skip to content

[DPE-7899] 8.4 - Migrate to TLS v4 (I)#248

Open
sinclert-canonical wants to merge 9 commits into8.4/edgefrom
sinclert/7899/tls-v4-part-1
Open

[DPE-7899] 8.4 - Migrate to TLS v4 (I)#248
sinclert-canonical wants to merge 9 commits into8.4/edgefrom
sinclert/7899/tls-v4-part-1

Conversation

@sinclert-canonical
Copy link
Copy Markdown
Contributor

@sinclert-canonical sinclert-canonical commented Apr 16, 2026

This PR migrates the handling of TLS certificates to use version 4 of the tls-certificates interface.

The library used to deal with version 4 of such interface was initially published as a charmlib, but then ported to a pure Python package within the charmlibs repository, to be published and consumed via PyPi. Despite the package current version (1.X.Y), it is shipping version 4 of the interface.

Approach:

The new interface version allow us to simplify the current logic by skipping any certificate expiration event handling. This is now managed by the provider automatically, so the only event we need to handle is CertificateAvailable.

Future work:

  1. Enable peer-to-peer encryption by enabling the group replication SSL.
  2. Define the necessary logic to parse a manually configured private key for TLS certificates generation.

@sinclert-canonical sinclert-canonical added the enhancement New feature, UI change, or workload upgrade label Apr 16, 2026
@github-actions github-actions Bot added the Libraries: Out of sync The charm libs used are out-of-sync label Apr 16, 2026
Comment thread kubernetes/tests/integration/integration/test_tls.py Fixed
Comment thread kubernetes/tests/integration/integration/test_tls.py Fixed
Comment thread kubernetes/tests/integration/integration/test_tls.py Fixed
Comment thread kubernetes/tests/integration/integration/test_tls.py Fixed
Comment thread kubernetes/tests/integration/integration/test_tls.py Fixed
Comment thread kubernetes/tests/integration/integration/test_tls.py Fixed
Comment thread machines/tests/integration/integration/test_tls.py Fixed
Comment thread machines/tests/integration/integration/test_tls.py Fixed
@sinclert-canonical sinclert-canonical force-pushed the sinclert/7899/tls-v4-part-1 branch from 7ae46b1 to aa07e3e Compare April 16, 2026 15:35
Comment thread kubernetes/src/charm.py
Comment on lines +362 to +364
except RuntimeError:
logger.warning("Unit DNS domain name is not propagated yet")
return ""
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is required so that the TLS class initialization does not crash when the charm does not has any of the expected relations (database, database-peers, replication, replication-offer). This usually happens at the very early stages of a charm deployment, or during unit tests.

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.

Should we defer instead. I not sure how cert request behave with a "" SAN

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am not entirely sure how to do so: the function does not received any event to defer upon 🤔

Regardless, these host-names will only be used when the group-replication encryption mode is set to VERIFY_IDENTITY (see docs), which we are far from using. The code is here to mimic PostgreSQL way of dealing with certificate generation.

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.

Good point. I'd say then to not include the empty str in the SAN set.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Avoiding the empty string is already managed here, similarly to PostgreSQL implementation (see code).

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.

What about moving this try...except one level up then? Not a fan of that return ""

Comment thread machines/src/charm.py
@sinclert-canonical sinclert-canonical force-pushed the sinclert/7899/tls-v4-part-1 branch 3 times, most recently from 436a30b to f4c48c0 Compare April 21, 2026 14:55
@sinclert-canonical sinclert-canonical marked this pull request as ready for review April 22, 2026 09:00
Copy link
Copy Markdown
Contributor

@paulomach paulomach left a comment

Choose a reason for hiding this comment

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

Nice. Couple open questions, minor catches

Comment thread kubernetes/src/relations/tls.py Outdated
Comment thread kubernetes/src/charm.py
Comment on lines +362 to +364
except RuntimeError:
logger.warning("Unit DNS domain name is not propagated yet")
return ""
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.

Should we defer instead. I not sure how cert request behave with a "" SAN

Comment thread kubernetes/src/relations/tls.py
Comment thread kubernetes/src/charm.py Outdated
@sinclert-canonical sinclert-canonical marked this pull request as draft April 22, 2026 10:31
@sinclert-canonical sinclert-canonical force-pushed the sinclert/7899/tls-v4-part-1 branch from d4512d1 to 267e79f Compare April 23, 2026 10:01
@sinclert-canonical sinclert-canonical marked this pull request as ready for review April 23, 2026 10:07
@sinclert-canonical sinclert-canonical force-pushed the sinclert/7899/tls-v4-part-1 branch 2 times, most recently from 5d69742 to 5a87f5b Compare April 23, 2026 12:42
@sinclert-canonical sinclert-canonical force-pushed the sinclert/7899/tls-v4-part-1 branch from 5a87f5b to 5758b15 Compare April 23, 2026 13:56
@sinclert-canonical
Copy link
Copy Markdown
Contributor Author

🗞️ PR branch rebased from 8.4/edge. This is ready for review again.

Copy link
Copy Markdown
Contributor

@paulomach paulomach left a comment

Choose a reason for hiding this comment

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

No blocker from my side! Nice work

Copy link
Copy Markdown
Contributor

@astrojuanlu astrojuanlu left a comment

Choose a reason for hiding this comment

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

Left a few nits, leaving those to your discretion. Otherwise LGTM!

Comment on lines +94 to +96
— CA file should have a full chain.
— Key file should have private key.
— Certificate file should have certificate without certificate chain.
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.

Suggested change
CA file should have a full chain.
Key file should have private key.
Certificate file should have certificate without certificate chain.
- CA file should have a full chain.
- Key file should have private key.
- Certificate file should have certificate without certificate chain.

?

Comment on lines +136 to +137
except MySQLTLSSetupError:
logger.error("Failed to enable TLS configuration.")
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.

Any problem with retaining the original context for debugging?

Suggested change
except MySQLTLSSetupError:
logger.error("Failed to enable TLS configuration.")
except MySQLTLSSetupError as exc:
logger.error(f"Failed to enable TLS configuration: {exc}")

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.

Or even logger.exception to show the full traceback

Comment on lines +154 to +155
except MySQLTLSSetupError:
logger.error("Failed to disable TLS configuration.")
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.

Same as above:

Suggested change
except MySQLTLSSetupError:
logger.error("Failed to disable TLS configuration.")
except MySQLTLSSetupError as exc:
logger.error(f"Failed to disable TLS configuration: {exc}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature, UI change, or workload upgrade Libraries: Out of sync The charm libs used are out-of-sync

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants