Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An federation whitelist query endpoint extension #16848

Merged
merged 15 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
56 changes: 25 additions & 31 deletions docs/usage/configuration/config_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,31 @@ federation_domain_whitelist:
- syd.example.com
```
---
### `federation_whitelist_endpoint_enabled`

Enables an endpoint for fetching the federation whitelist config.

The request method and path is `GET /_synapse/client/config/federation_whitelist`, and the
response format is:
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved

```json
{
"whitelist_enabled": true, // Whether the federation whitelist is being enforced
"whitelist": [ // Which server names are allowed by the whitelist
"example.com"
]
}
```

If `whitelist_enabled` is `false` then the server is permitted to federate with all others.

The endpoint requires authentication.

Example configuration:
```yaml
federation_whitelist_endpoint_enabled: true
```
---
### `federation_metrics_domains`

Report prometheus metrics on the age of PDUs being sent to and received from
Expand Down Expand Up @@ -4546,34 +4571,3 @@ background_updates:
min_batch_size: 10
default_batch_size: 50
```


---
## Extension features
Configuration for extension features for Synapse

---
### `extension_federation_whitelist_endpoint`

Enables an endpoint for fetching the federation whitelist config.

The request method and path is `GET /_synapse/client/config/federation_whitelist`, and the
response format is:

```json
{
"whitelist_enabled": true, // Whether the federation whitelist is being enforced
"whitelist": [ // Which server names are allowed by the whitelist
"example.com"
]
}
```

If `whitelist_enabled` is `false` then the server is permitted to federate with all others.

The endpoint requires authentication.

Example configuration:
```yaml
extension_federation_whitelist_endpoint: true
```
2 changes: 0 additions & 2 deletions synapse/config/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ from synapse.config import ( # noqa: F401
database,
emailconfig,
experimental,
extensions,
federation,
jwt,
key,
Expand Down Expand Up @@ -121,7 +120,6 @@ class RootConfig:
federation: federation.FederationConfig
retention: retention.RetentionConfig
background_updates: background_updates.BackgroundUpdateConfig
extensions: extensions.ExtensionsConfig

config_classes: List[Type["Config"]] = ...
config_files: List[str]
Expand Down
29 changes: 0 additions & 29 deletions synapse/config/extensions.py

This file was deleted.

4 changes: 4 additions & 0 deletions synapse/config/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
for domain in federation_domain_whitelist:
self.federation_domain_whitelist[domain] = True

self.federation_whitelist_endpoint_enabled = config.get(
"federation_whitelist_endpoint_enabled", False
)

federation_metrics_domains = config.get("federation_metrics_domains") or []
validate_config(
_METRICS_FOR_DOMAINS_SCHEMA,
Expand Down
2 changes: 0 additions & 2 deletions synapse/config/homeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
from .database import DatabaseConfig
from .emailconfig import EmailConfig
from .experimental import ExperimentalConfig
from .extensions import ExtensionsConfig
from .federation import FederationConfig
from .jwt import JWTConfig
from .key import KeyConfig
Expand Down Expand Up @@ -106,5 +105,4 @@ class HomeServerConfig(RootConfig):
RedisConfig,
ExperimentalConfig,
BackgroundUpdateConfig,
ExtensionsConfig,
]
2 changes: 1 addition & 1 deletion synapse/rest/synapse/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def build_synapse_client_resource_tree(hs: "HomeServer") -> Mapping[str, Resourc
# To be removed in Synapse v1.32.0.
resources["/_matrix/saml2"] = res

if hs.config.extensions.federation_whitelist_endpoint:
if hs.config.federation.federation_whitelist_endpoint_enabled:
resources[FederationWhitelistResource.PATH] = FederationWhitelistResource(hs)

if hs.config.experimental.msc4108_enabled:
Expand Down
8 changes: 4 additions & 4 deletions tests/rest/synapse/client/test_federation_whitelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_default(self) -> None:

self.assertEqual(channel.code, 404)

@unittest.override_config({"extension_federation_whitelist_endpoint": True})
@unittest.override_config({"federation_whitelist_endpoint_enabled": True})
def test_no_auth(self) -> None:
"Endpoint requires auth when enabled"

Expand All @@ -51,7 +51,7 @@ def test_no_auth(self) -> None:

self.assertEqual(channel.code, 401)

@unittest.override_config({"extension_federation_whitelist_endpoint": True})
@unittest.override_config({"federation_whitelist_endpoint_enabled": True})
def test_no_whitelist(self) -> None:
"Test when there is no whitelist configured"

Expand All @@ -72,7 +72,7 @@ def test_no_whitelist(self) -> None:

@unittest.override_config(
{
"extension_federation_whitelist_endpoint": True,
"federation_whitelist_endpoint_enabled": True,
"federation_domain_whitelist": ["example.com"],
}
)
Expand All @@ -96,7 +96,7 @@ def test_whitelist(self) -> None:

@unittest.override_config(
{
"extension_federation_whitelist_endpoint": True,
"federation_whitelist_endpoint_enabled": True,
"federation_domain_whitelist": ["example.com", "example.com"],
}
)
Expand Down
Loading