Add HTTP proxy support for tunnel connections#1514
Add HTTP proxy support for tunnel connections#1514shayonj wants to merge 1 commit intocloudflare:masterfrom
Conversation
7995418 to
664ed3f
Compare
|
Hi, will this work for quick tunnel setup as well? |
GoncaloGarcia
left a comment
There was a problem hiding this comment.
Hey! Thank you for the PR.
As discussed offline it seems like your interest is mostly the HTTP proxy? If so, we don't need to introduce support for SOCKS proxy in this PR.
Additionally, I wasn't able to verify the behavior by setting up a local instance of mitmproxy and setting the flags as your example suggests. Could you provide a script that sets up a basic example with a client + cloudflared running a tunnel + mitmproxy logging the requests?
| return nil, fmt.Errorf("proxy connection failed: %w", err) | ||
| } | ||
|
|
||
| connectReq := fmt.Sprintf("CONNECT %s HTTP/1.1\r\nHost: %s\r\n\r\n", addr, addr) |
There was a problem hiding this comment.
Could you use the request struct instead and req.Write instead?
// Build CONNECT request using http.Request
req := &http.Request{
Method: "CONNECT",
URL: &url.URL{Host: addr},
Host: addr,
Proto: "HTTP/1.1",
ProtoMajor: 1,
ProtoMinor: 1,
Header: make(http.Header),
}
Also, is there a reason why you're hardcoding HTTP 1.1?
| httpProxy := getEnvProxy("HTTP_PROXY", "http_proxy") | ||
| httpsProxy := getEnvProxy("HTTPS_PROXY", "https_proxy") | ||
|
|
||
| if httpProxy == "" && httpsProxy == "" { | ||
| if logger != nil { | ||
| logger.Debug().Msg("proxy: no proxy configured, using direct connection") | ||
| } | ||
| return baseDialer | ||
| } |
There was a problem hiding this comment.
Could you use golang.org/x/net/http/httpproxy instead of checking for these variables manually?
| require.Error(t, err) | ||
| } | ||
|
|
||
| func TestProxyAwareDialer(t *testing.T) { |
There was a problem hiding this comment.
Could you add some tests that use the authentication variables in the proxy URL and another for NO_PROXY?
This PR adds support for HTTP and SOCKS proxy configurations to cloudflared tunnel connections via standard environment variables (
HTTP_PROXY,HTTPS_PROXY,ALL_PROXY). This enables cloudflared to work in enterprise environments that require all outbound traffic to route through corporate proxy infrastructure.Changes include:
proxyAwareDialerstruct that implements both HTTP CONNECT and SOCKS proxy protocolsrawTCPServiceandtcpOverWSServiceto useproxy.Dialerinterface instead ofnet.Dialerproxy.FromEnvironmentUsing()for SOCKS proxies andhttp.ProxyFromEnvironment()for HTTP proxiescreateProxyDialerto make delegation easyProxy precedence order:
ALL_PROXYenvironment variableHTTP_PROXY/HTTPS_PROXYenvironment variables (supports both upper and lower case)Authentication support:
http://user:pass@proxy:8080)golang.org/x/net/proxyUsage Example:
Example:

#1076