Fix permissions of out-of-PGDATA created postgresql.conf. (#3308)

Since 01d07f86c, the permissions of postgresql.conf created in PGDATA was
explicitly set. However, the umask of the Patroni process was adjusted as well
and as a result of this, Patroni would write postgresql.conf with 600
permissions if the configuration files are outside PGDATA.

Fix this by using the original umask as mode for files created outside PGDATA.

Fixes: #3302
This commit is contained in:
Michael Banck
2025-03-14 12:21:25 +01:00
committed by GitHub
parent 9977850b56
commit a3c772dfc9
+5 -2
View File
@@ -477,16 +477,19 @@ class ConfigHandler(object):
return configuration return configuration
def set_file_permissions(self, filename: str) -> None: def set_file_permissions(self, filename: str) -> None:
"""Set permissions of file *filename* according to the expected permissions if it resides under PGDATA. """Set permissions of file *filename* according to the expected permissions.
.. note:: .. note::
Do nothing if the file is not under PGDATA. Use original umask if the file is not under PGDATA, use PGDATA
permissions otherwise.
:param filename: path to a file which permissions might need to be adjusted. :param filename: path to a file which permissions might need to be adjusted.
""" """
if is_subpath(self._postgresql.data_dir, filename): if is_subpath(self._postgresql.data_dir, filename):
pg_perm.set_permissions_from_data_directory(self._postgresql.data_dir) pg_perm.set_permissions_from_data_directory(self._postgresql.data_dir)
os.chmod(filename, pg_perm.file_create_mode) os.chmod(filename, pg_perm.file_create_mode)
else:
os.chmod(filename, 0o666 & ~pg_perm.orig_umask)
@contextmanager @contextmanager
def config_writer(self, filename: str) -> Iterator[ConfigWriter]: def config_writer(self, filename: str) -> Iterator[ConfigWriter]: