From b8af91403d16886bc7aa60d931379c007adbe2f0 Mon Sep 17 00:00:00 2001 From: Andrew Lytvynov Date: Mon, 8 Jul 2024 15:54:50 -0700 Subject: [PATCH] clientupdate: return true for CanAutoUpdate for macsys (#12746) While `clientupdate.Updater` won't be able to apply updates on macsys, we use `clientupdate.CanAutoUpdate` to gate the EditPrefs endpoint in localAPI. We should allow the GUI client to set AutoUpdate.Apply on macsys for it to properly get reported to the control plane. This also allows the tailnet-wide default for auto-updates to propagate to macsys clients. Updates https://github.com/tailscale/corp/issues/21339 Signed-off-by: Andrew Lytvynov --- clientupdate/clientupdate.go | 5 +++++ cmd/tailscale/cli/set.go | 7 +++---- ipn/ipnlocal/autoupdate.go | 5 +++++ ipn/ipnlocal/c2n.go | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/clientupdate/clientupdate.go b/clientupdate/clientupdate.go index 50bcf12dd..67edce05b 100644 --- a/clientupdate/clientupdate.go +++ b/clientupdate/clientupdate.go @@ -248,6 +248,11 @@ func (up *Updater) getUpdateFunction() (fn updateFunction, canAutoUpdate bool) { // CanAutoUpdate reports whether auto-updating via the clientupdate package // is supported for the current os/distro. func CanAutoUpdate() bool { + if version.IsMacSysExt() { + // Macsys uses Sparkle for auto-updates, which doesn't have an update + // function in this package. + return true + } _, canAutoUpdate := (&Updater{}).getUpdateFunction() return canAutoUpdate } diff --git a/cmd/tailscale/cli/set.go b/cmd/tailscale/cli/set.go index 0e9d35924..2e1251f04 100644 --- a/cmd/tailscale/cli/set.go +++ b/cmd/tailscale/cli/set.go @@ -210,6 +210,9 @@ func runSet(ctx context.Context, args []string) (retErr error) { } } if maskedPrefs.AutoUpdateSet.ApplySet { + if !clientupdate.CanAutoUpdate() { + return errors.New("automatic updates are not supported on this platform") + } // On macsys, tailscaled will set the Sparkle auto-update setting. It // does not use clientupdate. if version.IsMacSysExt() { @@ -221,10 +224,6 @@ func runSet(ctx context.Context, args []string) (retErr error) { if err != nil { return fmt.Errorf("failed to enable automatic updates: %v, %q", err, out) } - } else { - if !clientupdate.CanAutoUpdate() { - return errors.New("automatic updates are not supported on this platform") - } } } checkPrefs := curPrefs.Clone() diff --git a/ipn/ipnlocal/autoupdate.go b/ipn/ipnlocal/autoupdate.go index b12fbb67d..b7d217a10 100644 --- a/ipn/ipnlocal/autoupdate.go +++ b/ipn/ipnlocal/autoupdate.go @@ -11,6 +11,7 @@ import ( "tailscale.com/clientupdate" "tailscale.com/ipn" + "tailscale.com/version" ) func (b *LocalBackend) stopOfflineAutoUpdate() { @@ -30,6 +31,10 @@ func (b *LocalBackend) maybeStartOfflineAutoUpdate(prefs ipn.PrefsView) { if !clientupdate.CanAutoUpdate() { return } + // On macsys, auto-updates are managed by Sparkle. + if version.IsMacSysExt() { + return + } if b.offlineAutoUpdateCancel != nil { // Already running. diff --git a/ipn/ipnlocal/c2n.go b/ipn/ipnlocal/c2n.go index f90f73423..44dc4a6ba 100644 --- a/ipn/ipnlocal/c2n.go +++ b/ipn/ipnlocal/c2n.go @@ -355,7 +355,7 @@ func (b *LocalBackend) newC2NUpdateResponse() tailcfg.C2NUpdateResponse { prefs := b.Prefs().AutoUpdate() return tailcfg.C2NUpdateResponse{ Enabled: envknob.AllowsRemoteUpdate() || prefs.Apply.EqualBool(true), - Supported: clientupdate.CanAutoUpdate(), + Supported: clientupdate.CanAutoUpdate() && !version.IsMacSysExt(), } }