mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
wip
Signed-off-by: Irbe Krumina <irbe@tailscale.com>
This commit is contained in:
parent
e38522c081
commit
d8dda0048e
@ -564,6 +564,12 @@ func (c *Direct) doLogin(ctx context.Context, opt loginOpt) (mustRegen bool, new
|
|||||||
case opt.URL != "":
|
case opt.URL != "":
|
||||||
// Nothing.
|
// Nothing.
|
||||||
case regen || persist.PrivateNodeKey.IsZero():
|
case regen || persist.PrivateNodeKey.IsZero():
|
||||||
|
if regen {
|
||||||
|
c.logf("TEST: need to regenerate")
|
||||||
|
} else {
|
||||||
|
c.logf("TEST: private node key is zero, persist is %v", persist)
|
||||||
|
c.logf("TEST: private node key is zero, persist is %v", persist)
|
||||||
|
}
|
||||||
c.logf("Generating a new nodekey.")
|
c.logf("Generating a new nodekey.")
|
||||||
persist.OldPrivateNodeKey = persist.PrivateNodeKey
|
persist.OldPrivateNodeKey = persist.PrivateNodeKey
|
||||||
tryingNewKey = key.NewNode()
|
tryingNewKey = key.NewNode()
|
||||||
|
@ -1995,6 +1995,7 @@ func (b *LocalBackend) Start(opts ipn.Options) error {
|
|||||||
defer unlock()
|
defer unlock()
|
||||||
|
|
||||||
if opts.UpdatePrefs != nil {
|
if opts.UpdatePrefs != nil {
|
||||||
|
log.Printf("TESTPREFS: update prefs non-nil")
|
||||||
if err := b.checkPrefsLocked(opts.UpdatePrefs); err != nil {
|
if err := b.checkPrefsLocked(opts.UpdatePrefs); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -2061,6 +2062,10 @@ func (b *LocalBackend) Start(opts ipn.Options) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
prefs := b.pm.CurrentPrefs()
|
prefs := b.pm.CurrentPrefs()
|
||||||
|
log.Printf("TESTPREFS persistent prefs: %v", prefs.Persist())
|
||||||
|
if s := prefs.Persist().AsStruct(); s != nil {
|
||||||
|
log.Printf("TESTPREFS persistent prefs private key is %v", s.PrivateNodeKey)
|
||||||
|
}
|
||||||
wantRunning := prefs.WantRunning()
|
wantRunning := prefs.WantRunning()
|
||||||
if wantRunning {
|
if wantRunning {
|
||||||
if err := b.initMachineKeyLocked(); err != nil {
|
if err := b.initMachineKeyLocked(); err != nil {
|
||||||
@ -6778,6 +6783,7 @@ func (b *LocalBackend) CurrentProfile() ipn.LoginProfile {
|
|||||||
|
|
||||||
// NewProfile creates and switches to the new profile.
|
// NewProfile creates and switches to the new profile.
|
||||||
func (b *LocalBackend) NewProfile() error {
|
func (b *LocalBackend) NewProfile() error {
|
||||||
|
log.Printf("TESTPREFS: NewProfile LB")
|
||||||
unlock := b.lockAndGetUnlock()
|
unlock := b.lockAndGetUnlock()
|
||||||
defer unlock()
|
defer unlock()
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"runtime"
|
"runtime"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
@ -203,6 +204,7 @@ func (pm *profileManager) setUnattendedModeAsConfigured() error {
|
|||||||
|
|
||||||
// Reset unloads the current profile, if any.
|
// Reset unloads the current profile, if any.
|
||||||
func (pm *profileManager) Reset() {
|
func (pm *profileManager) Reset() {
|
||||||
|
log.Printf("TESTPREFS: Reset")
|
||||||
pm.currentUserID = ""
|
pm.currentUserID = ""
|
||||||
pm.NewProfile()
|
pm.NewProfile()
|
||||||
}
|
}
|
||||||
@ -215,6 +217,7 @@ func (pm *profileManager) Reset() {
|
|||||||
// is logged into so that we can keep track of things like their domain name
|
// is logged into so that we can keep track of things like their domain name
|
||||||
// across user switches to disambiguate the same account but a different tailnet.
|
// across user switches to disambiguate the same account but a different tailnet.
|
||||||
func (pm *profileManager) SetPrefs(prefsIn ipn.PrefsView, np ipn.NetworkProfile) error {
|
func (pm *profileManager) SetPrefs(prefsIn ipn.PrefsView, np ipn.NetworkProfile) error {
|
||||||
|
log.Printf("TESTPREFS: SetPrefs with prefs %v", prefsIn)
|
||||||
cp := pm.currentProfile
|
cp := pm.currentProfile
|
||||||
if persist := prefsIn.Persist(); !persist.Valid() || persist.NodeID() == "" || persist.UserProfile().LoginName == "" {
|
if persist := prefsIn.Persist(); !persist.Valid() || persist.NodeID() == "" || persist.UserProfile().LoginName == "" {
|
||||||
// We don't know anything about this profile, so ignore it for now.
|
// We don't know anything about this profile, so ignore it for now.
|
||||||
@ -223,6 +226,7 @@ func (pm *profileManager) SetPrefs(prefsIn ipn.PrefsView, np ipn.NetworkProfile)
|
|||||||
|
|
||||||
// Check if we already have an existing profile that matches the user/node.
|
// Check if we already have an existing profile that matches the user/node.
|
||||||
if existing := pm.findMatchingProfiles(prefsIn); len(existing) > 0 {
|
if existing := pm.findMatchingProfiles(prefsIn); len(existing) > 0 {
|
||||||
|
log.Printf("TESTPREFS: SetPrefs found existing profile")
|
||||||
// We already have a profile for this user/node we should reuse it. Also
|
// We already have a profile for this user/node we should reuse it. Also
|
||||||
// cleanup any other duplicate profiles.
|
// cleanup any other duplicate profiles.
|
||||||
cp = existing[0]
|
cp = existing[0]
|
||||||
@ -230,6 +234,7 @@ func (pm *profileManager) SetPrefs(prefsIn ipn.PrefsView, np ipn.NetworkProfile)
|
|||||||
for _, p := range existing {
|
for _, p := range existing {
|
||||||
// Clear the state.
|
// Clear the state.
|
||||||
if err := pm.store.WriteState(p.Key, nil); err != nil {
|
if err := pm.store.WriteState(p.Key, nil); err != nil {
|
||||||
|
log.Printf("TESTPREFS: SetPrefs found existing profile, error writing state: %v", err)
|
||||||
// We couldn't delete the state, so keep the profile around.
|
// We couldn't delete the state, so keep the profile around.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -237,6 +242,8 @@ func (pm *profileManager) SetPrefs(prefsIn ipn.PrefsView, np ipn.NetworkProfile)
|
|||||||
// in [profileManager.setProfilePrefs] below.
|
// in [profileManager.setProfilePrefs] below.
|
||||||
delete(pm.knownProfiles, p.ID)
|
delete(pm.knownProfiles, p.ID)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.Printf("TESTPREFS: SetPrefs not found existing profile")
|
||||||
}
|
}
|
||||||
pm.currentProfile = cp
|
pm.currentProfile = cp
|
||||||
if err := pm.SetProfilePrefs(cp, prefsIn, np); err != nil {
|
if err := pm.SetProfilePrefs(cp, prefsIn, np); err != nil {
|
||||||
@ -327,6 +334,7 @@ func newUnusedID(knownProfiles map[ipn.ProfileID]*ipn.LoginProfile) (ipn.Profile
|
|||||||
// profile, such as verifying the caller's access rights or checking
|
// profile, such as verifying the caller's access rights or checking
|
||||||
// if another profile for the same node already exists.
|
// if another profile for the same node already exists.
|
||||||
func (pm *profileManager) setProfilePrefsNoPermCheck(profile *ipn.LoginProfile, clonedPrefs ipn.PrefsView) error {
|
func (pm *profileManager) setProfilePrefsNoPermCheck(profile *ipn.LoginProfile, clonedPrefs ipn.PrefsView) error {
|
||||||
|
log.Printf("TESTPREFS: setProfilePrefsNoPerm")
|
||||||
isCurrentProfile := pm.currentProfile == profile
|
isCurrentProfile := pm.currentProfile == profile
|
||||||
if isCurrentProfile {
|
if isCurrentProfile {
|
||||||
pm.prefs = clonedPrefs
|
pm.prefs = clonedPrefs
|
||||||
@ -423,6 +431,7 @@ func (pm *profileManager) profilePrefs(p *ipn.LoginProfile) (ipn.PrefsView, erro
|
|||||||
// If the profile exists but is not accessible to the current user, it returns an [errProfileAccessDenied].
|
// If the profile exists but is not accessible to the current user, it returns an [errProfileAccessDenied].
|
||||||
// If the profile does not exist, it returns an [errProfileNotFound].
|
// If the profile does not exist, it returns an [errProfileNotFound].
|
||||||
func (pm *profileManager) SwitchProfile(id ipn.ProfileID) error {
|
func (pm *profileManager) SwitchProfile(id ipn.ProfileID) error {
|
||||||
|
log.Printf("TESTPREFS: SwitchProfile")
|
||||||
metricSwitchProfile.Add(1)
|
metricSwitchProfile.Add(1)
|
||||||
|
|
||||||
kp, ok := pm.knownProfiles[id]
|
kp, ok := pm.knownProfiles[id]
|
||||||
@ -450,6 +459,7 @@ func (pm *profileManager) SwitchProfile(id ipn.ProfileID) error {
|
|||||||
// It creates a new one and switches to it if the current user does not have a default profile,
|
// It creates a new one and switches to it if the current user does not have a default profile,
|
||||||
// or returns an error if the default profile is inaccessible or could not be loaded.
|
// or returns an error if the default profile is inaccessible or could not be loaded.
|
||||||
func (pm *profileManager) SwitchToDefaultProfile() error {
|
func (pm *profileManager) SwitchToDefaultProfile() error {
|
||||||
|
log.Printf("TESTPREFS: SwitchToDefault")
|
||||||
if id := pm.DefaultUserProfileID(pm.currentUserID); id != "" {
|
if id := pm.DefaultUserProfileID(pm.currentUserID); id != "" {
|
||||||
return pm.SwitchProfile(id)
|
return pm.SwitchProfile(id)
|
||||||
}
|
}
|
||||||
@ -547,6 +557,7 @@ func (pm *profileManager) DeleteProfile(id ipn.ProfileID) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pm *profileManager) deleteCurrentProfile() error {
|
func (pm *profileManager) deleteCurrentProfile() error {
|
||||||
|
log.Printf("TESTPREFS: deleteCurrent")
|
||||||
if err := pm.checkProfileAccess(pm.currentProfile); err != nil {
|
if err := pm.checkProfileAccess(pm.currentProfile); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -627,6 +638,7 @@ func (pm *profileManager) NewProfile() {
|
|||||||
// NewProfileForUser is like [profileManager.NewProfile], but it switches to the
|
// NewProfileForUser is like [profileManager.NewProfile], but it switches to the
|
||||||
// specified user and sets that user as the profile owner for the new profile.
|
// specified user and sets that user as the profile owner for the new profile.
|
||||||
func (pm *profileManager) NewProfileForUser(uid ipn.WindowsUserID) {
|
func (pm *profileManager) NewProfileForUser(uid ipn.WindowsUserID) {
|
||||||
|
log.Printf("TESTPREFS: NewProfileForUser")
|
||||||
pm.currentUserID = uid
|
pm.currentUserID = uid
|
||||||
|
|
||||||
metricNewProfile.Add(1)
|
metricNewProfile.Add(1)
|
||||||
@ -641,6 +653,7 @@ func (pm *profileManager) NewProfileForUser(uid ipn.WindowsUserID) {
|
|||||||
// newly created profile immediately. It returns the newly created profile on success,
|
// newly created profile immediately. It returns the newly created profile on success,
|
||||||
// or an error on failure.
|
// or an error on failure.
|
||||||
func (pm *profileManager) newProfileWithPrefs(uid ipn.WindowsUserID, prefs ipn.PrefsView, switchNow bool) (*ipn.LoginProfile, error) {
|
func (pm *profileManager) newProfileWithPrefs(uid ipn.WindowsUserID, prefs ipn.PrefsView, switchNow bool) (*ipn.LoginProfile, error) {
|
||||||
|
log.Printf("TESTPREFS: newProfileWithPrefs")
|
||||||
metricNewProfile.Add(1)
|
metricNewProfile.Add(1)
|
||||||
|
|
||||||
profile := &ipn.LoginProfile{LocalUserID: uid}
|
profile := &ipn.LoginProfile{LocalUserID: uid}
|
||||||
@ -733,6 +746,7 @@ func newProfileManagerWithGOOS(store ipn.StateStore, logf logger.Logf, ht *healt
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
log.Printf("TESTPREFS: newProfileWithGOOS with state key %v", stateKey)
|
||||||
|
|
||||||
knownProfiles, err := readKnownProfiles(store)
|
knownProfiles, err := readKnownProfiles(store)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -748,12 +762,15 @@ func newProfileManagerWithGOOS(store ipn.StateStore, logf logger.Logf, ht *healt
|
|||||||
}
|
}
|
||||||
|
|
||||||
if stateKey != "" {
|
if stateKey != "" {
|
||||||
|
log.Printf("TESTPREFS: state key %v exists", stateKey)
|
||||||
for _, v := range knownProfiles {
|
for _, v := range knownProfiles {
|
||||||
|
log.Printf("TESTPREFS: state key %v exists looking at matching profile %s", stateKey, v)
|
||||||
if v.Key == stateKey {
|
if v.Key == stateKey {
|
||||||
pm.currentProfile = v
|
pm.currentProfile = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if pm.currentProfile == nil {
|
if pm.currentProfile == nil {
|
||||||
|
log.Printf("TESTPREFS: current profile is nil")
|
||||||
if suf, ok := strings.CutPrefix(string(stateKey), "user-"); ok {
|
if suf, ok := strings.CutPrefix(string(stateKey), "user-"); ok {
|
||||||
pm.currentUserID = ipn.WindowsUserID(suf)
|
pm.currentUserID = ipn.WindowsUserID(suf)
|
||||||
}
|
}
|
||||||
@ -776,12 +793,14 @@ func newProfileManagerWithGOOS(store ipn.StateStore, logf logger.Logf, ht *healt
|
|||||||
// uid passed in from the unix tests. The uid's used for Windows tests
|
// uid passed in from the unix tests. The uid's used for Windows tests
|
||||||
// and runtime must be valid Windows security identifier structures.
|
// and runtime must be valid Windows security identifier structures.
|
||||||
} else if len(knownProfiles) == 0 && goos != "windows" && runtime.GOOS != "windows" {
|
} else if len(knownProfiles) == 0 && goos != "windows" && runtime.GOOS != "windows" {
|
||||||
|
log.Printf("TESTPREFS: no known profiles")
|
||||||
// No known profiles, try a migration.
|
// No known profiles, try a migration.
|
||||||
pm.dlogf("no known profiles; trying to migrate from legacy prefs")
|
pm.dlogf("no known profiles; trying to migrate from legacy prefs")
|
||||||
if _, err := pm.migrateFromLegacyPrefs(pm.currentUserID, true); err != nil {
|
if _, err := pm.migrateFromLegacyPrefs(pm.currentUserID, true); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
log.Printf("TESTPREFS: newProfileWithGOOS new profile")
|
||||||
pm.NewProfile()
|
pm.NewProfile()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@ -142,6 +143,7 @@ func (s *Store) loadState() error {
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Printf("TEST: kube store: got secret: %#+v", secret.Data)
|
||||||
s.memory.LoadFromMap(secret.Data)
|
s.memory.LoadFromMap(secret.Data)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"log"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
xmaps "golang.org/x/exp/maps"
|
xmaps "golang.org/x/exp/maps"
|
||||||
@ -32,18 +33,21 @@ func (s *Store) String() string { return "mem.Store" }
|
|||||||
// ReadState implements the StateStore interface.
|
// ReadState implements the StateStore interface.
|
||||||
// It returns ipn.ErrStateNotExist if the state does not exist.
|
// It returns ipn.ErrStateNotExist if the state does not exist.
|
||||||
func (s *Store) ReadState(id ipn.StateKey) ([]byte, error) {
|
func (s *Store) ReadState(id ipn.StateKey) ([]byte, error) {
|
||||||
|
log.Printf("TEST: ReadState key %v ", id)
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
bs, ok := s.cache[id]
|
bs, ok := s.cache[id]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, ipn.ErrStateNotExist
|
return nil, ipn.ErrStateNotExist
|
||||||
}
|
}
|
||||||
|
log.Printf("TEST: ReadState key %v val %v", id, string(bs))
|
||||||
return bs, nil
|
return bs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteState implements the StateStore interface.
|
// WriteState implements the StateStore interface.
|
||||||
// It never returns an error.
|
// It never returns an error.
|
||||||
func (s *Store) WriteState(id ipn.StateKey, bs []byte) error {
|
func (s *Store) WriteState(id ipn.StateKey, bs []byte) error {
|
||||||
|
log.Printf("TEST: WriteState key %v ", id)
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
if s.cache == nil {
|
if s.cache == nil {
|
||||||
@ -57,10 +61,12 @@ func (s *Store) WriteState(id ipn.StateKey, bs []byte) error {
|
|||||||
// Any existing content is cleared, and the provided map is
|
// Any existing content is cleared, and the provided map is
|
||||||
// copied into the cache.
|
// copied into the cache.
|
||||||
func (s *Store) LoadFromMap(m map[string][]byte) {
|
func (s *Store) LoadFromMap(m map[string][]byte) {
|
||||||
|
log.Printf("Store: LoadFromMap")
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
xmaps.Clear(s.cache)
|
xmaps.Clear(s.cache)
|
||||||
for k, v := range m {
|
for k, v := range m {
|
||||||
|
log.Printf("TEST: setting state key %v %+#v", k, string(v))
|
||||||
mak.Set(&s.cache, ipn.StateKey(k), v)
|
mak.Set(&s.cache, ipn.StateKey(k), v)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user