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
Ability to blacklist ip ranges for federation traffic #5043
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
1b8532b
tests fail
anoadragon453 4501489
tests pass
anoadragon453 0200c86
lint
anoadragon453 9f1f03f
lint and changelog
anoadragon453 6631485
actually add changelog
anoadragon453 25c99dc
sample config
anoadragon453 9795344
Don't raise an exception if coming from federation
anoadragon453 1b3989b
lint
anoadragon453 0e2f8ca
Add some notes
anoadragon453 6479cd5
Use an empty list as default
anoadragon453 3f4f931
Merge branch 'develop' into anoa/blacklist_ip_ranges
anoadragon453 968ddca
Testing
anoadragon453 e1feb45
We can't throw exceptions in an IResolutionReceiver
richvdh 152d7a8
Remove different behaviour for fed vs. nonfed
anoadragon453 6592691
Import at the top
anoadragon453 517794e
isort locally didn't have a problem >:(
anoadragon453 15d1802
lint
anoadragon453 131b9c0
yield deferred
anoadragon453 13f430c
Same behavior for no result and result blacklisted
anoadragon453 e2bc9af
lint
anoadragon453 ec67848
Remove yield
anoadragon453 43ffe47
Enable federation blacklisting by default
anoadragon453 aee810a
Fix tests and various small review issues
anoadragon453 a30a778
Update tests
anoadragon453 ede582f
lint
anoadragon453 4ba420f
always blacklist 0.0.0.0, ::
anoadragon453 358777d
lower pump value
anoadragon453 7f15dd7
lint
anoadragon453 6b29f7e
regen config
anoadragon453 e0715d0
Merge branch 'develop' into anoa/blacklist_ip_ranges
anoadragon453 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 @@ | ||
Add ability to blacklist IP ranges for the federation client. |
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 |
---|---|---|
|
@@ -17,6 +17,8 @@ | |
import logging | ||
import os.path | ||
|
||
from netaddr import IPSet | ||
|
||
from synapse.http.endpoint import parse_and_validate_server_name | ||
from synapse.python_dependencies import DependencyException, check_requirements | ||
|
||
|
@@ -137,6 +139,24 @@ def read_config(self, config): | |
for domain in federation_domain_whitelist: | ||
self.federation_domain_whitelist[domain] = True | ||
|
||
self.federation_ip_range_blacklist = config.get( | ||
"federation_ip_range_blacklist", [], | ||
) | ||
|
||
# Attempt to create an IPSet from the given ranges | ||
try: | ||
self.federation_ip_range_blacklist = IPSet( | ||
self.federation_ip_range_blacklist | ||
) | ||
|
||
# Always blacklist 0.0.0.0, :: | ||
self.federation_ip_range_blacklist.update(["0.0.0.0", "::"]) | ||
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. this could really have done with being outside the try/catch, but nm |
||
except Exception as e: | ||
raise ConfigError( | ||
"Invalid range(s) provided in " | ||
"federation_ip_range_blacklist: %s" % e | ||
) | ||
|
||
if self.public_baseurl is not None: | ||
if self.public_baseurl[-1] != '/': | ||
self.public_baseurl += '/' | ||
|
@@ -386,6 +406,24 @@ def default_config(self, server_name, data_dir_path, **kwargs): | |
# - nyc.example.com | ||
# - syd.example.com | ||
|
||
# Prevent federation requests from being sent to the following | ||
# blacklist IP address CIDR ranges. If this option is not specified, or | ||
# specified with an empty list, no ip range blacklist will be enforced. | ||
# | ||
# (0.0.0.0 and :: are always blacklisted, whether or not they are explicitly | ||
# listed here, since they correspond to unroutable addresses.) | ||
# | ||
federation_ip_range_blacklist: | ||
- '127.0.0.0/8' | ||
- '10.0.0.0/8' | ||
- '172.16.0.0/12' | ||
- '192.168.0.0/16' | ||
- '100.64.0.0/10' | ||
- '169.254.0.0/16' | ||
- '::1/128' | ||
- 'fe80::/64' | ||
- 'fc00::/7' | ||
|
||
# List of ports that Synapse should listen on, their purpose and their | ||
# configuration. | ||
# | ||
|
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
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.
we ought to follow the example of #5134 and include 0.0.0.0 and
::
, whether they were explicitly listed or not.