ipn/ipnlocal: make StartLoginInteractive take (yet unused) context

In prep for future fix to undermentioned issue.

Updates tailscale/tailscale#7036

Change-Id: Ide114db917dcba43719482ffded6a9a54630d99e
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2024-04-15 15:05:50 -07:00 committed by Brad Fitzpatrick
parent 9171b217ba
commit 7ec0dc3834
6 changed files with 15 additions and 16 deletions

View File

@ -322,7 +322,7 @@ func (i *jsIPN) run(jsCallbacks js.Value) {
} }
func (i *jsIPN) login() { func (i *jsIPN) login() {
go i.lb.StartLoginInteractive() go i.lb.StartLoginInteractive(context.Background())
} }
func (i *jsIPN) logout() { func (i *jsIPN) logout() {

View File

@ -2834,11 +2834,11 @@ func (b *LocalBackend) tryLookupUserName(uid string) string {
return u.Username return u.Username
} }
// StartLoginInteractive implements Backend. It requests a new // StartLoginInteractive requests a new interactive login from controlclient,
// interactive login from controlclient, unless such a flow is already // unless such a flow is already in progress, in which case
// in progress, in which case StartLoginInteractive attempts to pick // StartLoginInteractive attempts to pick up the in-progress flow where it left
// up the in-progress flow where it left off. // off.
func (b *LocalBackend) StartLoginInteractive() { func (b *LocalBackend) StartLoginInteractive(ctx context.Context) error {
b.mu.Lock() b.mu.Lock()
if b.cc == nil { if b.cc == nil {
panic("LocalBackend.assertClient: b.cc == nil") panic("LocalBackend.assertClient: b.cc == nil")
@ -2858,6 +2858,7 @@ func (b *LocalBackend) StartLoginInteractive() {
} else { } else {
cc.Login(nil, b.loginFlags|controlclient.LoginInteractive) cc.Login(nil, b.loginFlags|controlclient.LoginInteractive)
} }
return nil
} }
func (b *LocalBackend) Ping(ctx context.Context, ip netip.Addr, pingType tailcfg.PingType, size int) (*ipnstate.PingResult, error) { func (b *LocalBackend) Ping(ctx context.Context, ip netip.Addr, pingType tailcfg.PingType, size int) (*ipnstate.PingResult, error) {

View File

@ -862,10 +862,6 @@ type legacyBackend interface {
// Start starts or restarts the backend, typically when a // Start starts or restarts the backend, typically when a
// frontend client connects. // frontend client connects.
Start(ipn.Options) error Start(ipn.Options) error
// StartLoginInteractive requests to start a new interactive login
// flow. This should trigger a new BrowseToURL notification
// eventually.
StartLoginInteractive()
} }
// Verify that LocalBackend still implements the legacyBackend interface // Verify that LocalBackend still implements the legacyBackend interface

View File

@ -441,7 +441,7 @@ func TestStateMachine(t *testing.T) {
// indicating that the UI should browse to the given URL. // indicating that the UI should browse to the given URL.
t.Logf("\n\nLogin (interactive)") t.Logf("\n\nLogin (interactive)")
notifies.expect(1) notifies.expect(1)
b.StartLoginInteractive() b.StartLoginInteractive(context.Background())
{ {
nn := notifies.drain(1) nn := notifies.drain(1)
cc.assertCalls() cc.assertCalls()
@ -457,7 +457,7 @@ func TestStateMachine(t *testing.T) {
// we must always get a *new* login URL first. // we must always get a *new* login URL first.
t.Logf("\n\nLogin2 (interactive)") t.Logf("\n\nLogin2 (interactive)")
notifies.expect(0) notifies.expect(0)
b.StartLoginInteractive() b.StartLoginInteractive(context.Background())
{ {
notifies.drain(0) notifies.drain(0)
// backend asks control for another login sequence // backend asks control for another login sequence
@ -677,7 +677,7 @@ func TestStateMachine(t *testing.T) {
c.Assert(ipn.NeedsLogin, qt.Equals, b.State()) c.Assert(ipn.NeedsLogin, qt.Equals, b.State())
} }
b.StartLoginInteractive() b.StartLoginInteractive(context.Background())
t.Logf("\n\nLoginFinished3") t.Logf("\n\nLoginFinished3")
notifies.expect(3) notifies.expect(3)
cc.persist.UserProfile.LoginName = "user2" cc.persist.UserProfile.LoginName = "user2"
@ -800,7 +800,7 @@ func TestStateMachine(t *testing.T) {
ControlURL: "https://localhost:1/", ControlURL: "https://localhost:1/",
}, },
}) })
b.StartLoginInteractive() b.StartLoginInteractive(context.Background())
url3 := "https://localhost:1/3" url3 := "https://localhost:1/3"
cc.send(nil, url3, false, nil) cc.send(nil, url3, false, nil)
{ {

View File

@ -1306,7 +1306,7 @@ func (h *Handler) serveLoginInteractive(w http.ResponseWriter, r *http.Request)
http.Error(w, "want POST", http.StatusBadRequest) http.Error(w, "want POST", http.StatusBadRequest)
return return
} }
h.b.StartLoginInteractive() h.b.StartLoginInteractive(r.Context())
w.WriteHeader(http.StatusNoContent) w.WriteHeader(http.StatusNoContent)
return return
} }

View File

@ -597,7 +597,9 @@ func (s *Server) start() (reterr error) {
st := lb.State() st := lb.State()
if st == ipn.NeedsLogin || envknob.Bool("TSNET_FORCE_LOGIN") { if st == ipn.NeedsLogin || envknob.Bool("TSNET_FORCE_LOGIN") {
logf("LocalBackend state is %v; running StartLoginInteractive...", st) logf("LocalBackend state is %v; running StartLoginInteractive...", st)
s.lb.StartLoginInteractive() if err := s.lb.StartLoginInteractive(s.shutdownCtx); err != nil {
return fmt.Errorf("StartLoginInteractive: %w", err)
}
} else if authKey != "" { } else if authKey != "" {
logf("Authkey is set; but state is %v. Ignoring authkey. Re-run with TSNET_FORCE_LOGIN=1 to force use of authkey.", st) logf("Authkey is set; but state is %v. Ignoring authkey. Re-run with TSNET_FORCE_LOGIN=1 to force use of authkey.", st)
} }