mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Remove pg_hba injection and filtering
Previously we explicitly injected a replication record into pg_hba.conf. This doesn't allow users to explicitly write their configurations. This change will just write the lines specified by the user.
This commit is contained in:
@@ -446,11 +446,7 @@ class Postgresql(object):
|
|||||||
|
|
||||||
def write_pg_hba(self):
|
def write_pg_hba(self):
|
||||||
with open(os.path.join(self.data_dir, 'pg_hba.conf'), 'a') as f:
|
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))
|
f.write('\n{}\n'.format('\n'.join(self.config.get('pg_hba', []))))
|
||||||
for line in self.config.get('pg_hba', []):
|
|
||||||
if line.split()[0].strip() == 'hostssl' and self.server_parameters.get('ssl', 'off').lower() != 'on':
|
|
||||||
continue
|
|
||||||
f.write(line + '\n')
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def primary_conninfo(leader_url):
|
def primary_conninfo(leader_url):
|
||||||
|
|||||||
+2
-2
@@ -56,12 +56,12 @@ postgresql:
|
|||||||
username: postgres
|
username: postgres
|
||||||
password: zalando
|
password: zalando
|
||||||
pg_hba:
|
pg_hba:
|
||||||
|
- host replication replicator 127.0.0.1/32 md5
|
||||||
- host all all 0.0.0.0/0 md5
|
- host all all 0.0.0.0/0 md5
|
||||||
- hostssl all all 0.0.0.0/0 md5
|
# - hostssl all all 0.0.0.0/0 md5
|
||||||
replication:
|
replication:
|
||||||
username: replicator
|
username: replicator
|
||||||
password: rep-pass
|
password: rep-pass
|
||||||
network: 127.0.0.1/32
|
|
||||||
superuser:
|
superuser:
|
||||||
username: postgres
|
username: postgres
|
||||||
password: zalando
|
password: zalando
|
||||||
|
|||||||
+2
-2
@@ -56,12 +56,12 @@ postgresql:
|
|||||||
username: postgres
|
username: postgres
|
||||||
password: zalando
|
password: zalando
|
||||||
pg_hba:
|
pg_hba:
|
||||||
|
- host replication replicator 127.0.0.1/32 md5
|
||||||
- host all all 0.0.0.0/0 md5
|
- host all all 0.0.0.0/0 md5
|
||||||
- hostssl all all 0.0.0.0/0 md5
|
# - hostssl all all 0.0.0.0/0 md5
|
||||||
replication:
|
replication:
|
||||||
username: replicator
|
username: replicator
|
||||||
password: rep-pass
|
password: rep-pass
|
||||||
network: 127.0.0.1/32
|
|
||||||
superuser:
|
superuser:
|
||||||
username: postgres
|
username: postgres
|
||||||
password: zalando
|
password: zalando
|
||||||
|
|||||||
+2
-2
@@ -56,12 +56,12 @@ postgresql:
|
|||||||
username: postgres
|
username: postgres
|
||||||
password: zalando
|
password: zalando
|
||||||
pg_hba:
|
pg_hba:
|
||||||
|
- host replication replicator 127.0.0.1/32 md5
|
||||||
- host all all 0.0.0.0/0 md5
|
- host all all 0.0.0.0/0 md5
|
||||||
- hostssl all all 0.0.0.0/0 md5
|
# - hostssl all all 0.0.0.0/0 md5
|
||||||
replication:
|
replication:
|
||||||
username: replicator
|
username: replicator
|
||||||
password: rep-pass
|
password: rep-pass
|
||||||
network: 127.0.0.1/32
|
|
||||||
superuser:
|
superuser:
|
||||||
username: postgres
|
username: postgres
|
||||||
password: zalando
|
password: zalando
|
||||||
|
|||||||
@@ -164,13 +164,14 @@ class TestPostgresql(unittest.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.p = Postgresql({'name': 'test0', 'scope': 'batman', 'data_dir': 'data/test0',
|
self.p = Postgresql({'name': 'test0', 'scope': 'batman', 'data_dir': 'data/test0',
|
||||||
'listen': '127.0.0.1, *:5432', 'connect_address': '127.0.0.2:5432',
|
'listen': '127.0.0.1, *:5432', 'connect_address': '127.0.0.2:5432',
|
||||||
'pg_hba': ['hostssl all all 0.0.0.0/0 md5', 'host all all 0.0.0.0/0 md5'],
|
'pg_hba': ['host replication replicator 127.0.0.1/32 md5',
|
||||||
|
'hostssl all all 0.0.0.0/0 md5',
|
||||||
|
'host all all 0.0.0.0/0 md5'],
|
||||||
'superuser': {'username': 'test', 'password': 'test'},
|
'superuser': {'username': 'test', 'password': 'test'},
|
||||||
'admin': {'username': 'admin', 'password': 'admin'},
|
'admin': {'username': 'admin', 'password': 'admin'},
|
||||||
'pg_rewind': {'username': 'admin', 'password': 'admin'},
|
'pg_rewind': {'username': 'admin', 'password': 'admin'},
|
||||||
'replication': {'username': 'replicator',
|
'replication': {'username': 'replicator',
|
||||||
'password': 'rep-pass',
|
'password': 'rep-pass'},
|
||||||
'network': '127.0.0.1/32'},
|
|
||||||
'parameters': {'foo': 'bar'}, 'recovery_conf': {'foo': 'bar'},
|
'parameters': {'foo': 'bar'}, 'recovery_conf': {'foo': 'bar'},
|
||||||
'callbacks': {'on_start': 'true', 'on_stop': 'true',
|
'callbacks': {'on_start': 'true', 'on_stop': 'true',
|
||||||
'on_restart': 'true', 'on_role_change': 'true',
|
'on_restart': 'true', 'on_role_change': 'true',
|
||||||
@@ -205,6 +206,11 @@ class TestPostgresql(unittest.TestCase):
|
|||||||
self.assertTrue(self.p.initialize())
|
self.assertTrue(self.p.initialize())
|
||||||
self.assertTrue(os.path.exists(os.path.join(self.p.data_dir, 'pg_hba.conf')))
|
self.assertTrue(os.path.exists(os.path.join(self.p.data_dir, 'pg_hba.conf')))
|
||||||
|
|
||||||
|
with open(os.path.join(self.p.data_dir, 'pg_hba.conf')) as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
assert 'host replication replicator 127.0.0.1/32 md5\n' in lines
|
||||||
|
assert 'host all all 0.0.0.0/0 md5\n' in lines
|
||||||
|
|
||||||
@patch('os.path.exists', Mock(return_value=True))
|
@patch('os.path.exists', Mock(return_value=True))
|
||||||
@patch('os.unlink', Mock())
|
@patch('os.unlink', Mock())
|
||||||
def test_delete_trigger_file(self):
|
def test_delete_trigger_file(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user