From 0748e658ccdf5ff0f1f37a6ab758674630a2259f Mon Sep 17 00:00:00 2001 From: Jose Garcia Date: Thu, 14 Oct 2021 11:07:25 -0400 Subject: [PATCH] Switches port binding to 127.0.0.1 where possible --- internal/codespaces/states.go | 2 +- pkg/cmd/codespace/logs.go | 2 +- pkg/cmd/codespace/ssh.go | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/codespaces/states.go b/internal/codespaces/states.go index 00170d3ec..b686c1888 100644 --- a/internal/codespaces/states.go +++ b/internal/codespaces/states.go @@ -52,7 +52,7 @@ func PollPostCreateStates(ctx context.Context, logger logger, apiClient apiClien }() // Ensure local port is listening before client (getPostCreateOutput) connects. - listen, err := net.Listen("tcp", ":0") // arbitrary port + listen, err := net.Listen("tcp", "127.0.0.1:0") // arbitrary port if err != nil { return err } diff --git a/pkg/cmd/codespace/logs.go b/pkg/cmd/codespace/logs.go index 317059918..1b6e57a84 100644 --- a/pkg/cmd/codespace/logs.go +++ b/pkg/cmd/codespace/logs.go @@ -62,7 +62,7 @@ func (a *App) Logs(ctx context.Context, codespaceName string, follow bool) (err } // Ensure local port is listening before client (getPostCreateOutput) connects. - listen, err := net.Listen("tcp", ":0") // arbitrary port + listen, err := net.Listen("tcp", "127.0.0.1:0") // arbitrary port if err != nil { return err } diff --git a/pkg/cmd/codespace/ssh.go b/pkg/cmd/codespace/ssh.go index fbd479c38..218494a13 100644 --- a/pkg/cmd/codespace/ssh.go +++ b/pkg/cmd/codespace/ssh.go @@ -94,7 +94,9 @@ func (a *App) SSH(ctx context.Context, sshArgs []string, opts sshOptions) (err e usingCustomPort := localSSHServerPort != 0 // suppress log of command line in Shell // Ensure local port is listening before client (Shell) connects. - listen, err := net.Listen("tcp", fmt.Sprintf(":%d", localSSHServerPort)) + // Unless the user specifies a server port, localSSHServerPort is 0 + // and thus the client will pick a random port. + listen, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", localSSHServerPort)) if err != nil { return err }