From 2f17a34242bd73036a3c55a02caf9ad07f60fb45 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 21 Apr 2021 13:37:36 -0700 Subject: [PATCH] ipn/ipnlocal: fix tailscale status --json AuthURL field It was getting cleared on notify. Document that authURL is cleared on notify and add a new field that isn't, using the new field for the JSON status. Signed-off-by: Brad Fitzpatrick --- ipn/ipnlocal/local.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 8c9c490ad..478a30507 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -114,7 +114,8 @@ type LocalBackend struct { engineStatus ipn.EngineStatus endpoints []tailcfg.Endpoint blocked bool - authURL string + authURL string // cleared on Notify + authURLSticky string // not cleared on Notify interact bool prevIfState *interfaces.State peerAPIServer *peerAPIServer // or nil @@ -310,7 +311,7 @@ func (b *LocalBackend) updateStatus(sb *ipnstate.StatusBuilder, extraLocked func sb.MutateStatus(func(s *ipnstate.Status) { s.Version = version.Long s.BackendState = b.state.String() - s.AuthURL = b.authURL + s.AuthURL = b.authURLSticky if b.netMap != nil { s.MagicDNSSuffix = b.netMap.MagicDNSSuffix() } @@ -460,6 +461,7 @@ func (b *LocalBackend) setClientStatus(st controlclient.Status) { } if st.URL != "" { b.authURL = st.URL + b.authURLSticky = st.URL } if b.state == ipn.NeedsLogin { if !b.prefs.WantRunning { @@ -1031,7 +1033,7 @@ func (b *LocalBackend) popBrowserAuthNow() { b.mu.Lock() url := b.authURL b.interact = false - b.authURL = "" + b.authURL = "" // but NOT clearing authURLSticky b.mu.Unlock() b.logf("popBrowserAuthNow: url=%v", url != "") @@ -1965,6 +1967,10 @@ func (b *LocalBackend) enterState(newState ipn.State) { networkUp := b.prevIfState.AnyInterfaceUp() activeLogin := b.activeLogin authURL := b.authURL + if newState == ipn.Running { + b.authURL = "" + b.authURLSticky = "" + } b.mu.Unlock() if state == newState { @@ -2116,6 +2122,7 @@ func (b *LocalBackend) ResetForClientDisconnect() { b.setNetMapLocked(nil) b.prefs = new(ipn.Prefs) b.authURL = "" + b.authURLSticky = "" b.activeLogin = "" }