diff --git a/cli/cliui/agent.go b/cli/cliui/agent.go index dbc73fb13e663..f2c1378eecb7a 100644 --- a/cli/cliui/agent.go +++ b/cli/cliui/agent.go @@ -411,7 +411,8 @@ func (d ConnDiags) splitDiagnostics() (general, client, agent []string) { } if d.DisableDirect { - general = append(general, "❗ Direct connections are disabled locally, by `--disable-direct` or `CODER_DISABLE_DIRECT`") + general = append(general, "❗ Direct connections are disabled locally, by `--disable-direct-connections` or `CODER_DISABLE_DIRECT_CONNECTIONS`.\n"+ + " They may still be established over a private network.") if !d.Verbose { return general, client, agent } diff --git a/cli/ping.go b/cli/ping.go index 0423416f040cb..cd3f6e3a8ba55 100644 --- a/cli/ping.go +++ b/cli/ping.go @@ -118,6 +118,7 @@ func (r *RootCmd) ping() *serpent.Command { workspaceName, ) if err != nil { + spin.Stop() return err } @@ -128,7 +129,6 @@ func (r *RootCmd) ping() *serpent.Command { } if r.disableDirect { - _, _ = fmt.Fprintln(inv.Stderr, "Direct connections disabled.") opts.BlockEndpoints = true } if !r.disableNetworkTelemetry { @@ -137,6 +137,7 @@ func (r *RootCmd) ping() *serpent.Command { wsClient := workspacesdk.New(client) conn, err := wsClient.DialAgent(ctx, workspaceAgent.ID, opts) if err != nil { + spin.Stop() return err } defer conn.Close() @@ -168,6 +169,7 @@ func (r *RootCmd) ping() *serpent.Command { connInfo, err := wsClient.AgentConnectionInfoGeneric(diagCtx) if err != nil || connInfo.DERPMap == nil { + spin.Stop() return xerrors.Errorf("Failed to retrieve connection info from server: %w\n", err) } connDiags.ConnInfo = connInfo @@ -197,6 +199,11 @@ func (r *RootCmd) ping() *serpent.Command { results := &pingSummary{ Workspace: workspaceName, } + var ( + pong *ipnstate.PingResult + dur time.Duration + p2p bool + ) n := 0 start := time.Now() pingLoop: @@ -207,7 +214,7 @@ func (r *RootCmd) ping() *serpent.Command { n++ ctx, cancel := context.WithTimeout(ctx, pingTimeout) - dur, p2p, pong, err := conn.Ping(ctx) + dur, p2p, pong, err = conn.Ping(ctx) cancel() results.addResult(pong) if err != nil { @@ -275,10 +282,15 @@ func (r *RootCmd) ping() *serpent.Command { } } - if didP2p { - _, _ = fmt.Fprintf(inv.Stderr, "✔ You are connected directly (p2p)\n") + if p2p { + msg := "✔ You are connected directly (p2p)" + if pong != nil && isPrivateEndpoint(pong.Endpoint) { + msg += ", over a private network" + } + _, _ = fmt.Fprintln(inv.Stderr, msg) } else { - _, _ = fmt.Fprintf(inv.Stderr, "❗ You are connected via a DERP relay, not directly (p2p)\n%s#common-problems-with-direct-connections\n", connDiags.TroubleshootingURL) + _, _ = fmt.Fprintf(inv.Stderr, "❗ You are connected via a DERP relay, not directly (p2p)\n"+ + " %s#common-problems-with-direct-connections\n", connDiags.TroubleshootingURL) } results.Write(inv.Stdout) @@ -329,3 +341,11 @@ func isAWSIP(awsRanges *cliutil.AWSIPRanges, ni *tailcfg.NetInfo) bool { } return false } + +func isPrivateEndpoint(endpoint string) bool { + ip, err := netip.ParseAddrPort(endpoint) + if err != nil { + return false + } + return ip.Addr().IsPrivate() +}
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: