Skip to content

Commit cc14fb8

Browse files
[DPE-2830] Update TLS lib and PostgreSQL TLS lib (#321)
* Update TLS lib and PostgreSQL TLS lib Signed-off-by: Marcelo Henrique Neppel <[email protected]> * Update poetry.lock Signed-off-by: Marcelo Henrique Neppel <[email protected]> * Update TLS lib and test Signed-off-by: Marcelo Henrique Neppel <[email protected]> --------- Signed-off-by: Marcelo Henrique Neppel <[email protected]>
1 parent bf91e13 commit cc14fb8

File tree

5 files changed

+798
-181
lines changed

5 files changed

+798
-181
lines changed

lib/charms/postgresql_k8s/v0/postgresql_tls.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@
2424
import socket
2525
from typing import List, Optional
2626

27-
from charms.tls_certificates_interface.v1.tls_certificates import (
27+
from charms.tls_certificates_interface.v2.tls_certificates import (
2828
CertificateAvailableEvent,
2929
CertificateExpiringEvent,
30-
TLSCertificatesRequiresV1,
30+
TLSCertificatesRequiresV2,
3131
generate_csr,
3232
generate_private_key,
3333
)
34-
from cryptography import x509
35-
from cryptography.x509.extensions import ExtensionType
3634
from ops.charm import ActionEvent, RelationBrokenEvent
3735
from ops.framework import Object
3836
from ops.pebble import ConnectionError, PathError, ProtocolError
@@ -45,7 +43,7 @@
4543

4644
# Increment this PATCH version before using `charmcraft publish-lib` or reset
4745
# to 0 if you are raising the major API version.
48-
LIBPATCH = 7
46+
LIBPATCH = 8
4947

5048
logger = logging.getLogger(__name__)
5149
SCOPE = "unit"
@@ -63,7 +61,7 @@ def __init__(
6361
self.charm = charm
6462
self.peer_relation = peer_relation
6563
self.additional_dns_names = additional_dns_names or []
66-
self.certs = TLSCertificatesRequiresV1(self.charm, TLS_RELATION)
64+
self.certs = TLSCertificatesRequiresV2(self.charm, TLS_RELATION)
6765
self.framework.observe(
6866
self.charm.on.set_tls_private_key_action, self._on_set_tls_private_key
6967
)
@@ -90,7 +88,6 @@ def _request_certificate(self, param: Optional[str]):
9088
csr = generate_csr(
9189
private_key=key,
9290
subject=self.charm.get_hostname_by_unit(self.charm.unit.name),
93-
additional_critical_extensions=self._get_tls_extensions(),
9491
**self._get_sans(),
9592
)
9693

@@ -161,7 +158,6 @@ def _on_certificate_expiring(self, event: CertificateExpiringEvent) -> None:
161158
new_csr = generate_csr(
162159
private_key=key,
163160
subject=self.charm.get_hostname_by_unit(self.charm.unit.name),
164-
additional_critical_extensions=self._get_tls_extensions(),
165161
**self._get_sans(),
166162
)
167163
self.certs.request_certificate_renewal(
@@ -207,12 +203,6 @@ def is_ip_address(address: str) -> bool:
207203
"sans_dns": sans_dns,
208204
}
209205

210-
@staticmethod
211-
def _get_tls_extensions() -> Optional[List[ExtensionType]]:
212-
"""Return a list of TLS extensions for which certificate key can be used."""
213-
basic_constraints = x509.BasicConstraints(ca=True, path_length=None)
214-
return [basic_constraints]
215-
216206
def get_tls_files(self) -> (Optional[str], Optional[str], Optional[str]):
217207
"""Prepare TLS files in special PostgreSQL way.
218208

0 commit comments

Comments
 (0)