From 3650899b2950d059fbfed4b42fec19e47f1a4739 Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Wed, 30 Sep 2015 12:14:00 +0200 Subject: [PATCH] Add --address to kubectl proxy --- pkg/kubectl/cmd/proxy.go | 4 +++- pkg/kubectl/proxy_server.go | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/kubectl/cmd/proxy.go b/pkg/kubectl/cmd/proxy.go index 5ab96b185ee..5ec9114f16d 100644 --- a/pkg/kubectl/cmd/proxy.go +++ b/pkg/kubectl/cmd/proxy.go @@ -77,6 +77,7 @@ The above lets you 'curl localhost:8001/custom/api/v1/pods' cmd.Flags().String("accept-hosts", kubectl.DefaultHostAcceptRE, "Regular expression for hosts that the proxy should accept.") cmd.Flags().String("reject-methods", kubectl.DefaultMethodRejectRE, "Regular expression for HTTP methods that the proxy should reject.") cmd.Flags().IntP("port", "p", default_port, "The port on which to run the proxy. Set to 0 to pick a random port.") + cmd.Flags().StringP("address", "", "127.0.0.1", "The IP address on which to serve on.") cmd.Flags().Bool("disable-filter", false, "If true, disable request filtering in the proxy. This is dangerous, and can leave you vulnerable to XSRF attacks, when used with an accessible port.") cmd.Flags().StringP("unix-socket", "u", "", "Unix socket on which to run the proxy.") return cmd @@ -85,6 +86,7 @@ The above lets you 'curl localhost:8001/custom/api/v1/pods' func RunProxy(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command) error { path := cmdutil.GetFlagString(cmd, "unix-socket") port := cmdutil.GetFlagInt(cmd, "port") + address := cmdutil.GetFlagString(cmd, "address") if port != default_port && path != "" { return errors.New("Don't specify both --unix-socket and --port") @@ -122,7 +124,7 @@ func RunProxy(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command) error { // when it is chosen by os (eg: port == 0) var l net.Listener if path == "" { - l, err = server.Listen(port) + l, err = server.Listen(address, port) } else { l, err = server.ListenUnix(path) } diff --git a/pkg/kubectl/proxy_server.go b/pkg/kubectl/proxy_server.go index 09fef59d810..11125023ddc 100644 --- a/pkg/kubectl/proxy_server.go +++ b/pkg/kubectl/proxy_server.go @@ -179,8 +179,8 @@ func NewProxyServer(filebase string, apiProxyPrefix string, staticPrefix string, } // Listen is a simple wrapper around net.Listen. -func (s *ProxyServer) Listen(port int) (net.Listener, error) { - return net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", port)) +func (s *ProxyServer) Listen(address string, port int) (net.Listener, error) { + return net.Listen("tcp", fmt.Sprintf("%s:%d", address, port)) } // ListenUnix does net.Listen for a unix socket