Skip to content

Commit

Permalink
Add config option redis.password_path
Browse files Browse the repository at this point in the history
  • Loading branch information
V02460 committed Sep 16, 2024
1 parent 8de3283 commit 26f57af
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/17717.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add config option `redis.password_path`.
8 changes: 7 additions & 1 deletion docs/usage/configuration/config_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4359,6 +4359,9 @@ This setting has the following sub-options:
* `path`: The full path to a local Unix socket file. **If this is used, `host` and
`port` are ignored.** Defaults to `/tmp/redis.sock'
* `password`: Optional password if configured on the Redis instance.
* `password_path`: Alternative to `password`, reading the password from an
external file. The file should be a plain text file, containing only the
password. Synapse reads the password from the given file once at startup.
* `dbid`: Optional redis dbid if needs to connect to specific redis logical db.
* `use_tls`: Whether to use tls connection. Defaults to false.
* `certificate_file`: Optional path to the certificate file
Expand All @@ -4372,13 +4375,16 @@ This setting has the following sub-options:

_Changed in Synapse 1.85.0: Added path option to use a local Unix socket_

_Changed in Synapse 1.116.0: Added password\_path_

Example configuration:
```yaml
redis:
enabled: true
host: localhost
port: 6379
password: <secret_password>
password_path: <path_to_the_password_file>
# OR password: <secret_password>
dbid: <dbid>
#use_tls: True
#certificate_file: <path_to_the_certificate_file>
Expand Down
18 changes: 17 additions & 1 deletion synapse/config/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@

from typing import Any

from synapse.config._base import Config
from synapse.config._base import Config, ConfigError, read_file
from synapse.types import JsonDict
from synapse.util.check_dependencies import check_requirements

CONFLICTING_PASSWORD_OPTS_ERROR = """\
You have configured both `redis.password` and `redis.password_path`.
These are mutually incompatible.
"""


class RedisConfig(Config):
section = "redis"
Expand All @@ -43,6 +48,17 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
self.redis_path = redis_config.get("path", None)
self.redis_dbid = redis_config.get("dbid", None)
self.redis_password = redis_config.get("password")
redis_password_path = redis_config.get("password_path")
if redis_password_path:
if self.redis_password:
raise ConfigError(CONFLICTING_PASSWORD_OPTS_ERROR)
self.redis_password = read_file(
redis_password_path,
(
"redis",
"password_path",
),
).strip()

self.redis_use_tls = redis_config.get("use_tls", False)
self.redis_certificate = redis_config.get("certificate_file", None)
Expand Down

0 comments on commit 26f57af

Please sign in to comment.