-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Conversation
I'm trying to adapt the proxyagent tests for this... but it's not that easy to see what's going on and now having to nest two ssl connections inside each other isn't helping at all. |
Please feel free to ask, probably best in #synapse-dev:matrix.org. |
f01e490
to
8818309
Compare
Sorry for this being stale so long, I've rebased this on develop again (meanwhile #9372 has changed things up somewhat, so that required some cosmetic changes here as well). The blocker preciously were missing tests, I think I found a good way to add tests for this 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.
Looks reasonable overall! I left a few comments though.
I have this issue[1], I assume it is related to half implemented proxy support. Is it possible to get some patch or so, that I can apply to the pip package matrix-synapse. I would like to try matrix chat. Or is there some indication when proxy support will be fully implemented? [1] |
I think #9119 (comment) is still an oustanding comment, by the way. |
I think we're still waiting for #9119 (comment) to be dealt with, so removing review request for now. (There also seems to be some conflicts that need to be resolved) |
I tried this bubu https_proxy branch, but I am still getting these matrix-synapse synapse.http.federation.matrix_federation_agent - 288 - INFO - GET-23 - Failed to connect to matrix-federation.matrix.org.cdn.cloudflare.net:8443: No route to host: 101: Network unreachable. |
Note that the context for @f1-outsourcing's setup is at #9852. |
Will this merge make it possible to use matrix without setting a default gateway and only use a forward and reverse proxy? Because this is still not clear to me. Or is this changing just a little part of the code, and then we have to change another little part, and then we have to change another little part. etc. |
If you do not know, would you mind stating this then, because I do not know what to expect now. |
This comment has been minimized.
This comment has been minimized.
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.
looks generally good to me! A few small comments here.
@@ -121,11 +122,11 @@ def __init__( | |||
self.https_proxy_creds, https_proxy = parse_username_password(https_proxy) |
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.
this will break for https://username:password@host
, I think? Probably best to call parse_proxy
here
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.
Is there a reason why only credentials were parsed for https proxy? Only security reason or anything else?
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.
this will break for
https://username:password@host
, I think? Probably best to callparse_proxy
here
I would suggest a solution like this.
This change can make parse_username_password
compatible to https://username:password@host
diff --git a/synapse/http/proxyagent.py b/synapse/http/proxyagent.py
index c747b99..3c4fee6 100644
--- a/synapse/http/proxyagent.py
+++ b/synapse/http/proxyagent.py
@@ -293,7 +293,7 @@
def parse_username_password(proxy: bytes) -> Tuple[Optional[ProxyCredentials], bytes]:
"""
Parses the username and password from a proxy declaration e.g
- username:password@hostname:port.
+ username:password@hostname:port or https://username:password@hostname:port
Args:
proxy: The proxy connection string.
@@ -304,9 +304,15 @@
ProxyCredentials instance is replaced with None.
"""
if proxy and b"@" in proxy:
+ scheme, host, port = parse_proxy(proxy)
# We use rsplit here as the password could contain an @ character
- credentials, proxy_without_credentials = proxy.rsplit(b"@", 1)
- return ProxyCredentials(credentials), proxy_without_credentials
+ credentials, proxy_without_credentials = host.rsplit(b"@", 1)
+ return (
+ ProxyCredentials(credentials),
+ b"".join(
+ [scheme, b"://", proxy_without_credentials, b":", str(port).encode()]
+ ),
+ )
return None, proxy
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.
Is there a reason why only credentials were parsed for https proxy? Only security reason or anything else?
I don't think there is much reason at all. Support for credentials was added in #9657: perhaps http_proxy
was just fogotten?
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 would suggest a solution like this.
seems sensible.
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.
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.
needs support for <scheme>://<username>:<password>@<host>
While I'm here, I'll just complain that it's a real shame that this code has been cut-and-pasted into sygnal, at https://github.com/matrix-org/sygnal/blob/main/sygnal/helper/proxy/proxyagent_twisted.py rather than factored out to a separate library. Now we have two versions to maintain :(. |
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
oh I hadn't realised that @Bubu had updated it since my last review. Let me stick it back in the queue for review. |
Co-authored-by: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com>
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.
This currently supports http:// and https:// proxies. | ||
A hostname without scheme is assumed to be http. |
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.
this is a bit confusing. A hostname where?
... and yes, of course it supports http and https proxies - what other sorts of proxies would an http/https agent possibly care about?
Suggest removing these lines.
@@ -121,11 +122,11 @@ def __init__( | |||
self.https_proxy_creds, https_proxy = parse_username_password(https_proxy) |
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.
Is there a reason why only credentials were parsed for https proxy? Only security reason or anything else?
I don't think there is much reason at all. Support for credentials was added in #9657: perhaps http_proxy
was just fogotten?
@@ -121,11 +122,11 @@ def __init__( | |||
self.https_proxy_creds, https_proxy = parse_username_password(https_proxy) |
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 would suggest a solution like this.
seems sensible.
if b"://" in proxy: | ||
scheme, host = proxy.split(b"://", 1) |
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 have thought about the problem with Python 3.9 and urlparse
. See: #9119 (comment)
I would suggest to work with urlparse after all. For compatibility reasons we can check if there is a sheme and if not we add this. Somthing like this
if b"://" in proxy: | |
scheme, host = proxy.split(b"://", 1) | |
if not b"://" in proxy: | |
proxy = b"".join([default_scheme, b"://", proxy]) |
Thanks for taking over! ❤️ |
Pull Request Checklist
EventStore
toEventWorkerStore
.".code blocks
.