WIP: add session ownership

This commit is contained in:
Theodor S. Midtlien
2026-09-03 11:50:21 +02:00
parent fbd4730f0b
commit 34f78b5119
4 changed files with 110 additions and 1 deletions
+21
View File
@@ -35,6 +35,7 @@ import (
"github.com/netbirdio/netbird/shared/management/domain"
"github.com/netbirdio/netbird/client/internal"
"github.com/netbirdio/netbird/client/internal/ipcauth"
"github.com/netbirdio/netbird/client/internal/peer"
"github.com/netbirdio/netbird/client/internal/statemanager"
"github.com/netbirdio/netbird/client/internal/updater"
@@ -148,6 +149,8 @@ type Server struct {
loginAttemptFn func(ctx context.Context, setupKey, jwtToken string) (internal.StatusType, error)
isLoginRequiredFn func(ctx context.Context) (bool, error)
sessionHolder ipcauth.Identity
}
type oauthAuthFlow struct {
@@ -1083,6 +1086,14 @@ func (s *Server) Up(callerCtx context.Context, msg *proto.UpRequest) (*proto.UpR
s.statusRecorder.UpdateRosenpass(s.config.RosenpassEnabled, s.config.RosenpassPermissive)
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.clientRunningChan = make(chan struct{})
s.clientGiveUpChan = make(chan struct{})
@@ -1332,6 +1343,7 @@ func (s *Server) cleanupConnection() error {
// explicitly asked for it. MDM restart does NOT go through this
// path, so its clientRunning stays true.
s.clientRunning = false
s.sessionHolder = ipcauth.Identity{}
// Capture the engine reference before cancelling the context.
// After actCancel(), the connectWithRetryRuns goroutine wakes up
@@ -2695,6 +2707,15 @@ func (s *Server) authorizeAndPrepareLogin(callerCtx context.Context, msg *proto.
return ctx, activeProf, nil
}
func (s *Server) SessionHolder() (ipcauth.Identity, bool) {
s.mutex.Lock()
defer s.mutex.Unlock()
if !s.clientRunning {
return ipcauth.Identity{}, false
}
return s.sessionHolder, true
}
func persistLoginOverrides(activeProf *profilemanager.ActiveProfileState, managementURL string, preSharedKey *string) error {
if preSharedKey != nil && *preSharedKey == "" {
preSharedKey = nil