]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2064] hammer.py: ensure postgres entry in hba
authorAndrei Pavel <andrei.pavel@mail.com>
Mon, 6 Sep 2021 17:28:26 +0000 (20:28 +0300)
committerAndrei Pavel <andrei.pavel@mail.com>
Mon, 6 Sep 2021 17:28:26 +0000 (20:28 +0300)
hammer.py

index c8a23c5fef54ef1670cf70c95abda4e11be4f0b2..db344097fc8aa6c99b7be9a454454486151a091b 100755 (executable)
--- a/hammer.py
+++ b/hammer.py
@@ -1208,6 +1208,14 @@ def _configure_pgsql(system, features):
     _change_postgresql_auth_method('host', 'md5', hba_file)
     _change_postgresql_auth_method('local', 'md5', hba_file)
 
+    # Make sure hba file has a postgres superuser entry. It needs to be placed
+    # before any other local auth method for higher priority. Let's simulate
+    # that by putting it just after the auth header.
+    if 0 != execute("sudo cat {} | grep -E '^local.*all.*postgres'".format(hba_file), raise_error=False):
+        auth_header='# TYPE  DATABASE        USER            ADDRESS                 METHOD'
+        postgres_auth_line='local   all             postgres                                ident'
+        execute("sudo sed -i.bak '/{}/a {}' '{}'".format(auth_header, postgres_auth_line, hba_file))
+
     _restart_postgresql(system)
 
     cmd = """bash -c \"cat <<EOF | sudo -u postgres psql postgres