Default generated logger config causes "Permission denied: '/homeserver.log'" for non-root containers #9970
Description
Description
Using generate
to create config files with the Docker image sets the value of handlers.file.filename
inside the *.log.config
file to /homeserver.log
, causing the following error when running the container as non-root:
PermissionError: [Errno 13] Permission denied: '/homeserver.log'
Changing it to /data/homeserver.log
fixes the issue since the synapse
user has write access to that folder.
Unfortunately it's not enough to disable the file
log handler
. Even when disabled an empty log file is initially created.
Steps to reproduce
- Create minimal config files with
generate
- Run container in non-root mode
Version information
If not matrix.org:
-
Version: v1.33.1
-
Install method: Docker Image
-
Platform: Kubernetes
Cause
The issue lies within how the log config is generated (https://github.com/matrix-org/synapse/blob/develop/synapse/config/logger.py#L171-L180):
def generate_files(self, config, config_dir_path):
log_config = config.get("log_config")
if log_config and not os.path.exists(log_config):
log_file = self.abspath("homeserver.log")
print(
"Generating log config file %s which will log to %s"
% (log_config, log_file)
)
with open(log_config, "w") as log_config_file:
log_config_file.write(DEFAULT_LOG_CONFIG.substitute(log_file=log_file))
which calls:
@staticmethod
def abspath(file_path):
return os.path.abspath(file_path) if file_path else file_path
Since the container runs start.py
in /
, the above resolves to /homeserver.log