From 8e8513e3253e9093c217c23b9d0d11d49c4e93a3 Mon Sep 17 00:00:00 2001 From: Lee Valentine Date: Thu, 24 Sep 2020 21:33:12 -0500 Subject: [PATCH] TRAFFIC-448: allow the user to specify the proxy address and port to bind to, falling back to 127.0.0.1 and random port if not specified --- cmd/cloudflared/tunnel/cmd.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cmd/cloudflared/tunnel/cmd.go b/cmd/cloudflared/tunnel/cmd.go index 8b60eb4a..80638d09 100644 --- a/cmd/cloudflared/tunnel/cmd.go +++ b/cmd/cloudflared/tunnel/cmd.go @@ -12,6 +12,7 @@ import ( "reflect" "runtime" "runtime/trace" + "strconv" "strings" "sync" "time" @@ -506,7 +507,7 @@ func StartServer( } if staticHost := hostnameFromURI(c.String("url")); isProxyDestinationConfigured(staticHost, c) { - listener, err := net.Listen("tcp", "127.0.0.1:") + listener, err := net.Listen("tcp", net.JoinHostPort(c.String("proxy-address"), strconv.Itoa(c.Int("proxy-port")))) if err != nil { log.Errorf("Cannot start Websocket Proxy Server: %s", err) return errors.Wrap(err, "Cannot start Websocket Proxy Server") @@ -947,6 +948,20 @@ func tunnelFlags(shouldHide bool) []cli.Flag { Value: 4, Hidden: true, }), + altsrc.NewStringFlag(&cli.StringFlag{ + Name: "proxy-address", + Usage: "Listen address for the proxy.", + Value: "127.0.0.1", + EnvVars: []string{"TUNNEL_PROXY_ADDRESS"}, + Hidden: shouldHide, + }), + altsrc.NewIntFlag(&cli.IntFlag{ + Name: "proxy-port", + Usage: "Listen port for the proxy.", + Value: 0, + EnvVars: []string{"TUNNEL_PROXY_PORT"}, + Hidden: shouldHide, + }), altsrc.NewDurationFlag(&cli.DurationFlag{ Name: "proxy-connect-timeout", Usage: "HTTP proxy timeout for establishing a new connection",