Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 232b324

Browse files
Port "Add support for no_proxy and case insensitive env variables" from mainline to dinsic (#93)
This PR is simply porting matrix-org/synapse#9372 to dinsic. I also had to bring in matrix-org/synapse#8821 and matrix-org/synapse#9084 for this code to work properly - a sign that we should merge mainline into dinsic again soon.
1 parent 396e7d4 commit 232b324

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+398
-154
lines changed

changelog.d/8821.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Apply the `federation_ip_range_blacklist` to push and key revocation requests.

changelog.d/9084.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Don't blacklist connections to the configured proxy. Contributed by @Bubu.

changelog.d/9372.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The `no_proxy` and `NO_PROXY` environment variables are now respected in proxied HTTP clients with the lowercase form taking precedence if both are present. Additionally, the lowercase `https_proxy` environment variable is now respected in proxied HTTP clients on top of existing support for the uppercase `HTTPS_PROXY` form and takes precedence if both are present. Contributed by Timothy Leung.

docs/sample_config.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -710,17 +710,19 @@ acme:
710710
# - nyc.example.com
711711
# - syd.example.com
712712

713-
# Prevent federation requests from being sent to the following
714-
# blacklist IP address CIDR ranges. If this option is not specified, or
715-
# specified with an empty list, no ip range blacklist will be enforced.
713+
# Prevent outgoing requests from being sent to the following blacklisted IP address
714+
# CIDR ranges. If this option is not specified, or specified with an empty list,
715+
# no IP range blacklist will be enforced.
716716
#
717-
# As of Synapse v1.4.0 this option also affects any outbound requests to identity
718-
# servers provided by user input.
717+
# The blacklist applies to the outbound requests for federation, identity servers,
718+
# push servers, and for checking key validitity for third-party invite events.
719719
#
720720
# (0.0.0.0 and :: are always blacklisted, whether or not they are explicitly
721721
# listed here, since they correspond to unroutable addresses.)
722722
#
723-
federation_ip_range_blacklist:
723+
# This option replaces federation_ip_range_blacklist in Synapse v1.24.0.
724+
#
725+
ip_range_blacklist:
724726
- '127.0.0.0/8'
725727
- '10.0.0.0/8'
726728
- '172.16.0.0/12'

synapse/app/generic_worker.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ def __init__(self, hs):
266266
super().__init__(hs)
267267
self.hs = hs
268268
self.is_mine_id = hs.is_mine_id
269-
self.http_client = hs.get_simple_http_client()
270269

271270
self._presence_enabled = hs.config.use_presence
272271

synapse/config/federation.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,30 @@ def read_config(self, config, **kwargs):
3636
for domain in federation_domain_whitelist:
3737
self.federation_domain_whitelist[domain] = True
3838

39-
self.federation_ip_range_blacklist = config.get(
40-
"federation_ip_range_blacklist", []
41-
)
39+
ip_range_blacklist = config.get("ip_range_blacklist", [])
4240

4341
# Attempt to create an IPSet from the given ranges
4442
try:
45-
self.federation_ip_range_blacklist = IPSet(
46-
self.federation_ip_range_blacklist
47-
)
48-
49-
# Always blacklist 0.0.0.0, ::
50-
self.federation_ip_range_blacklist.update(["0.0.0.0", "::"])
43+
self.ip_range_blacklist = IPSet(ip_range_blacklist)
44+
except Exception as e:
45+
raise ConfigError("Invalid range(s) provided in ip_range_blacklist: %s" % e)
46+
# Always blacklist 0.0.0.0, ::
47+
self.ip_range_blacklist.update(["0.0.0.0", "::"])
48+
49+
# The federation_ip_range_blacklist is used for backwards-compatibility
50+
# and only applies to federation and identity servers. If it is not given,
51+
# default to ip_range_blacklist.
52+
federation_ip_range_blacklist = config.get(
53+
"federation_ip_range_blacklist", ip_range_blacklist
54+
)
55+
try:
56+
self.federation_ip_range_blacklist = IPSet(federation_ip_range_blacklist)
5157
except Exception as e:
5258
raise ConfigError(
5359
"Invalid range(s) provided in federation_ip_range_blacklist: %s" % e
5460
)
61+
# Always blacklist 0.0.0.0, ::
62+
self.federation_ip_range_blacklist.update(["0.0.0.0", "::"])
5563

5664
federation_metrics_domains = config.get("federation_metrics_domains") or []
5765
validate_config(
@@ -76,17 +84,19 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs):
7684
# - nyc.example.com
7785
# - syd.example.com
7886
79-
# Prevent federation requests from being sent to the following
80-
# blacklist IP address CIDR ranges. If this option is not specified, or
81-
# specified with an empty list, no ip range blacklist will be enforced.
87+
# Prevent outgoing requests from being sent to the following blacklisted IP address
88+
# CIDR ranges. If this option is not specified, or specified with an empty list,
89+
# no IP range blacklist will be enforced.
8290
#
83-
# As of Synapse v1.4.0 this option also affects any outbound requests to identity
84-
# servers provided by user input.
91+
# The blacklist applies to the outbound requests for federation, identity servers,
92+
# push servers, and for checking key validitity for third-party invite events.
8593
#
8694
# (0.0.0.0 and :: are always blacklisted, whether or not they are explicitly
8795
# listed here, since they correspond to unroutable addresses.)
8896
#
89-
federation_ip_range_blacklist:
97+
# This option replaces federation_ip_range_blacklist in Synapse v1.24.0.
98+
#
99+
ip_range_blacklist:
90100
- '127.0.0.0/8'
91101
- '10.0.0.0/8'
92102
- '172.16.0.0/12'

synapse/crypto/keyring.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ class PerspectivesKeyFetcher(BaseV2KeyFetcher):
578578
def __init__(self, hs):
579579
super().__init__(hs)
580580
self.clock = hs.get_clock()
581-
self.client = hs.get_http_client()
581+
self.client = hs.get_federation_http_client()
582582
self.key_servers = self.config.key_servers
583583

584584
async def get_keys(self, keys_to_fetch):
@@ -748,7 +748,7 @@ class ServerKeyFetcher(BaseV2KeyFetcher):
748748
def __init__(self, hs):
749749
super().__init__(hs)
750750
self.clock = hs.get_clock()
751-
self.client = hs.get_http_client()
751+
self.client = hs.get_federation_http_client()
752752

753753
async def get_keys(self, keys_to_fetch):
754754
"""

synapse/federation/federation_server.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,6 @@ class FederationHandlerRegistry:
916916

917917
def __init__(self, hs: "HomeServer"):
918918
self.config = hs.config
919-
self.http_client = hs.get_simple_http_client()
920919
self.clock = hs.get_clock()
921920
self._instance_name = hs.get_instance_name()
922921

synapse/federation/transport/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class TransportLayerClient:
3838

3939
def __init__(self, hs):
4040
self.server_name = hs.hostname
41-
self.client = hs.get_http_client()
41+
self.client = hs.get_federation_http_client()
4242

4343
@log_function
4444
def get_room_state_ids(self, destination, room_id, event_id):

synapse/handlers/federation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def __init__(self, hs: "HomeServer"):
141141
self._message_handler = hs.get_message_handler()
142142
self._server_notices_mxid = hs.config.server_notices_mxid
143143
self.config = hs.config
144-
self.http_client = hs.get_simple_http_client()
144+
self.http_client = hs.get_proxied_blacklisted_http_client()
145145
self._instance_name = hs.get_instance_name()
146146
self._replication = hs.get_replication_data_handler()
147147

0 commit comments

Comments
 (0)