Skip to content

Commit fe73262

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

File tree

6 files changed

+17
-5
lines changed

6 files changed

+17
-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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ postgresql:
173173
- local all backup peer map=operator
174174
- local all operator scram-sha-256
175175
- local all monitoring password
176+
- local all taurus {{ instance_password_encryption }}
176177
- {{ 'hostssl' if enable_tls else 'host' }} all +charmed_stats 0.0.0.0/0 scram-sha-256
177178
- {{ 'hostssl' if enable_tls else 'host' }} all +charmed_read 0.0.0.0/0 scram-sha-256
178179
- {{ 'hostssl' if enable_tls else 'host' }} all +charmed_dml 0.0.0.0/0 scram-sha-256
@@ -181,21 +182,21 @@ postgresql:
181182
- {{ 'hostssl' if enable_tls else 'host' }} all +charmed_admin 0.0.0.0/0 scram-sha-256
182183
- {{ 'hostssl' if enable_tls else 'host' }} all +charmed_databases_owner 0.0.0.0/0 scram-sha-256
183184
{%- if not connectivity %}
184-
- {{ 'hostssl' if enable_tls else 'host' }} all all {{ self_ip }} scram-sha-256
185+
- {{ 'hostssl' if enable_tls else 'host' }} all all {{ self_ip }} {{ instance_password_encryption }}
185186
- {{ 'hostssl' if enable_tls else 'host' }} all all 0.0.0.0/0 reject
186187
{%- elif enable_ldap %}
187188
- {{ '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
189+
- {{ 'hostssl' if enable_tls else 'host' }} all +internal_access 0.0.0.0/0 {{ instance_password_encryption }}
189190
{%- 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
191+
- {{ 'hostssl' if enable_tls else 'host' }} {{ databases }} {{ user }} 0.0.0.0/0 {{ instance_password_encryption }}
191192
{%- endfor %}
192193
{%- else %}
193194
- {{ 'hostssl' if enable_tls else 'host' }} all +internal_access 0.0.0.0/0 scram-sha-256
194195
{%- for user, databases in user_databases_map.items() %}
195196
{%- if 'pgbouncer_auth_relation_' in user %}
196197
- {{ 'hostssl' if enable_tls else 'host' }} {{ databases }} {{ user }} 0.0.0.0/0 md5
197198
{%- else %}
198-
- {{ 'hostssl' if enable_tls else 'host' }} {{ databases }} {{ user }} 0.0.0.0/0 scram-sha-256
199+
- {{ 'hostssl' if enable_tls else 'host' }} {{ databases }} {{ user }} 0.0.0.0/0 {{ instance_password_encryption }}
199200
{%- endif %}
200201
{%- endfor %}
201202
{%- endif %}
@@ -205,7 +206,7 @@ postgresql:
205206
- {{ 'hostssl' if enable_tls else 'host' }} replication replication {{ endpoint }}/32 scram-sha-256
206207
{%- endfor %}
207208
{%- for peer_ip in peers_ips %}
208-
- {{ 'hostssl' if enable_tls else 'host' }} replication replication {{ peer_ip }}/0 scram-sha-256
209+
- {{ 'hostssl' if enable_tls else 'host' }} replication replication {{ peer_ip }}/0 scram-sha-256
209210
{%- endfor %}
210211

211212
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: 2 additions & 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()
@@ -1194,6 +1195,7 @@ class _MockSnap:
11941195
no_peers=False,
11951196
user_databases_map={"operator": "all", "replication": "all", "rewind": "all"},
11961197
slots=None,
1198+
instance_password_encryption="scram-sha-256",
11971199
)
11981200
_handle_postgresql_restart_need.assert_called_once()
11991201
_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
@@ -295,6 +295,7 @@ def test_render_patroni_yml_file(peers_ips, patroni):
295295
new_callable=PropertyMock,
296296
return_value=["1.1.1.1", "192.168.0.1"],
297297
),
298+
#patch("charm.CharmConfig.instance_password_encryption", return_value="scram-sha-256")
298299
):
299300
_get_postgresql_version.return_value = "16.6"
300301

@@ -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+
instance_password_encryption="scram-sha-256",
334336
)
335337

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

0 commit comments

Comments
 (0)