From 0c4c1455639eb26511ab10edf2dcf51138d1fa11 Mon Sep 17 00:00:00 2001 From: Hugo Shaka Date: Tue, 23 Jan 2024 11:08:05 -0500 Subject: [PATCH 1/2] Fix a bug causing the webUI to be unusable if automatic upgrades are misconfigured --- lib/automaticupgrades/channel.go | 30 ++++++++++++++++-------------- lib/web/apiserver.go | 4 +--- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/automaticupgrades/channel.go b/lib/automaticupgrades/channel.go index 9090d5744c946..f29ceaf3ba631 100644 --- a/lib/automaticupgrades/channel.go +++ b/lib/automaticupgrades/channel.go @@ -179,26 +179,28 @@ func (c *Channel) GetCritical(ctx context.Context) (bool, error) { return c.criticalTrigger.CanStart(ctx, nil) } +var newDefaultChannel = sync.OnceValues[*Channel, error]( + func() (*Channel, error) { + forwardURL := GetChannel() + if forwardURL == "" { + forwardURL = stableCloudVersionBaseURL + } + defaultChannel := &Channel{ + ForwardURL: forwardURL, + } + if err := defaultChannel.CheckAndSetDefaults(); err != nil { + return nil, trace.Wrap(err) + } + return defaultChannel, nil + }) + // NewDefaultChannel creates a default automatic upgrade channel // It looks up the environment variable, and if not found uses the default // base URL. This default channel can be used in the proxy (to back its own version server) // or in other Teleport process such as integration services deploying and // updating teleport agents. func NewDefaultChannel() (*Channel, error) { - return sync.OnceValues[*Channel, error]( - func() (*Channel, error) { - forwardURL := GetChannel() - if forwardURL == "" { - forwardURL = stableCloudVersionBaseURL - } - defaultChannel := &Channel{ - ForwardURL: forwardURL, - } - if err := defaultChannel.CheckAndSetDefaults(); err != nil { - return nil, trace.Wrap(err) - } - return defaultChannel, nil - })() + return newDefaultChannel() } func parseMajorFromVersionString(v string) (int, error) { diff --git a/lib/web/apiserver.go b/lib/web/apiserver.go index 3a75d73b7d01a..8f78a24a9412b 100644 --- a/lib/web/apiserver.go +++ b/lib/web/apiserver.go @@ -1604,9 +1604,7 @@ func (h *Handler) getWebConfig(w http.ResponseWriter, r *http.Request, p httprou var automaticUpgradesTargetVersion string if automaticUpgradesEnabled { automaticUpgradesTargetVersion, err = h.cfg.AutomaticUpgradesChannels.DefaultVersion(r.Context()) - if err != nil { - return nil, trace.Wrap(err) - } + h.log.WithError(err).Error("Cannot read target version") } webCfg := webclient.WebConfig{ From febe0657c3dc5c90a626155191c6fd9afd0ca168 Mon Sep 17 00:00:00 2001 From: Hugo Shaka Date: Tue, 23 Jan 2024 16:19:48 -0500 Subject: [PATCH 2/2] document which env var --- lib/automaticupgrades/channel.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/automaticupgrades/channel.go b/lib/automaticupgrades/channel.go index f29ceaf3ba631..ffabfbf3540a9 100644 --- a/lib/automaticupgrades/channel.go +++ b/lib/automaticupgrades/channel.go @@ -195,9 +195,10 @@ var newDefaultChannel = sync.OnceValues[*Channel, error]( }) // NewDefaultChannel creates a default automatic upgrade channel -// It looks up the environment variable, and if not found uses the default -// base URL. This default channel can be used in the proxy (to back its own version server) -// or in other Teleport process such as integration services deploying and +// It looks up the TELEPORT_AUTOMATIC_UPGRADES_CHANNEL environment variable for +// backward compatibility, and if not found uses the default base URL. +// This default channel can be used in the proxy (to back its own version server) +// or in other Teleport processes such as integration services deploying and // updating teleport agents. func NewDefaultChannel() (*Channel, error) { return newDefaultChannel()