From 0bf515e78089fb1e43f3117c2e4e412365daba00 Mon Sep 17 00:00:00 2001 From: Maisem Ali Date: Tue, 19 Oct 2021 23:36:29 -0700 Subject: [PATCH] cmd/tailscale: changes to --advertise-tags should wait for possible reauth. Signed-off-by: Maisem Ali --- cmd/tailscale/cli/cli_test.go | 12 ++++++++++++ cmd/tailscale/cli/up.go | 7 +++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/cmd/tailscale/cli/cli_test.go b/cmd/tailscale/cli/cli_test.go index 24f3fb100..1af9cc3b1 100644 --- a/cmd/tailscale/cli/cli_test.go +++ b/cmd/tailscale/cli/cli_test.go @@ -759,6 +759,18 @@ func TestUpdatePrefs(t *testing.T) { wantJustEditMP: &ipn.MaskedPrefs{WantRunningSet: true}, wantErrSubtr: "can't change --login-server without --force-reauth", }, + { + name: "change_tags", + flags: []string{"--advertise-tags=tag:foo"}, + curPrefs: &ipn.Prefs{ + ControlURL: "https://login.tailscale.com", + Persist: &persist.Persist{LoginName: "crawshaw.github"}, + AllowSingleHosts: true, + CorpDNS: true, + NetfilterMode: preftype.NetfilterOn, + }, + env: upCheckEnv{backendState: "Running"}, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/cmd/tailscale/cli/up.go b/cmd/tailscale/cli/up.go index 72982e13d..4a4baae81 100644 --- a/cmd/tailscale/cli/up.go +++ b/cmd/tailscale/cli/up.go @@ -277,7 +277,7 @@ func prefsFromUpArgs(upArgs upArgsT, warnf logger.Logf, st *ipnstate.Status, goo // It returns a non-nil justEditMP if we're already running and none of // the flags require a restart, so we can just do an EditPrefs call and // change the prefs at runtime (e.g. changing hostname, changing -// advertised tags, routes, etc). +// advertised routes, etc). // // It returns simpleUp if we're running a simple "tailscale up" to // transition to running from a previously-logged-in but down state, @@ -297,6 +297,8 @@ func updatePrefs(prefs, curPrefs *ipn.Prefs, env upCheckEnv) (simpleUp bool, jus return false, nil, fmt.Errorf("can't change --login-server without --force-reauth") } + tagsChanged := !reflect.DeepEqual(curPrefs.AdvertiseTags, prefs.AdvertiseTags) + simpleUp = env.flagSet.NFlag() == 0 && curPrefs.Persist != nil && curPrefs.Persist.LoginName != "" && @@ -306,7 +308,8 @@ func updatePrefs(prefs, curPrefs *ipn.Prefs, env upCheckEnv) (simpleUp bool, jus !env.upArgs.forceReauth && !env.upArgs.reset && env.upArgs.authKeyOrFile == "" && - !controlURLChanged + !controlURLChanged && + !tagsChanged if justEdit { justEditMP = new(ipn.MaskedPrefs) justEditMP.WantRunningSet = true