Skip to content

Conversation

@dragomirp
Copy link
Contributor

@dragomirp dragomirp commented Sep 17, 2025

  • Prevent early generation of the internal certificate
  • Use peer address as comon name in peer certificates
  • Update charm libs

Checklist

  • I have added or updated any relevant documentation.
  • I have cleaned any remaining cloud resources from my accounts.

@dragomirp dragomirp added the bug Something isn't working as expected label Sep 17, 2025
@github-actions github-actions bot added the Libraries: Out of sync The charm libs used are out-of-sync label Sep 17, 2025
@codecov
Copy link

codecov bot commented Sep 17, 2025

Codecov Report

❌ Patch coverage is 46.15385% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.51%. Comparing base (d1e7c54) to head (21567e7).
⚠️ Report is 5 commits behind head on 16/edge.

Files with missing lines Patch % Lines
src/charm.py 22.22% 7 Missing ⚠️

❌ Your project status has failed because the head coverage (64.51%) is below the target coverage (70.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##           16/edge    #1162      +/-   ##
===========================================
- Coverage    64.57%   64.51%   -0.07%     
===========================================
  Files           17       17              
  Lines         4328     4337       +9     
  Branches       669      671       +2     
===========================================
+ Hits          2795     2798       +3     
- Misses        1351     1357       +6     
  Partials       182      182              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dragomirp dragomirp force-pushed the dpe-8320-internal-peer-backups branch from ff8127c to 847d51a Compare September 17, 2025 13:05

if not self.get_secret(APP_SCOPE, "internal-ca"):
self.tls.generate_internal_peer_ca()
self.tls.generate_internal_peer_cert()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the internal cert generates before the IP is set to the peer data, the hostname will be used as common name. It also causes issues on Juju 4.

Comment on lines +167 to +169
None,
None,
None,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test on microceph with the internal certs, without using a TLS operator.

Comment on lines +77 to +78
def _get_peer_common_name(self) -> str:
return self.charm.unit_peer_data.get("database-peers-address") or self.host
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should use the peers address here, in case it's different from the relation address.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense, as we might have different Juju spaces and for the purpose of using the certificates for backup on replicas, what makes sense is the peer address.

Comment on lines +383 to +392
try:
if raw_cert := self.get_secret(UNIT_SCOPE, "internal-cert"):
cert = load_pem_x509_certificate(raw_cert.encode())
if (
cert.subject.get_attributes_for_oid(NameOID.COMMON_NAME)[0].value
!= self._unit_ip
):
self.tls.generate_internal_peer_cert()
except Exception:
logger.exception("Unable to check or update internal cert")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regenerate the cert if the common name is not the IP before the upgrade.

@dragomirp dragomirp changed the title [DPE-8320] internal peer backups [DPE-8320] Fix backups with internal certificates Sep 17, 2025
@dragomirp dragomirp marked this pull request as ready for review September 17, 2025 23:13
@dragomirp dragomirp requested review from a team, marceloneppel and taurus-forever and removed request for a team September 17, 2025 23:13
Copy link
Contributor

@taurus-forever taurus-forever left a comment

Choose a reason for hiding this comment

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

LGTM, please add one more message as we are going to regenerate cert.

cert.subject.get_attributes_for_oid(NameOID.COMMON_NAME)[0].value
!= self._unit_ip
):
self.tls.generate_internal_peer_cert()
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add INFO-like message to log to see when cert is regenerated (to simplify production troubleshooting). Warning is also fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added info log inside generate_internal_peer_cert().

@github-actions github-actions bot added Libraries: OK The charm libs used are OK and in-sync and removed Libraries: Out of sync The charm libs used are out-of-sync labels Sep 18, 2025
Comment on lines +77 to +78
def _get_peer_common_name(self) -> str:
return self.charm.unit_peer_data.get("database-peers-address") or self.host
Copy link
Member

Choose a reason for hiding this comment

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

Makes sense, as we might have different Juju spaces and for the purpose of using the certificates for backup on replicas, what makes sense is the peer address.

@dragomirp dragomirp merged commit d1b3c8c into 16/edge Sep 22, 2025
311 of 316 checks passed
@dragomirp dragomirp deleted the dpe-8320-internal-peer-backups branch September 22, 2025 20:59
dragomirp added a commit that referenced this pull request Oct 24, 2025
* Wait for ip to generate leader cert

* Regenerate cert if common name is host

* Add info message on internal cert generation
dragomirp added a commit that referenced this pull request Oct 24, 2025
* Wait for ip to generate leader cert

* Regenerate cert if common name is host

* Add info message on internal cert generation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as expected Libraries: OK The charm libs used are OK and in-sync

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants