Implement support of log.mode. (#3122)

There was one oversight of #2781 - to influence external tools that Patroni could execute, we set global `umask` value based on permissions of the $PGDATA directory. As a result, it also influenced permissions of log files created by Patroni.

To address the problem we implement two measures:
1. Make `log.mode` configurable.
2. If the value is not set - calculate permissions from the original value of the umask setting.
This commit is contained in:
Alexander Kukushkin
2024-08-13 08:11:28 +02:00
committed by GitHub
parent b458bd992a
commit 56dba93c55
9 changed files with 67 additions and 13 deletions
+2
View File
@@ -38,6 +38,7 @@ class TestConfig(unittest.TestCase):
'PATRONI_LOG_FORMAT': '["message", {"levelname": "level"}]',
'PATRONI_LOG_LOGGERS': 'patroni.postmaster: WARNING, urllib3: DEBUG',
'PATRONI_LOG_FILE_NUM': '5',
'PATRONI_LOG_MODE': '0123',
'PATRONI_CITUS_DATABASE': 'citus',
'PATRONI_CITUS_GROUP': '0',
'PATRONI_CITUS_HOST': '0',
@@ -81,6 +82,7 @@ class TestConfig(unittest.TestCase):
'PATRONI_POSTGRESQL_BIN_POSTGRES': 'sergtsop'
})
config = Config('postgres0.yml')
self.assertEqual(config.local_configuration['log']['mode'], 0o123)
with patch.object(Config, '_load_config_file', Mock(return_value={'restapi': {}})):
with patch.object(Config, '_build_effective_configuration', Mock(side_effect=Exception)):
config.reload_local_configuration()
+3
View File
@@ -30,3 +30,6 @@ class TestFilePermissions(unittest.TestCase):
def test_set_permissions_from_data_directory(self, mock_logger):
pg_perm.set_permissions_from_data_directory('test')
self.assertEqual(mock_logger.call_args[0][0], 'Can not check permissions on %s: %r')
def test_orig_umask(self):
self.assertIsNotNone(pg_perm.orig_umask)
+4 -1
View File
@@ -38,6 +38,7 @@ class TestPatroniLogger(unittest.TestCase):
'traceback_level': 'DEBUG',
'max_queue_size': 5,
'dir': 'foo',
'mode': 0o600,
'file_size': 4096,
'file_num': 5,
'loggers': {
@@ -50,7 +51,9 @@ class TestPatroniLogger(unittest.TestCase):
os.environ[Config.PATRONI_CONFIG_VARIABLE] = yaml.dump(config, default_flow_style=False)
logger = PatroniLogger()
patroni_config = Config(None)
logger.reload_config(patroni_config['log'])
with patch('os.chmod') as mock_chmod:
logger.reload_config(patroni_config['log'])
self.assertEqual(mock_chmod.call_args[0][1], 0o600)
_LOG.exception('test')
logger.start()