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

This commit is contained in:
Lee Valentine 2020-09-24 21:33:12 -05:00
parent 607dcff697
commit 8e8513e325
1 changed files with 16 additions and 1 deletions

View File

@ -12,6 +12,7 @@ import (
"reflect" "reflect"
"runtime" "runtime"
"runtime/trace" "runtime/trace"
"strconv"
"strings" "strings"
"sync" "sync"
"time" "time"
@ -506,7 +507,7 @@ func StartServer(
} }
if staticHost := hostnameFromURI(c.String("url")); isProxyDestinationConfigured(staticHost, c) { 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 { if err != nil {
log.Errorf("Cannot start Websocket Proxy Server: %s", err) log.Errorf("Cannot start Websocket Proxy Server: %s", err)
return errors.Wrap(err, "Cannot start Websocket Proxy Server") return errors.Wrap(err, "Cannot start Websocket Proxy Server")
@ -947,6 +948,20 @@ func tunnelFlags(shouldHide bool) []cli.Flag {
Value: 4, Value: 4,
Hidden: true, 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{ altsrc.NewDurationFlag(&cli.DurationFlag{
Name: "proxy-connect-timeout", Name: "proxy-connect-timeout",
Usage: "HTTP proxy timeout for establishing a new connection", Usage: "HTTP proxy timeout for establishing a new connection",