Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a16116a
Update charmcraft.yaml build tools (#903)
renovate[bot] Mar 25, 2025
7083f18
Update canonical/data-platform-workflows action to v31.0.1 (#902)
renovate[bot] Mar 25, 2025
91ec95e
[DPE-6344] LDAP IV: Define pebble service (#897)
sinclert-canonical Mar 26, 2025
1be9f1b
Update ghcr.io/canonical/charmed-postgresql:14.17-22.04_edge Docker d…
renovate[bot] Mar 26, 2025
8a3957e
[DPE-6344] LDAP V: Define mapping option (#900)
sinclert-canonical Mar 28, 2025
b85d54e
Update charmcraft.yaml build tools (#912)
renovate[bot] Apr 2, 2025
5041520
[DPE-6910] Remove duplicate parameters specification (#896)
marceloneppel Apr 4, 2025
699e5c2
[MISC] Conditional checksum calculation (#901)
dragomirp Apr 8, 2025
afea281
Update charmcraft.yaml build tools (#916)
renovate[bot] Apr 9, 2025
fa2f7f8
Create SECURITY.md (#914)
marceloneppel Apr 9, 2025
bce4974
Update pull_request_template.md (#918)
a-velasco Apr 9, 2025
073110f
[MISC] Add missing connection vars (#920)
sinclert-canonical Apr 10, 2025
3ce2aa5
Update README file's security section (#921)
izmalk Apr 10, 2025
e060a91
[DPE-6218] Static code analysis (#915)
marceloneppel Apr 10, 2025
7ca1e26
Update dependency uv to v0.6.14 (#924)
renovate[bot] Apr 15, 2025
d5114d9
Disable pgaudit (#931)
dragomirp Apr 17, 2025
94c25c3
Lock file maintenance Python dependencies (main) (#904)
renovate[bot] Apr 21, 2025
c246fae
[DPE-6344] Remove CA transferred check (#932)
sinclert-canonical Apr 22, 2025
bebd8b9
[MISC] Don't set tls flag if relation isn't initialised (#933)
dragomirp Apr 22, 2025
6f97e1d
Update dependency uv to v0.6.16 (#936)
renovate[bot] Apr 22, 2025
68c1e42
Lock file maintenance Python dependencies (#937)
renovate[bot] Apr 22, 2025
bb2459a
Update ghcr.io/canonical/charmed-postgresql:14.17-22.04_edge Docker d…
renovate[bot] Apr 22, 2025
9f306cc
Merge branch 'main' into sync16
dragomirp Apr 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,7 @@ def _generate_ldap_service(self) -> dict:

ldap_base_dn = ldap_params["ldapbasedn"]
ldap_bind_username = ldap_params["ldapbinddn"]
ldap_bing_password = ldap_params["ldapbindpasswd"]
ldap_bind_password = ldap_params["ldapbindpasswd"]
ldap_group_mappings = self.postgresql.build_postgresql_group_map(self.config.ldap_map)

return {
Expand All @@ -1766,7 +1766,7 @@ def _generate_ldap_service(self) -> dict:
"LDAP_PORT": ldap_port,
"LDAP_BASE_DN": ldap_base_dn,
"LDAP_BIND_USERNAME": ldap_bind_username,
"LDAP_BIND_PASSWORD": ldap_bing_password,
"LDAP_BIND_PASSWORD": ldap_bind_password,
"LDAP_GROUP_IDENTITY": json.dumps(ACCESS_GROUP_IDENTITY),
"LDAP_GROUP_MAPPINGS": json.dumps(ldap_group_mappings),
"POSTGRES_HOST": "127.0.0.1",
Expand Down Expand Up @@ -1984,7 +1984,7 @@ def _restart_ldap_sync_service(self) -> None:

if not self.is_primary and sync_service[0].is_running():
logger.debug("Stopping LDAP sync service. It must only run in the primary")
container.stop(self.pg_ldap_sync_service)
container.stop(self.ldap_sync_service)

if self.is_primary and not self.is_ldap_enabled:
logger.debug("Stopping LDAP sync service")
Expand Down
23 changes: 2 additions & 21 deletions src/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@
LdapRequirer,
LdapUnavailableEvent,
)
from charms.postgresql_k8s.v0.postgresql_tls import (
TLS_TRANSFER_RELATION,
)
from ops import Relation
from ops.framework import Object
from ops.model import ActiveStatus, BlockedStatus
from ops.model import ActiveStatus

logger = logging.getLogger(__name__)

Expand All @@ -35,29 +32,13 @@ def __init__(self, charm, relation_name: str):
self.framework.observe(self.ldap.on.ldap_ready, self._on_ldap_ready)
self.framework.observe(self.ldap.on.ldap_unavailable, self._on_ldap_unavailable)

@property
def ca_transferred(self) -> bool:
"""Return whether the CA certificate has been transferred."""
ca_transferred_relations = self.model.relations[TLS_TRANSFER_RELATION]

for relation in ca_transferred_relations:
if relation.app.name == self._relation.app.name:
return True

return False

@property
def _relation(self) -> Relation:
"""Return the relation object."""
return self.model.get_relation(self.relation_name)

def _on_ldap_ready(self, event: LdapReadyEvent) -> None:
def _on_ldap_ready(self, _: LdapReadyEvent) -> None:
"""Handler for the LDAP ready event."""
if not self.ca_transferred:
self.charm.unit.status = BlockedStatus("LDAP insecure. Send LDAP server certificate")
event.defer()
return

logger.debug("Enabling LDAP connection")
if self.charm.unit.is_leader():
self.charm.app_peer_data.update({"ldap_enabled": "True"})
Expand Down
5 changes: 3 additions & 2 deletions src/relations/postgresql_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@ def update_tls_flag(self, tls: str) -> None:
ca = ""

for relation in relations:
self.database_provides.set_tls(relation.id, tls)
self.database_provides.set_tls_ca(relation.id, ca)
if self.database_provides.fetch_relation_field(relation.id, "database"):
self.database_provides.set_tls(relation.id, tls)
self.database_provides.set_tls_ca(relation.id, ca)

def _check_multiple_endpoints(self) -> bool:
"""Checks if there are relations with other endpoints."""
Expand Down
1 change: 0 additions & 1 deletion tests/integration/ha_tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ async def test_deploy_latest(ops_test: OpsTest) -> None:
await ops_test.model.wait_for_idle(
apps=[DATABASE_APP_NAME, APPLICATION_NAME],
status="active",
raise_on_error=False,
timeout=1000,
)
assert len(ops_test.model.applications[DATABASE_APP_NAME].units) == 3
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/ha_tests/test_upgrade_from_stable.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def test_deploy_stable(ops_test: OpsTest) -> None:
logger.info("Wait for applications to become active")
async with ops_test.fast_forward():
await ops_test.model.wait_for_idle(
apps=[DATABASE_APP_NAME, APPLICATION_NAME], status="active", raise_on_error=False
apps=[DATABASE_APP_NAME, APPLICATION_NAME], status="active"
)
assert len(ops_test.model.applications[DATABASE_APP_NAME].units) == 3

Expand Down
1 change: 0 additions & 1 deletion tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ async def build_and_deploy(
apps=[database_app_name],
status=status,
raise_on_blocked=True,
raise_on_error=False,
timeout=1000,
wait_for_exact_units=num_units,
)
Expand Down
25 changes: 2 additions & 23 deletions tests/unit/test_ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from unittest.mock import (
MagicMock,
PropertyMock,
patch,
)

Expand All @@ -29,14 +28,10 @@ def harness():
harness.cleanup()


def test_on_ldap_ready_with_certificate(harness):
def test_on_ldap_ready(harness):
mock_event = MagicMock()

with (
patch("charm.PostgresqlOperatorCharm.update_config") as _update_config,
patch("charm.PostgreSQLLDAP.ca_transferred", new_callable=PropertyMock) as _ca_transferred,
):
_ca_transferred.return_value = True
with patch("charm.PostgresqlOperatorCharm.update_config") as _update_config:
harness.charm.ldap._on_ldap_ready(mock_event)
_update_config.assert_called_once()

Expand All @@ -45,22 +40,6 @@ def test_on_ldap_ready_with_certificate(harness):
assert "ldap_enabled" in app_databag


def test_on_ldap_ready_without_certificate(harness):
mock_event = MagicMock()

with (
patch("charm.PostgresqlOperatorCharm.update_config") as _update_config,
patch("charm.PostgreSQLLDAP.ca_transferred", new_callable=PropertyMock) as _ca_transferred,
):
_ca_transferred.return_value = False
harness.charm.ldap._on_ldap_ready(mock_event)
_update_config.assert_not_called()

peer_rel_id = harness.model.get_relation(PEER).id
app_databag = harness.get_relation_data(peer_rel_id, harness.charm.app)
assert "ldap_enabled" not in app_databag


def test_on_ldap_unavailable(harness):
mock_event = MagicMock()

Expand Down
26 changes: 25 additions & 1 deletion tests/unit/test_postgresql_provider.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2022 Canonical Ltd.
# See LICENSE file for licensing details.

from unittest.mock import Mock, PropertyMock, patch
from unittest.mock import Mock, PropertyMock, patch, sentinel

import pytest
from charms.postgresql_k8s.v0.postgresql import (
Expand Down Expand Up @@ -216,3 +216,27 @@ def test_on_relation_broken(harness):
)
harness.charm.postgresql_client_relation._on_relation_broken(event)
postgresql_mock.delete_user.assert_not_called()


def test_update_tls_flag(harness):
with (
patch("charm.PostgreSQLTLS.get_tls_files", return_value=(None, sentinel.ca, None)),
patch(
"relations.postgresql_provider.new_password", return_value="test-password"
) as _new_password,
patch(
"relations.postgresql_provider.DatabaseProvides.fetch_relation_field",
side_effect=[None, "db"],
),
patch(
"relations.postgresql_provider.DatabaseProvides.set_tls",
) as _set_tls,
patch(
"relations.postgresql_provider.DatabaseProvides.set_tls_ca",
) as _set_tls_ca,
):
with harness.hooks_disabled():
second_rel = harness.add_relation(RELATION_NAME, "second_app")
harness.charm.postgresql_client_relation.update_tls_flag("True")
_set_tls.assert_called_once_with(second_rel, "True")
_set_tls_ca.assert_called_once_with(second_rel, sentinel.ca)