Skip to content
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

[DPE-5964] - TLS certificate renewal #17

Open
wants to merge 4 commits into
base: DPE-5962-tls-implement-basic-flow
Choose a base branch
from

Conversation

skourta
Copy link
Contributor

@skourta skourta commented Jan 9, 2025

This PR handeled the TLS certificate renewal.

Enhancements to TLS Handling:

  • Modified the Status enum in src/literals.py to update the message for TLS_NOT_READY to "enabling/disabling TLS" for better clarity.
  • Updated the _on_certificate_available method in src/events/tls.py to only write the certificates to disk if TLS has already been enabled.

Improvements to Tests:

  • Added assertions to several test functions in tests/integration/test_tls.py to ensure that the leader unit and secrets are correctly retrieved. [1] [2] [3] [4] [5]
  • Introduced a new test case test_certificate_expiration in tests/integration/test_tls.py to verify that the system correctly handles certificate expiration and renewal.

Code Refinements:

  • Added type hints to functions in tests/integration/helpers.py to improve code readability and maintainability. [1] [2]
  • Imported CertType from managers/tls in tests/integration/helpers.py and tests/integration/test_tls.py to support the new test case and helper function. [1] [2]

Dependency Update:

  • Added pydantic version 2.9.1 to integration dependencies.

@skourta skourta marked this pull request as ready for review January 9, 2025 07:50
Copy link

@Mehdi-Bendriss Mehdi-Bendriss left a comment

Choose a reason for hiding this comment

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

Thanks Smail! No major concerns, I left some small questions.

# write certificates to disk
self.charm.tls_manager.write_certificate(cert, private_key)

# Updating certificates no need to do a rolling restart
if self.charm.state.unit_server.tls_state == TLSState.TLS:

Choose a reason for hiding this comment

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

what of the case where the peer-cert was issued but this hook was invoked for the client-cert? what would the state of tls be?

if self.charm.state.unit_server.certs_ready:
self.charm.set_status(Status.TLS_NOT_READY)

Choose a reason for hiding this comment

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

Left a comment on the other PR about this

# check if all units have been added to the cluster
endpoints = get_cluster_endpoints(ops_test, APP_NAME, tls_enabled=True)
leader_unit = await get_juju_leader_unit_name(ops_test, APP_NAME)
assert leader_unit

Choose a reason for hiding this comment

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

was there a case when this was false?


# make sure data can be written to the cluster
secret = await get_secret_by_label(ops_test, label=f"{PEER_RELATION}.{APP_NAME}.app")
assert secret

Choose a reason for hiding this comment

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

please add messages to your assertion for when they fail.
e.g

assert secret, f"Secret: {PEER_RELATION}.{APP_NAME}.app" missing.

# wait for certificate to expire
logger.info(f"Waiting for the certificate to expire {EXPIRATION_WAITING_TIME}s")
sleep(EXPIRATION_WAITING_TIME)

Choose a reason for hiding this comment

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

Can we add a test on the status of the application / units? Does it change?

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