ipn: improve --exit-node hostname error during startup

When parsing the `tailscale up --exit-node=ARG` argument, we try to
resolve hostnames by searching the list of peers. However, at startup,
the peer list is empty, causing hostname lookups to trivially fail with
an unhelpful "invalid value" erorr.

Improve the error message when the peer list is empty to inform the user
that hostnames cannot be resolved during startup, and advise them to use
the exit node's Tailscale IP address instead.

Also, clarify that hostnames must be peer hostnames, not arbitrary
hostnames.

Fixes #19882

Change-Id: I9390a427c2863d657cf46c5e33b43cb3c5363764
Signed-off-by: Alex Chan <alexc@tailscale.com>
This commit is contained in:
Alex Chan
2026-05-28 16:43:45 +01:00
committed by Alex Chan
parent 4b8115bb2c
commit 446ae97491
3 changed files with 49 additions and 7 deletions
+17 -1
View File
@@ -30,6 +30,7 @@ import (
"tailscale.com/tka"
"tailscale.com/tstest"
"tailscale.com/tstest/deptest"
"tailscale.com/types/key"
"tailscale.com/types/logger"
"tailscale.com/types/opt"
"tailscale.com/types/persist"
@@ -769,7 +770,22 @@ func TestPrefsFromUpArgs(t *testing.T) {
args: upArgsT{
exitNodeIP: "foo",
},
wantErr: `invalid value "foo" for --exit-node; must be IP or hostname`,
st: &ipnstate.Status{
Peer: map[key.NodePublic]*ipnstate.PeerStatus{
key.NewNode().Public(): {
DNSName: "example.com.",
TailscaleIPs: []netip.Addr{netip.MustParseAddr("1.0.0.2")},
},
},
},
wantErr: `invalid value "foo" for --exit-node; must be IP or peer hostname`,
},
{
name: "error_exit_node_not_started",
args: upArgsT{
exitNodeIP: "foo",
},
wantErr: `cannot resolve exit node by hostname while Tailscale is starting up; please use its Tailscale IP address instead`,
},
{
name: "error_exit_node_allow_lan_without_exit_node",