mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-27 06:49:07 +01:00
Let active profile owner be the source of truth for the session holder
This commit is contained in:
@@ -578,7 +578,7 @@ func readProfileName(path string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// nolint: unused,unusedfunc
|
// nolint: unused,unusedfunc
|
||||||
func readProfileOwner(path string) (ipcauth.Identity, error) {
|
func ReadProfileOwner(path string) (ipcauth.Identity, error) {
|
||||||
data, err := os.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ipcauth.Identity{}, err
|
return ipcauth.Identity{}, err
|
||||||
@@ -603,7 +603,7 @@ func readProfileOwner(path string) (ipcauth.Identity, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// nolint: unused,unusedfunc
|
// nolint: unused,unusedfunc
|
||||||
func stampOwner(path string, owner ipcauth.Identity) error {
|
func StampOwner(path string, owner ipcauth.Identity) error {
|
||||||
data, err := os.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
+18
-13
@@ -157,8 +157,6 @@ type Server struct {
|
|||||||
loginAttemptFn func(ctx context.Context, setupKey, jwtToken string) (internal.StatusType, error)
|
loginAttemptFn func(ctx context.Context, setupKey, jwtToken string) (internal.StatusType, error)
|
||||||
|
|
||||||
isLoginRequiredFn func(ctx context.Context) (bool, error)
|
isLoginRequiredFn func(ctx context.Context) (bool, error)
|
||||||
|
|
||||||
sessionHolder *ipcauth.Identity
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type oauthAuthFlow struct {
|
type oauthAuthFlow struct {
|
||||||
@@ -1100,14 +1098,6 @@ func (s *Server) Up(callerCtx context.Context, msg *proto.UpRequest) (*proto.UpR
|
|||||||
s.statusRecorder.UpdateRosenpass(s.config.RosenpassEnabled, s.config.RosenpassPermissive)
|
s.statusRecorder.UpdateRosenpass(s.config.RosenpassEnabled, s.config.RosenpassPermissive)
|
||||||
s.localMetrics.Reconcile(s.config.LocalMetricsEnabled, s.config.LocalMetricsAddress)
|
s.localMetrics.Reconcile(s.config.LocalMetricsEnabled, s.config.LocalMetricsAddress)
|
||||||
|
|
||||||
id, ok := ipcauth.CallerIdentity(callerCtx)
|
|
||||||
if !ok {
|
|
||||||
s.mutex.Unlock()
|
|
||||||
return nil, fmt.Errorf("failed to get identity")
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Infof("setting session holder: %d", id.UID)
|
|
||||||
s.sessionHolder = &id
|
|
||||||
s.clientRunning = true
|
s.clientRunning = true
|
||||||
s.clientRunningChan = make(chan struct{})
|
s.clientRunningChan = make(chan struct{})
|
||||||
s.clientGiveUpChan = make(chan struct{})
|
s.clientGiveUpChan = make(chan struct{})
|
||||||
@@ -1357,7 +1347,6 @@ func (s *Server) cleanupConnection() error {
|
|||||||
// explicitly asked for it. MDM restart does NOT go through this
|
// explicitly asked for it. MDM restart does NOT go through this
|
||||||
// path, so its clientRunning stays true.
|
// path, so its clientRunning stays true.
|
||||||
s.clientRunning = false
|
s.clientRunning = false
|
||||||
s.sessionHolder = nil
|
|
||||||
|
|
||||||
// Capture the engine reference before cancelling the context.
|
// Capture the engine reference before cancelling the context.
|
||||||
// After actCancel(), the connectWithRetryRuns goroutine wakes up
|
// After actCancel(), the connectWithRetryRuns goroutine wakes up
|
||||||
@@ -2739,13 +2728,29 @@ func (s *Server) authorizeAndPrepareLogin(callerCtx context.Context, msg *proto.
|
|||||||
return ctx, activeProf, nil
|
return ctx, activeProf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SessionHolder returns the Identity that owns the active and connected
|
||||||
|
// profile. The boolean indicates if the session is connected and an owner
|
||||||
|
// is defined in the config.
|
||||||
func (s *Server) SessionHolder() (ipcauth.Identity, bool) {
|
func (s *Server) SessionHolder() (ipcauth.Identity, bool) {
|
||||||
s.mutex.Lock()
|
s.mutex.Lock()
|
||||||
defer s.mutex.Unlock()
|
defer s.mutex.Unlock()
|
||||||
if !s.clientRunning || s.sessionHolder == nil {
|
activeOwners := s.config.Owners
|
||||||
|
|
||||||
|
if !s.clientRunning || len(activeOwners) < 1 {
|
||||||
return ipcauth.Identity{}, false
|
return ipcauth.Identity{}, false
|
||||||
}
|
}
|
||||||
return *s.sessionHolder, true
|
|
||||||
|
principal, ok := ipcauth.ParsePrincipal(activeOwners[0])
|
||||||
|
if !ok {
|
||||||
|
return ipcauth.Identity{}, false
|
||||||
|
}
|
||||||
|
|
||||||
|
id, err := ipcauth.IdentityFromPrincipal(principal)
|
||||||
|
if err != nil {
|
||||||
|
return ipcauth.Identity{}, false
|
||||||
|
}
|
||||||
|
|
||||||
|
return id, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func persistLoginOverrides(activeProf *profilemanager.ActiveProfileState, managementURL string, preSharedKey *string) error {
|
func persistLoginOverrides(activeProf *profilemanager.ActiveProfileState, managementURL string, preSharedKey *string) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user