From 1bcc2b5fa6875157da1385458818d45348fc3957 Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Mon, 1 Jun 2015 16:05:35 +0200 Subject: [PATCH] Extend postgres?.yml with pg_hba section to give possibility to customize pg_hba.conf --- helpers/postgresql.py | 4 ++++ postgres0.yml | 11 +++++++++++ postgres1.yml | 11 +++++++++++ tests/test_postgresql.py | 3 +++ 4 files changed, 29 insertions(+) diff --git a/helpers/postgresql.py b/helpers/postgresql.py index 7677c6c4..58038788 100644 --- a/helpers/postgresql.py +++ b/helpers/postgresql.py @@ -199,6 +199,10 @@ class Postgresql: def write_pg_hba(self): with open(os.path.join(self.data_dir, 'pg_hba.conf'), 'a') as f: f.write('\nhost replication {username} {network} md5\n'.format(**self.replication)) + for line in self.config.get('pg_hba', []): + if line['type'] == 'hostssl' and self.config['parameters'].get('ssl', 'off').lower() != 'on': + continue + f.write('{type} {database} {user} {address} {method}\n'. format(**line)) @staticmethod def primary_conninfo(leader_url): diff --git a/postgres0.yml b/postgres0.yml index 8757538f..7c1c8dbf 100644 --- a/postgres0.yml +++ b/postgres0.yml @@ -12,6 +12,17 @@ postgresql: connect_address: 127.0.0.1:5432 data_dir: data/postgresql0 maximum_lag_on_failover: 1048576 # 1 megabyte in bytes + pg_hba: + - type: host + database: all + user: all + address: 0.0.0.0/0 + method: md5 + - type: hostssl + database: all + user: all + address: 0.0.0.0/0 + method: md5 replication: username: replicator password: rep-pass diff --git a/postgres1.yml b/postgres1.yml index a0afe20f..2e6edf33 100644 --- a/postgres1.yml +++ b/postgres1.yml @@ -12,6 +12,17 @@ postgresql: connect_address: 127.0.0.1:5433 data_dir: data/postgresql1 maximum_lag_on_failover: 1048576 # 1 megabyte in bytes + pg_hba: + - type: host + database: all + user: all + address: 0.0.0.0/0 + method: md5 + - type: hostssl + database: all + user: all + address: 0.0.0.0/0 + method: md5 replication: username: replicator password: rep-pass diff --git a/tests/test_postgresql.py b/tests/test_postgresql.py index f0b04904..4fcec552 100644 --- a/tests/test_postgresql.py +++ b/tests/test_postgresql.py @@ -93,6 +93,9 @@ class TestPostgresql(unittest.TestCase): subprocess.call = subprocess_call self.p = Postgresql({'name': 'test0', 'data_dir': 'data/test0', 'listen': '127.0.0.1, 127.0.0.2:5432', 'connect_address': '127.0.0.2:5432', + 'pg_hba': [{'type': 'hostssl', 'database': 'all', 'user': 'all', 'address': '0.0.0.0/0', + 'method': 'md5'}, {'type': 'host', 'database': 'all', 'user': 'all', + 'address': '0.0.0.0/0', 'method': 'md5'}], 'replication': {'username': 'replicator', 'password': 'rep-pass', 'network': '127.0.0.1/32'},