-
Notifications
You must be signed in to change notification settings - Fork 411
An federation whitelist query endpoint extension #16848
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
Changes from 1 commit
1d03cfa
8653451
d4c1270
b79f8e4
264746c
da1b7b9
2ec7a55
d9aa8a9
1829e4a
a70d14f
77bd7b2
75a3ec2
320fb3e
e3794ad
a75e5b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||
| # | ||||
| # This file is licensed under the Affero General Public License (AGPL) version 3. | ||||
| # | ||||
| # Copyright (C) 2023 New Vector, Ltd | ||||
| # | ||||
| # This program is free software: you can redistribute it and/or modify | ||||
| # it under the terms of the GNU Affero General Public License as | ||||
| # published by the Free Software Foundation, either version 3 of the | ||||
| # License, or (at your option) any later version. | ||||
| # | ||||
| # See the GNU Affero General Public License for more details: | ||||
| # <https://www.gnu.org/licenses/agpl-3.0.html>. | ||||
| # | ||||
|
|
||||
| from typing import Any | ||||
|
|
||||
| from synapse.config._base import Config | ||||
| from synapse.types import JsonDict | ||||
|
|
||||
|
|
||||
| class ExtensionsConfig(Config): | ||||
| """Config section for enabling extension features""" | ||||
|
|
||||
| section = "extensions" | ||||
|
|
||||
| def read_config(self, config: JsonDict, **kwargs: Any) -> None: | ||||
| self.federation_whitelist_endpoint: bool = config.get( | ||||
|
||||
| class FederationConfig(Config): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be beneficial to follow the approach mentioned here: #17147 (comment)
ie. to move this to an in-tree-module and have the config follow the normal module config rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approach mentioned in that PR was deemed undesirable for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But would it not fit under "federation"?
On this, @erikjohnston wrote on Matrix:
Yeah, maybe. I suppose the federation section is relatively small. I'm just thinking of what this will look like if we have e.g. 10 optional features like this, and whether we'd want them grouped together in one place in the docs or not
and whether its clearer in the code or not
I suppose we can cross that bridge when we come to it
I don't see this as an optional feature, more a config option like any other. And they won't end up all under federation of course, but spread across the config. I don't think they'll build up in any noticeable way as a group.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I'll move it under the federation section.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # | ||
| # This file is licensed under the Affero General Public License (AGPL) version 3. | ||
| # | ||
| # Copyright (C) 2024 New Vector, Ltd | ||
| # | ||
| # This program is free software: you can redistribute it and/or modify | ||
| # it under the terms of the GNU Affero General Public License as | ||
| # published by the Free Software Foundation, either version 3 of the | ||
| # License, or (at your option) any later version. | ||
| # | ||
| # See the GNU Affero General Public License for more details: | ||
| # <https://www.gnu.org/licenses/agpl-3.0.html>. | ||
| # | ||
|
|
||
| import logging | ||
| from typing import TYPE_CHECKING, Tuple | ||
|
|
||
| from synapse.http.server import DirectServeJsonResource | ||
| from synapse.http.site import SynapseRequest | ||
| from synapse.types import JsonDict | ||
|
|
||
| if TYPE_CHECKING: | ||
| from synapse.server import HomeServer | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class FederationWhitelistResource(DirectServeJsonResource): | ||
| """Custom endpoint (disabled by default) to fetch the federation whitelist | ||
| config. | ||
|
|
||
| Only enabled if `federation_whitelist_endpoint` extension feature is | ||
| enabled. | ||
devonh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Response format: | ||
|
|
||
| { | ||
| "whitelist_enabled": true, // Whether there is a federation whitelist | ||
| "whitelist": [ // Which hosts are allowed by the whitelist | ||
| "example.com" | ||
| ] | ||
| } | ||
| """ | ||
|
|
||
| PATH = "/_synapse/client/config/federation_whitelist" | ||
|
|
||
| def __init__(self, hs: "HomeServer"): | ||
| super().__init__() | ||
|
|
||
| self._federation_whitelist = hs.config.federation.federation_domain_whitelist | ||
|
|
||
| self._auth = hs.get_auth() | ||
|
|
||
| async def _async_render_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]: | ||
| await self._auth.get_user_by_req(request) | ||
|
|
||
| whitelist = [] | ||
| if self._federation_whitelist: | ||
| # federation_whitelist is actually a dict, not a list | ||
| whitelist = list(self._federation_whitelist) | ||
|
|
||
| return_dict: JsonDict = { | ||
| "whitelist_enabled": self._federation_whitelist is not None, | ||
| "whitelist": whitelist, | ||
| } | ||
|
|
||
| return 200, return_dict | ||
Uh oh!
There was an error while loading. Please reload this page.