This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Re-introduce the outbound federation proxy #15913
Merged
erikjohnston
merged 13 commits into
develop
from
madlittlemods/outbound-federation-proxy
Jul 18, 2023
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7ad4cfc
Federation outbound proxy (#15773)
MadLittleMods 06107b8
Update changelog
MadLittleMods f067e6a
Fix TLS when using the `ProxyAgent`
MadLittleMods 4c17080
Add slightly better representation than built-in
MadLittleMods 1ac93f3
Merge branch 'develop' into madlittlemods/outbound-federation-proxy
MadLittleMods e127596
Add Unix socket support to the proxyagent
realtyem cb7c73e
Add authentication when proxying outbound federation traffic through …
MadLittleMods cbb536f
Add wrong authentication tests
MadLittleMods a7131bf
Remove comment that was copy pasted from above around `pool_key`
MadLittleMods 6823d77
Better error handling
MadLittleMods a41d9d9
Rewrap docs
MadLittleMods 2183969
Document `worker_replication_secret` requirement
MadLittleMods 4e49e66
Fix broken link in docs
MadLittleMods File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Allow configuring the set of workers to proxy outbound federation traffic through via `outbound_federation_restricted_to`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
|
||
import argparse | ||
import logging | ||
from typing import Any, Dict, List, Union | ||
from typing import Any, Dict, List, Optional, Union | ||
|
||
import attr | ||
from pydantic import BaseModel, Extra, StrictBool, StrictInt, StrictStr | ||
|
@@ -171,6 +171,27 @@ class WriterLocations: | |
) | ||
|
||
|
||
@attr.s(auto_attribs=True) | ||
class OutboundFederationRestrictedTo: | ||
"""Whether we limit outbound federation to a certain set of instances. | ||
|
||
Attributes: | ||
instances: optional list of instances that can make outbound federation | ||
requests. If None then all instances can make federation requests. | ||
locations: list of instance locations to connect to proxy via. | ||
""" | ||
|
||
instances: Optional[List[str]] | ||
locations: List[InstanceLocationConfig] = attr.Factory(list) | ||
|
||
def __contains__(self, instance: str) -> bool: | ||
# It feels a bit dirty to return `True` if `instances` is `None`, but it makes | ||
# sense in downstream usage in the sense that if | ||
# `outbound_federation_restricted_to` is not configured, then any instance can | ||
# talk to federation (no restrictions so always return `True`). | ||
return self.instances is None or instance in self.instances | ||
|
||
|
||
class WorkerConfig(Config): | ||
"""The workers are processes run separately to the main synapse process. | ||
They have their own pid_file and listener configuration. They use the | ||
|
@@ -385,6 +406,28 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None: | |
new_option_name="update_user_directory_from_worker", | ||
) | ||
|
||
outbound_federation_restricted_to = config.get( | ||
"outbound_federation_restricted_to", None | ||
) | ||
self.outbound_federation_restricted_to = OutboundFederationRestrictedTo( | ||
outbound_federation_restricted_to | ||
) | ||
if outbound_federation_restricted_to: | ||
if not self.worker_replication_secret: | ||
raise ConfigError( | ||
"`worker_replication_secret` must be configured when using `outbound_federation_restricted_to`." | ||
) | ||
Comment on lines
+416
to
+419
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we okay with re-using |
||
|
||
for instance in outbound_federation_restricted_to: | ||
if instance not in self.instance_map: | ||
raise ConfigError( | ||
"Instance %r is configured in 'outbound_federation_restricted_to' but does not appear in `instance_map` config." | ||
% (instance,) | ||
) | ||
self.outbound_federation_restricted_to.locations.append( | ||
self.instance_map[instance] | ||
) | ||
|
||
def _should_this_worker_perform_duty( | ||
self, | ||
config: Dict[str, Any], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For reviewers, here are all the new changes that are different from the original PR -> https://github.com/matrix-org/synapse/pull/15913/files/7ad4cfc6a056f42a884803072cd0440db07bdc69..4e49e661577ea4d0caf55a159df119d304121215. At the top in the PR description, there is a section that describes the "Details of the additional fixes in the re-introduction PR"
If you're looking for context/discussion on any previous code, #15773 might have some answers.