From 1229cf2c16e4c46a410dad985b7262a326414e15 Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Fri, 5 Jun 2020 09:33:50 +0200 Subject: [PATCH] Ignore hba_file and ident_file when they match with defaults (#1555) It is possible to specify custom hba_file and ident_file in the postgresql configuration parameters and Patroni is considering that these files are managed externally. It could happen that locations of these files matching with default locations of pg_hba,conf and pg_ident.conf. In this case we will ignore custom values and fallback to the default workflow, i.e. Patroni will overwrite them. Close: https://github.com/zalando/patroni/issues/1544 --- patroni/postgresql/bootstrap.py | 2 +- patroni/postgresql/config.py | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/patroni/postgresql/bootstrap.py b/patroni/postgresql/bootstrap.py index 5af95bdb..01608adc 100644 --- a/patroni/postgresql/bootstrap.py +++ b/patroni/postgresql/bootstrap.py @@ -363,7 +363,7 @@ END;$$""".format(f, rewind['username']) # at this point there should be no recovery.conf postgresql.config.remove_recovery_conf() - if postgresql.config.hba_file and postgresql.config.hba_file != postgresql.config.pg_hba_conf: + if postgresql.config.hba_file: postgresql.restart() else: postgresql.config.replace_pg_hba() diff --git a/patroni/postgresql/config.py b/patroni/postgresql/config.py index 2e16e1e4..0225a9bd 100644 --- a/patroni/postgresql/config.py +++ b/patroni/postgresql/config.py @@ -376,7 +376,7 @@ class ConfigHandler(object): configuration.append(os.path.basename(self._postgresql_base_conf_name)) if not self.hba_file: configuration.append('pg_hba.conf') - if not self._server_parameters.get('ident_file'): + if not self.ident_file: configuration.append('pg_ident.conf') return configuration @@ -483,7 +483,7 @@ class ConfigHandler(object): :returns: True if pg_ident.conf was rewritten. """ - if not self._server_parameters.get('ident_file') and self._config.get('pg_ident'): + if not self.ident_file and self._config.get('pg_ident'): with ConfigWriter(self._pg_ident_conf) as f: f.writelines(self._config['pg_ident']) return True @@ -963,10 +963,12 @@ class ConfigHandler(object): logger.warning('Removing invalid parameter `%s` from postgresql.parameters', param) server_parameters.pop(param) - if not server_parameters.get('hba_file') and config.get('pg_hba'): + if (not server_parameters.get('hba_file') or server_parameters['hba_file'] == self._pg_hba_conf) \ + and config.get('pg_hba'): hba_changed = self._config.get('pg_hba', []) != config['pg_hba'] - if not server_parameters.get('ident_file') and config.get('pg_ident'): + if (not server_parameters.get('ident_file') or server_parameters['ident_file'] == self._pg_hba_conf) \ + and config.get('pg_ident'): ident_changed = self._config.get('pg_ident', []) != config['pg_ident'] self._config = config @@ -1073,9 +1075,15 @@ class ConfigHandler(object): return self._config['authentication'].get('rewind', self._superuser) \ if self._postgresql.major_version >= 110000 else self._superuser + @property + def ident_file(self): + ident_file = self._server_parameters.get('ident_file') + return None if ident_file == self._pg_ident_conf else ident_file + @property def hba_file(self): - return self._server_parameters.get('hba_file') + hba_file = self._server_parameters.get('hba_file') + return None if hba_file == self._pg_hba_conf else hba_file @property def pg_hba_conf(self):