Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/18090.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `form_secret_path` config option.
16 changes: 16 additions & 0 deletions docs/usage/configuration/config_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -3238,6 +3238,22 @@ Example configuration:
```yaml
form_secret: <PRIVATE STRING>
```
---
### `form_secret_path`

An alternative to [`form_secret`](#form_secret):
allows the secret to be specified in an external file.

The file should be a plain text file, containing only the secret.
Synapse reads the secret from the given file once at startup.

Example configuration:
```yaml
form_secret_path: /path/to/secrets/file
```

_Added in Synapse 1.125.0._

---
## Signing Keys
Config options relating to signing keys
Expand Down
16 changes: 14 additions & 2 deletions synapse/config/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
both defined in config file.
"""

CONFLICTING_FORM_SECRET_OPTS_ERROR = """\
Conflicting options 'form_secret' and 'form_secret_path' are both defined in
config file.
"""

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -201,12 +206,19 @@ def read_config(

# a secret which is used to calculate HMACs for form values, to stop
# falsification of values
self.form_secret = config.get("form_secret", None)
if self.form_secret and not allow_secrets_in_config:
form_secret = config.get("form_secret", None)
if form_secret and not allow_secrets_in_config:
raise ConfigError(
"Config options that expect an in-line secret as value are disabled",
("form_secret",),
)
form_secret_path = config.get("form_secret_path", None)
if form_secret_path:
if form_secret:
raise ConfigError(CONFLICTING_FORM_SECRET_OPTS_ERROR)
self.form_secret = read_file(form_secret_path, "form_secret_path").strip()
else:
self.form_secret = form_secret

def generate_config_section(
self,
Expand Down
7 changes: 6 additions & 1 deletion tests/config/test_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def test_depreciated_identity_server_flag_throws_error(self) -> None:
"turn_shared_secret_path: /does/not/exist",
"registration_shared_secret_path: /does/not/exist",
"macaroon_secret_key_path: /does/not/exist",
"form_secret_path: /does/not/exist",
"experimental_features:\n msc3861:\n client_secret_path: /does/not/exist",
"experimental_features:\n msc3861:\n admin_token_path: /does/not/exist",
*["redis:\n enabled: true\n password_path: /does/not/exist"]
Expand Down Expand Up @@ -165,6 +166,10 @@ def test_secret_files_missing(self, config_str: str) -> None:
"macaroon_secret_key_path: {}",
lambda c: c.key.macaroon_secret_key,
),
(
"form_secret_path: {}",
lambda c: c.key.form_secret.encode("utf-8"),
),
(
"experimental_features:\n msc3861:\n client_secret_path: {}",
lambda c: c.experimental.msc3861.client_secret().encode("utf-8"),
Expand All @@ -186,7 +191,7 @@ def test_secret_files_existing(
self, config_line: str, get_secret: Callable[[RootConfig], str]
) -> None:
self.generate_config_and_remove_lines_containing(
["registration_shared_secret", "macaroon_secret_key"]
["form_secret", "macaroon_secret_key", "registration_shared_secret"]
)
with tempfile.NamedTemporaryFile(buffering=0) as secret_file:
secret_file.write(b"53C237")
Expand Down