From d28958428aa3a27d0205fe61a3d88e198543a48c Mon Sep 17 00:00:00 2001 From: Mike Tonks Date: Fri, 24 Jul 2015 16:03:04 +0100 Subject: [PATCH] Adds pg_hba.conf template support --- governor.py | 1 + helpers/postgresql.py | 13 +++++++++++-- pg_hba.conf | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 pg_hba.conf diff --git a/governor.py b/governor.py index 61dd2fb3..7db36b6b 100755 --- a/governor.py +++ b/governor.py @@ -110,6 +110,7 @@ def shutdown(): time.sleep(5) else: logging.info("Governor Starting up: Existing Data Dir") + postgresql.copy_pg_hba() postgresql.follow_no_leader() logging.info("Governor Starting up: Starting Postgres") postgresql.start(master=False) diff --git a/helpers/postgresql.py b/helpers/postgresql.py index 40714229..b1adb2ed 100644 --- a/helpers/postgresql.py +++ b/helpers/postgresql.py @@ -1,4 +1,4 @@ -import os, psycopg2, re, time +import os, psycopg2, re, time, shutil import logging from urlparse import urlparse @@ -69,7 +69,8 @@ def data_directory_empty(self): def initialize(self): if os.system("initdb -D %s" % self.data_dir) == 0: - self.write_pg_hba() + #self.write_pg_hba() + self.copy_pg_hba() self.start() self.create_replication_user() self.stop() @@ -191,6 +192,14 @@ def write_pg_hba(self): {"username": self.replication["username"], "network": self.replication["network"]}) f.close() + def copy_pg_hba(self): + if os.path.exists('pg_hba.conf'): + logger.info("Copying pg_hba.conf file") + shutil.copy2('pg_hba.conf', self.data_dir) + else: + logger.info("No pg_hba.conf file found - skipping") + + def write_recovery_conf(self, leader_hash): f = open("%s/recovery.conf" % self.data_dir, "w") f.write(""" diff --git a/pg_hba.conf b/pg_hba.conf new file mode 100644 index 00000000..fa744919 --- /dev/null +++ b/pg_hba.conf @@ -0,0 +1,14 @@ +# TYPE DATABASE USER ADDRESS METHOD + +# "local" is for Unix domain socket connections only +local all all trust +# IPv4 local connections: +host all all 127.0.0.1/32 trust +# IPv6 local connections: +host all all ::1/128 trust + +# Replication user +host replication replicator 10.0.3.1/24 md5 + +# Application users with md5 password +host all all 10.0.3.1/24 md5