WIP: add session ownership

This commit is contained in:
Theodor S. Midtlien
2026-09-16 10:36:43 +02:00
parent eab510178a
commit f4f47db14c
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"
@@ -157,6 +158,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 {
@@ -1098,6 +1101,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{})
@@ -1347,6 +1358,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
@@ -2724,6 +2736,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