Fix `gh cs ports` requiring `sudo` for privileged port numbers by cmbrose · Pull Request #7326 · cli/cli · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions internal/codespaces/codespaces.go
1 change: 1 addition & 0 deletions internal/codespaces/rpc/invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ func (i *invoker) StartSSHServerWithOptions(ctx context.Context, options StartSS
}

func listenTCP() (*net.TCPListener, error) {
// We will end up using this same address to connect, so specify the IP also or the connect will fail
Comment thread
jkeech marked this conversation as resolved.
addr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:0")
if err != nil {
return nil, fmt.Errorf("failed to build tcp address: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion internal/codespaces/states.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func PollPostCreateStates(ctx context.Context, progress progressIndicator, apiCl
}()

// Ensure local port is listening before client (getPostCreateOutput) connects.
listen, localPort, err := ListenTCP(0)
listen, localPort, err := ListenTCP(0, false)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/codespace/jupyter.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (a *App) Jupyter(ctx context.Context, selector *CodespaceSelector) (err err
}

// Pass 0 to pick a random port
listen, _, err := codespaces.ListenTCP(0)
listen, _, err := codespaces.ListenTCP(0, false)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/codespace/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (a *App) Logs(ctx context.Context, selector *CodespaceSelector, follow bool
defer safeClose(session, &err)

// Ensure local port is listening before client (getPostCreateOutput) connects.
listen, localPort, err := codespaces.ListenTCP(0)
listen, localPort, err := codespaces.ListenTCP(0, false)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/codespace/ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func (a *App) ForwardPorts(ctx context.Context, selector *CodespaceSelector, por
for _, pair := range portPairs {
pair := pair
group.Go(func() error {
listen, _, err := codespaces.ListenTCP(pair.local)
listen, _, err := codespaces.ListenTCP(pair.local, true)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/codespace/ssh.go