Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Default generated logger config causes "Permission denied: '/homeserver.log'" for non-root containers #9970

Closed
@schnerring

Description

@schnerring

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-DockerDocker images, or making it easier to run Synapse in a container.T-TaskRefactoring, removal, replacement, enabling or disabling functionality, other engineering tasks.X-Needs-InfoThis issue is blocked awaiting information from the reporter

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions