diff --git a/cmd/tailscaled/tailscaled.go b/cmd/tailscaled/tailscaled.go index 67233f767..88686ea50 100644 --- a/cmd/tailscaled/tailscaled.go +++ b/cmd/tailscaled/tailscaled.go @@ -520,7 +520,7 @@ func getLocalBackend(ctx context.Context, logf logger.Logf, logid string) (_ *ip return nil, fmt.Errorf("store.New: %w", err) } - lb, err := ipnlocal.NewLocalBackend(logf, logid, store, "", dialer, e, opts.LoginFlags) + lb, err := ipnlocal.NewLocalBackend(logf, logid, store, dialer, e, opts.LoginFlags) if err != nil { return nil, fmt.Errorf("ipnlocal.NewLocalBackend: %w", err) } diff --git a/cmd/tsconnect/wasm/wasm_js.go b/cmd/tsconnect/wasm/wasm_js.go index e070197a3..2a27ca421 100644 --- a/cmd/tsconnect/wasm/wasm_js.go +++ b/cmd/tsconnect/wasm/wasm_js.go @@ -124,7 +124,7 @@ func newIPN(jsConfig js.Value) map[string]any { logid := lpc.PublicID.String() srv := ipnserver.New(logf, logid) - lb, err := ipnlocal.NewLocalBackend(logf, logid, store, "", dialer, eng, controlclient.LoginEphemeral) + lb, err := ipnlocal.NewLocalBackend(logf, logid, store, dialer, eng, controlclient.LoginEphemeral) if err != nil { log.Fatalf("ipnlocal.NewLocalBackend: %v", err) } diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 4bbd97876..92cd01048 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -243,12 +243,12 @@ type clientGen func(controlclient.Options) (controlclient.Client, error) // but is not actually running. // // If dialer is nil, a new one is made. -func NewLocalBackend(logf logger.Logf, logid string, store ipn.StateStore, stateKey ipn.StateKey, dialer *tsdial.Dialer, e wgengine.Engine, loginFlags controlclient.LoginFlags) (*LocalBackend, error) { +func NewLocalBackend(logf logger.Logf, logid string, store ipn.StateStore, dialer *tsdial.Dialer, e wgengine.Engine, loginFlags controlclient.LoginFlags) (*LocalBackend, error) { if e == nil { panic("ipn.NewLocalBackend: engine must not be nil") } - pm, err := newProfileManager(store, logf, stateKey) + pm, err := newProfileManager(store, logf) if err != nil { return nil, err } diff --git a/ipn/ipnlocal/local_test.go b/ipn/ipnlocal/local_test.go index dd6f43636..4f1f017b3 100644 --- a/ipn/ipnlocal/local_test.go +++ b/ipn/ipnlocal/local_test.go @@ -491,7 +491,7 @@ func TestLazyMachineKeyGeneration(t *testing.T) { t.Fatalf("NewFakeUserspaceEngine: %v", err) } t.Cleanup(eng.Close) - lb, err := NewLocalBackend(logf, "logid", store, "default", nil, eng, 0) + lb, err := NewLocalBackend(logf, "logid", store, nil, eng, 0) if err != nil { t.Fatalf("NewLocalBackend: %v", err) } @@ -755,7 +755,7 @@ func TestStatusWithoutPeers(t *testing.T) { } t.Cleanup(e.Close) - b, err := NewLocalBackend(logf, "logid", store, "", nil, e, 0) + b, err := NewLocalBackend(logf, "logid", store, nil, e, 0) if err != nil { t.Fatalf("NewLocalBackend: %v", err) } diff --git a/ipn/ipnlocal/loglines_test.go b/ipn/ipnlocal/loglines_test.go index 52a64136e..8e4bfdec6 100644 --- a/ipn/ipnlocal/loglines_test.go +++ b/ipn/ipnlocal/loglines_test.go @@ -54,7 +54,7 @@ func TestLocalLogLines(t *testing.T) { } t.Cleanup(e.Close) - lb, err := NewLocalBackend(logf, idA.String(), store, "", nil, e, 0) + lb, err := NewLocalBackend(logf, idA.String(), store, nil, e, 0) if err != nil { t.Fatal(err) } diff --git a/ipn/ipnlocal/network-lock_test.go b/ipn/ipnlocal/network-lock_test.go index 0d555be43..daf1d0d06 100644 --- a/ipn/ipnlocal/network-lock_test.go +++ b/ipn/ipnlocal/network-lock_test.go @@ -141,7 +141,7 @@ func TestTKAEnablementFlow(t *testing.T) { temp := t.TempDir() cc := fakeControlClient(t, client) - pm := must.Get(newProfileManager(new(mem.Store), t.Logf, "")) + pm := must.Get(newProfileManager(new(mem.Store), t.Logf)) must.Do(pm.SetPrefs((&ipn.Prefs{ Persist: &persist.Persist{ PrivateNodeKey: nodePriv, @@ -182,7 +182,7 @@ func TestTKADisablementFlow(t *testing.T) { nlPriv := key.NewNLPrivate() key := tka.Key{Kind: tka.Key25519, Public: nlPriv.Public().Verifier(), Votes: 2} - pm := must.Get(newProfileManager(new(mem.Store), t.Logf, "")) + pm := must.Get(newProfileManager(new(mem.Store), t.Logf)) must.Do(pm.SetPrefs((&ipn.Prefs{ Persist: &persist.Persist{ PrivateNodeKey: nodePriv, @@ -377,7 +377,7 @@ func TestTKASync(t *testing.T) { t.Run(tc.name, func(t *testing.T) { nodePriv := key.NewNode() nlPriv := key.NewNLPrivate() - pm := must.Get(newProfileManager(new(mem.Store), t.Logf, "")) + pm := must.Get(newProfileManager(new(mem.Store), t.Logf)) must.Do(pm.SetPrefs((&ipn.Prefs{ Persist: &persist.Persist{ PrivateNodeKey: nodePriv, @@ -604,7 +604,7 @@ func TestTKADisable(t *testing.T) { disablementSecret := bytes.Repeat([]byte{0xa5}, 32) nlPriv := key.NewNLPrivate() - pm := must.Get(newProfileManager(new(mem.Store), t.Logf, "")) + pm := must.Get(newProfileManager(new(mem.Store), t.Logf)) must.Do(pm.SetPrefs((&ipn.Prefs{ Persist: &persist.Persist{ PrivateNodeKey: nodePriv, @@ -697,7 +697,7 @@ func TestTKASign(t *testing.T) { toSign := key.NewNode() nlPriv := key.NewNLPrivate() - pm := must.Get(newProfileManager(new(mem.Store), t.Logf, "")) + pm := must.Get(newProfileManager(new(mem.Store), t.Logf)) must.Do(pm.SetPrefs((&ipn.Prefs{ Persist: &persist.Persist{ PrivateNodeKey: nodePriv, @@ -788,7 +788,7 @@ func TestTKAForceDisable(t *testing.T) { nlPriv := key.NewNLPrivate() key := tka.Key{Kind: tka.Key25519, Public: nlPriv.Public().Verifier(), Votes: 2} - pm := must.Get(newProfileManager(new(mem.Store), t.Logf, "")) + pm := must.Get(newProfileManager(new(mem.Store), t.Logf)) must.Do(pm.SetPrefs((&ipn.Prefs{ Persist: &persist.Persist{ PrivateNodeKey: nodePriv, diff --git a/ipn/ipnlocal/peerapi_test.go b/ipn/ipnlocal/peerapi_test.go index f6d5b8c23..98e40e9c8 100644 --- a/ipn/ipnlocal/peerapi_test.go +++ b/ipn/ipnlocal/peerapi_test.go @@ -642,7 +642,7 @@ func TestPeerAPIReplyToDNSQueries(t *testing.T) { h.remoteAddr = netip.MustParseAddrPort("100.150.151.152:12345") eng, _ := wgengine.NewFakeUserspaceEngine(logger.Discard, 0) - pm := must.Get(newProfileManager(new(mem.Store), t.Logf, "")) + pm := must.Get(newProfileManager(new(mem.Store), t.Logf)) h.ps = &peerAPIServer{ b: &LocalBackend{ e: eng, diff --git a/ipn/ipnlocal/profiles.go b/ipn/ipnlocal/profiles.go index 556d490fb..55df0b60d 100644 --- a/ipn/ipnlocal/profiles.go +++ b/ipn/ipnlocal/profiles.go @@ -452,7 +452,7 @@ func (pm *profileManager) CurrentPrefs() ipn.PrefsView { // ReadStartupPrefsForTest reads the startup prefs from disk. It is only used for testing. func ReadStartupPrefsForTest(logf logger.Logf, store ipn.StateStore) (ipn.PrefsView, error) { - pm, err := newProfileManager(store, logf, "") + pm, err := newProfileManager(store, logf) if err != nil { return ipn.PrefsView{}, err } @@ -461,9 +461,8 @@ func ReadStartupPrefsForTest(logf logger.Logf, store ipn.StateStore) (ipn.PrefsV // newProfileManager creates a new ProfileManager using the provided StateStore. // It also loads the list of known profiles from the StateStore. -// If a state key is provided, it will be used to load the current profile. -func newProfileManager(store ipn.StateStore, logf logger.Logf, stateKey ipn.StateKey) (*profileManager, error) { - return newProfileManagerWithGOOS(store, logf, stateKey, envknob.GOOS()) +func newProfileManager(store ipn.StateStore, logf logger.Logf) (*profileManager, error) { + return newProfileManagerWithGOOS(store, logf, envknob.GOOS()) } func readAutoStartKey(store ipn.StateStore, goos string) (ipn.StateKey, error) { @@ -496,14 +495,11 @@ func readKnownProfiles(store ipn.StateStore) (map[ipn.ProfileID]*ipn.LoginProfil return knownProfiles, nil } -func newProfileManagerWithGOOS(store ipn.StateStore, logf logger.Logf, stateKey ipn.StateKey, goos string) (*profileManager, error) { +func newProfileManagerWithGOOS(store ipn.StateStore, logf logger.Logf, goos string) (*profileManager, error) { logf = logger.WithPrefix(logf, "pm: ") - if stateKey == "" { - var err error - stateKey, err = readAutoStartKey(store, goos) - if err != nil { - return nil, err - } + stateKey, err := readAutoStartKey(store, goos) + if err != nil { + return nil, err } knownProfiles, err := readKnownProfiles(store) diff --git a/ipn/ipnlocal/profiles_test.go b/ipn/ipnlocal/profiles_test.go index dcaf463e9..aff075274 100644 --- a/ipn/ipnlocal/profiles_test.go +++ b/ipn/ipnlocal/profiles_test.go @@ -18,7 +18,7 @@ import ( func TestProfileCurrentUserSwitch(t *testing.T) { store := new(mem.Store) - pm, err := newProfileManagerWithGOOS(store, logger.Discard, "", "linux") + pm, err := newProfileManagerWithGOOS(store, logger.Discard, "linux") if err != nil { t.Fatal(err) } @@ -56,7 +56,7 @@ func TestProfileCurrentUserSwitch(t *testing.T) { t.Fatalf("CurrentPrefs() = %v, want emptyPrefs", pm.CurrentPrefs().Pretty()) } - pm, err = newProfileManagerWithGOOS(store, logger.Discard, "", "linux") + pm, err = newProfileManagerWithGOOS(store, logger.Discard, "linux") if err != nil { t.Fatal(err) } @@ -74,7 +74,7 @@ func TestProfileCurrentUserSwitch(t *testing.T) { func TestProfileList(t *testing.T) { store := new(mem.Store) - pm, err := newProfileManagerWithGOOS(store, logger.Discard, "", "linux") + pm, err := newProfileManagerWithGOOS(store, logger.Discard, "linux") if err != nil { t.Fatal(err) } @@ -152,7 +152,7 @@ func TestProfileList(t *testing.T) { func TestProfileManagement(t *testing.T) { store := new(mem.Store) - pm, err := newProfileManagerWithGOOS(store, logger.Discard, "", "linux") + pm, err := newProfileManagerWithGOOS(store, logger.Discard, "linux") if err != nil { t.Fatal(err) } @@ -250,7 +250,7 @@ func TestProfileManagement(t *testing.T) { t.Logf("Recreate profile manager from store") // Recreate the profile manager to ensure that it can load the profiles // from the store at startup. - pm, err = newProfileManagerWithGOOS(store, logger.Discard, "", "linux") + pm, err = newProfileManagerWithGOOS(store, logger.Discard, "linux") if err != nil { t.Fatal(err) } @@ -266,7 +266,7 @@ func TestProfileManagement(t *testing.T) { t.Logf("Recreate profile manager from store after deleting default profile") // Recreate the profile manager to ensure that it can load the profiles // from the store at startup. - pm, err = newProfileManagerWithGOOS(store, logger.Discard, "", "linux") + pm, err = newProfileManagerWithGOOS(store, logger.Discard, "linux") if err != nil { t.Fatal(err) } @@ -303,7 +303,7 @@ func TestProfileManagement(t *testing.T) { func TestProfileManagementWindows(t *testing.T) { store := new(mem.Store) - pm, err := newProfileManagerWithGOOS(store, logger.Discard, "", "windows") + pm, err := newProfileManagerWithGOOS(store, logger.Discard, "windows") if err != nil { t.Fatal(err) } @@ -374,7 +374,7 @@ func TestProfileManagementWindows(t *testing.T) { t.Logf("Recreate profile manager from store, should reset prefs") // Recreate the profile manager to ensure that it can load the profiles // from the store at startup. - pm, err = newProfileManagerWithGOOS(store, logger.Discard, "", "windows") + pm, err = newProfileManagerWithGOOS(store, logger.Discard, "windows") if err != nil { t.Fatal(err) } @@ -399,7 +399,7 @@ func TestProfileManagementWindows(t *testing.T) { } // Recreate the profile manager to ensure that it starts with test profile. - pm, err = newProfileManagerWithGOOS(store, logger.Discard, "", "windows") + pm, err = newProfileManagerWithGOOS(store, logger.Discard, "windows") if err != nil { t.Fatal(err) } diff --git a/ipn/ipnlocal/ssh_test.go b/ipn/ipnlocal/ssh_test.go index 837924965..c4fe992c7 100644 --- a/ipn/ipnlocal/ssh_test.go +++ b/ipn/ipnlocal/ssh_test.go @@ -49,7 +49,7 @@ type fakeSSHServer struct { } func TestGetSSHUsernames(t *testing.T) { - pm := must.Get(newProfileManager(new(mem.Store), t.Logf, "")) + pm := must.Get(newProfileManager(new(mem.Store), t.Logf)) b := &LocalBackend{pm: pm, store: pm.Store()} b.sshServer = fakeSSHServer{} res, err := b.getSSHUsernames(new(tailcfg.C2NSSHUsernamesRequest)) diff --git a/ipn/ipnlocal/state_test.go b/ipn/ipnlocal/state_test.go index 39af2c63f..980c69dfc 100644 --- a/ipn/ipnlocal/state_test.go +++ b/ipn/ipnlocal/state_test.go @@ -303,7 +303,7 @@ func TestStateMachine(t *testing.T) { } t.Cleanup(e.Close) - b, err := NewLocalBackend(logf, "logid", store, "", nil, e, 0) + b, err := NewLocalBackend(logf, "logid", store, nil, e, 0) if err != nil { t.Fatalf("NewLocalBackend: %v", err) } @@ -943,7 +943,7 @@ func TestEditPrefsHasNoKeys(t *testing.T) { } t.Cleanup(e.Close) - b, err := NewLocalBackend(logf, "logid", new(mem.Store), "", nil, e, 0) + b, err := NewLocalBackend(logf, "logid", new(mem.Store), nil, e, 0) if err != nil { t.Fatalf("NewLocalBackend: %v", err) } @@ -1022,7 +1022,7 @@ func TestWGEngineStatusRace(t *testing.T) { eng, err := wgengine.NewFakeUserspaceEngine(logf, 0) c.Assert(err, qt.IsNil) t.Cleanup(eng.Close) - b, err := NewLocalBackend(logf, "logid", new(mem.Store), "", nil, eng, 0) + b, err := NewLocalBackend(logf, "logid", new(mem.Store), nil, eng, 0) c.Assert(err, qt.IsNil) var cc *mockControl diff --git a/ssh/tailssh/tailssh_test.go b/ssh/tailssh/tailssh_test.go index 2c0710003..9cb8a4148 100644 --- a/ssh/tailssh/tailssh_test.go +++ b/ssh/tailssh/tailssh_test.go @@ -507,7 +507,7 @@ func TestSSH(t *testing.T) { t.Fatal(err) } lb, err := ipnlocal.NewLocalBackend(logf, "", - new(mem.Store), "", + new(mem.Store), new(tsdial.Dialer), eng, 0) if err != nil { diff --git a/tsnet/tsnet.go b/tsnet/tsnet.go index a905a4d64..d6750d75d 100644 --- a/tsnet/tsnet.go +++ b/tsnet/tsnet.go @@ -338,7 +338,7 @@ func (s *Server) start() (reterr error) { if s.Ephemeral { loginFlags = controlclient.LoginEphemeral } - lb, err := ipnlocal.NewLocalBackend(logf, logid, s.Store, "", s.dialer, eng, loginFlags) + lb, err := ipnlocal.NewLocalBackend(logf, logid, s.Store, s.dialer, eng, loginFlags) if err != nil { return fmt.Errorf("NewLocalBackend: %v", err) } diff --git a/wgengine/netstack/netstack_test.go b/wgengine/netstack/netstack_test.go index b229396ba..b8f2eab0e 100644 --- a/wgengine/netstack/netstack_test.go +++ b/wgengine/netstack/netstack_test.go @@ -49,7 +49,7 @@ func TestInjectInboundLeak(t *testing.T) { t.Fatal("failed to get internals") } - lb, err := ipnlocal.NewLocalBackend(logf, "logid", new(mem.Store), "", dialer, eng, 0) + lb, err := ipnlocal.NewLocalBackend(logf, "logid", new(mem.Store), dialer, eng, 0) if err != nil { t.Fatal(err) } @@ -113,7 +113,7 @@ func makeNetstack(t *testing.T, config func(*Impl)) *Impl { } t.Cleanup(func() { ns.Close() }) - lb, err := ipnlocal.NewLocalBackend(logf, "logid", new(mem.Store), "", dialer, eng, 0) + lb, err := ipnlocal.NewLocalBackend(logf, "logid", new(mem.Store), dialer, eng, 0) if err != nil { t.Fatalf("NewLocalBackend: %v", err) }