Skip to content

Commit e1c2f86

Browse files
DPE-5512: add instance_password_encryption to patroni.yml
1 parent c2d9df3 commit e1c2f86

File tree

6 files changed

+15
-5
lines changed

6 files changed

+15
-5
lines changed

src/charm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,6 +2366,7 @@ def update_config(
23662366
no_peers=no_peers,
23672367
user_databases_map=self.relations_user_databases_map,
23682368
slots=replication_slots or None,
2369+
instance_password_encryption=self.config.instance_password_encryption,
23692370
)
23702371
if no_peers:
23712372
return True

src/cluster.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@ def render_patroni_yml_file(
651651
no_peers: bool = False,
652652
user_databases_map: dict[str, str] | None = None,
653653
slots: dict[str, str] | None = None,
654+
instance_password_encryption: str | None = None,
654655
) -> None:
655656
"""Render the Patroni configuration file.
656657
@@ -670,6 +671,7 @@ def render_patroni_yml_file(
670671
no_peers: Don't include peers.
671672
user_databases_map: map of databases to be accessible by each user.
672673
slots: replication slots (keys) with assigned database name (values).
674+
instance_password_encryption: algorithm to use to encrypt the users passwords.
673675
"""
674676
if not self._are_passwords_set:
675677
logger.warning("Passwords are not yet generated by the leader")
@@ -724,6 +726,7 @@ def render_patroni_yml_file(
724726
patroni_password=self.patroni_password,
725727
user_databases_map=user_databases_map,
726728
slots=slots,
729+
instance_password_encryption=instance_password_encryption,
727730
)
728731
self.render_file(f"{PATRONI_CONF_PATH}/patroni.yaml", rendered, 0o600)
729732

templates/patroni.yml.j2

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,21 +181,21 @@ postgresql:
181181
- {{ 'hostssl' if enable_tls else 'host' }} all +charmed_admin 0.0.0.0/0 scram-sha-256
182182
- {{ 'hostssl' if enable_tls else 'host' }} all +charmed_databases_owner 0.0.0.0/0 scram-sha-256
183183
{%- if not connectivity %}
184-
- {{ 'hostssl' if enable_tls else 'host' }} all all {{ self_ip }} scram-sha-256
184+
- {{ 'hostssl' if enable_tls else 'host' }} all all {{ self_ip }} {{ instance_password_encryption }}
185185
- {{ 'hostssl' if enable_tls else 'host' }} all all 0.0.0.0/0 reject
186186
{%- elif enable_ldap %}
187187
- {{ 'hostssl' if enable_tls else 'host' }} all +identity_access 0.0.0.0/0 ldap {{ ldap_parameters }}
188-
- {{ 'hostssl' if enable_tls else 'host' }} all +internal_access 0.0.0.0/0 scram-sha-256
188+
- {{ 'hostssl' if enable_tls else 'host' }} all +internal_access 0.0.0.0/0 {{ instance_password_encryption }}
189189
{%- for user, databases in user_databases_map.items() %}
190-
- {{ 'hostssl' if enable_tls else 'host' }} {{ databases }} {{ user }} 0.0.0.0/0 scram-sha-256
190+
- {{ 'hostssl' if enable_tls else 'host' }} {{ databases }} {{ user }} 0.0.0.0/0 {{ instance_password_encryption }}
191191
{%- endfor %}
192192
{%- else %}
193193
- {{ 'hostssl' if enable_tls else 'host' }} all +internal_access 0.0.0.0/0 scram-sha-256
194194
{%- for user, databases in user_databases_map.items() %}
195195
{%- if 'pgbouncer_auth_relation_' in user %}
196196
- {{ 'hostssl' if enable_tls else 'host' }} {{ databases }} {{ user }} 0.0.0.0/0 md5
197197
{%- else %}
198-
- {{ 'hostssl' if enable_tls else 'host' }} {{ databases }} {{ user }} 0.0.0.0/0 scram-sha-256
198+
- {{ 'hostssl' if enable_tls else 'host' }} {{ databases }} {{ user }} 0.0.0.0/0 {{ instance_password_encryption }}
199199
{%- endif %}
200200
{%- endfor %}
201201
{%- endif %}
@@ -205,7 +205,7 @@ postgresql:
205205
- {{ 'hostssl' if enable_tls else 'host' }} replication replication {{ endpoint }}/32 scram-sha-256
206206
{%- endfor %}
207207
{%- for peer_ip in peers_ips %}
208-
- {{ 'hostssl' if enable_tls else 'host' }} replication replication {{ peer_ip }}/0 scram-sha-256
208+
- {{ 'hostssl' if enable_tls else 'host' }} replication replication {{ peer_ip }}/0 scram-sha-256
209209
{%- endfor %}
210210

211211
pg_ident:

tests/integration/test_config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ async def test_config_parameters(ops_test: OpsTest, charm) -> None:
4747
{
4848
"instance_max_locks_per_transaction": ["-1", "64"]
4949
}, # config option is between 64 and 2147483647
50+
{
51+
"instance_password_encryption": [test_string, "md5"]
52+
}, # config option is one of `md5` or `scram-sha-256`
5053
{
5154
"instance_password_encryption": [test_string, "scram-sha-256"]
5255
}, # config option is one of `md5` or `scram-sha-256`

tests/unit/test_charm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,7 @@ class _MockSnap:
11631163
no_peers=False,
11641164
user_databases_map={"operator": "all", "replication": "all", "rewind": "all"},
11651165
slots=None,
1166+
instance_password_encryption="scram-sha-256",
11661167
)
11671168
_handle_postgresql_restart_need.assert_called_once_with()
11681169
_restart_ldap_sync_service.assert_called_once()

tests/unit/test_cluster.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ def test_render_patroni_yml_file(peers_ips, patroni):
307307
raft_password = "fake-raft-password"
308308
patroni_password = "fake-patroni-password"
309309
postgresql_version = "16"
310+
instance_password_encryption = "md5"
310311

311312
# Get the expected content from a file.
312313
with open("templates/patroni.yml.j2") as file:
@@ -331,6 +332,7 @@ def test_render_patroni_yml_file(peers_ips, patroni):
331332
synchronous_node_count=0,
332333
raft_password=raft_password,
333334
patroni_password=patroni_password,
335+
render_patroni_yml_file=instance_password_encryption,
334336
)
335337

336338
# Setup a mock for the `open` method, set returned data to patroni.yml template.

0 commit comments

Comments
 (0)