From 7e81c83e64c9719907588f35b0935771d105fe54 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Fri, 3 Nov 2023 16:41:04 -0700 Subject: [PATCH] cmd/tailscale: respect existing web client pref After running `tailscale web`, only disable the user pref if it was not already previously set. Updates tailscale/corp#14335 Signed-off-by: Will Norris --- cmd/tailscale/cli/web.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/cmd/tailscale/cli/web.go b/cmd/tailscale/cli/web.go index f59905510..909979a45 100644 --- a/cmd/tailscale/cli/web.go +++ b/cmd/tailscale/cli/web.go @@ -91,12 +91,18 @@ func runWeb(ctx context.Context, args []string) error { hasPreviewCap := st.Self.HasCap(tailcfg.CapabilityPreviewWebClient) cliServerMode := web.LegacyServerMode + var existingWebClient bool + if prefs, err := localClient.GetPrefs(ctx); err == nil { + existingWebClient = prefs.RunWebClient + } if hasPreviewCap { cliServerMode = web.LoginServerMode - // Also start full client in tailscaled. - log.Printf("starting tailscaled web client at %s:5252\n", st.Self.TailscaleIPs[0]) - if err := setRunWebClient(ctx, true); err != nil { - return fmt.Errorf("starting web client in tailscaled: %w", err) + if !existingWebClient { + // Also start full client in tailscaled. + log.Printf("starting tailscaled web client at %s:5252\n", st.Self.TailscaleIPs[0]) + if err := setRunWebClient(ctx, true); err != nil { + return fmt.Errorf("starting web client in tailscaled: %w", err) + } } } @@ -115,7 +121,7 @@ func runWeb(ctx context.Context, args []string) error { case <-ctx.Done(): // Shutdown the server. webServer.Shutdown() - if hasPreviewCap && !webArgs.cgi { + if hasPreviewCap && !webArgs.cgi && !existingWebClient { log.Println("stopping tailscaled web client") // When not in cgi mode, shut down the tailscaled // web client on cli termination.