]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2064] hammer: don't modify postgres entry in hba
authorAndrei Pavel <andrei@isc.org>
Fri, 3 Sep 2021 12:00:03 +0000 (15:00 +0300)
committerAndrei Pavel <andrei@isc.org>
Mon, 6 Sep 2021 13:56:32 +0000 (13:56 +0000)
doc/devel/unit-tests.dox
hammer.py

index a87b56c9cee4932861ae5d8256b93099892f65b4..f49bb49934f676addbfb8db074963f878b934b95 100644 (file)
@@ -298,7 +298,7 @@ keatest=>
   <tt>/var/lib/postgresql/data/pg_hba.conf</tt> or at
   <tt>/etc/postgresql/${version}/main/pg_hba.conf</tt>, but you can find out
   for sure by running
-  <tt>printf 'SHOW hba_file' | sudo -u postgres psql -t postgres</tt>. Make sure
+  <tt>sudo -u postgres psql -t -c 'SHOW hba_file'</tt>. Make sure
   that all the authentication methods are changed to "md5" like this:
 
 @verbatim
index fbb3a204df8732685801fe778ff04bd4103801b2..4a515ac0c609999c3aaf6ca015ea41ba3c88c7cf 100755 (executable)
--- a/hammer.py
+++ b/hammer.py
@@ -1163,8 +1163,12 @@ def _restart_postgresql(system):
         execute('sudo systemctl restart postgresql.service')
 
 
+# Change authentication type for given connection type. Usual inputs for
+# connection type are 'host' or 'local'. Only affects entries with database
+# and user both set to 'all'. This is to not affect authentication of
+# `postgres` user which should have a separate entry.
 def _change_postgresql_auth_method(connection_type, auth_method, hba_file):
-    execute("sudo sed -i.bak 's/^{}\(.*\) [a-z0-9]*$/{}\\1 {}/g' '{}'".format(
+    execute("sudo sed -i.bak 's/^{}\(.*\)all\(.*\)all\(.*\) [a-z0-9]*$/{}\\1all\\2all\\3 {}/g' '{}'".format(
         connection_type, connection_type, auth_method, hba_file), cwd='/tmp')
 
 
@@ -1193,6 +1197,15 @@ def _configure_pgsql(system, features):
     _enable_postgresql(system)
     _restart_postgresql(system)
 
+    # Change auth-method to 'md5' on all connections.
+    cmd = "sudo -u postgres psql -t -c 'SHOW hba_file' | xargs"
+    _, output = execute(cmd, capture=True, cwd='/tmp')
+    hba_file = output.rstrip()
+    _change_postgresql_auth_method('host', 'md5', hba_file)
+    _change_postgresql_auth_method('local', 'md5', hba_file)
+
+    _restart_postgresql(system)
+
     cmd = """bash -c \"cat <<EOF | sudo -u postgres psql postgres
         DROP DATABASE IF EXISTS keatest;
         DROP USER IF EXISTS keatest;
@@ -1222,15 +1235,6 @@ def _configure_pgsql(system, features):
         cmd += "EOF\n\""
         execute(cmd, cwd='/tmp')
 
-    # Change auth-method to 'md5' on all connections.
-    cmd = "printf 'SHOW hba_file' | sudo -u postgres psql -t postgres | xargs"
-    _, output = execute(cmd, capture=True, cwd='/tmp')
-    hba_file = output.rstrip()
-    _change_postgresql_auth_method('host', 'md5', hba_file)
-    _change_postgresql_auth_method('local', 'md5', hba_file)
-
-    _restart_postgresql(system)
-
     log.info('postgresql just configured')