diff --git a/internal/outpost/ldap/instance.go b/internal/outpost/ldap/instance.go index b39dc8c51..646fa7f7b 100644 --- a/internal/outpost/ldap/instance.go +++ b/internal/outpost/ldap/instance.go @@ -9,6 +9,7 @@ import ( "github.com/go-openapi/strfmt" "github.com/nmcclain/ldap" log "github.com/sirupsen/logrus" + "goauthentik.io/api/v3" "goauthentik.io/internal/constants" "goauthentik.io/internal/outpost/ldap/bind" @@ -39,7 +40,7 @@ type ProviderInstance struct { outpostName string outpostPk int32 searchAllowedGroups []*strfmt.UUID - boundUsersMutex sync.RWMutex + boundUsersMutex *sync.RWMutex boundUsers map[string]*flags.UserFlags uidStartNumber int32 diff --git a/internal/outpost/ldap/refresh.go b/internal/outpost/ldap/refresh.go index 40b757c92..0d121ad46 100644 --- a/internal/outpost/ldap/refresh.go +++ b/internal/outpost/ldap/refresh.go @@ -9,6 +9,7 @@ import ( "github.com/go-openapi/strfmt" log "github.com/sirupsen/logrus" + "goauthentik.io/api/v3" "goauthentik.io/internal/outpost/ldap/bind" directbind "goauthentik.io/internal/outpost/ldap/bind/direct" @@ -56,11 +57,12 @@ func (ls *LDAPServer) Refresh() error { // Get existing instance so we can transfer boundUsers existing := ls.getCurrentProvider(provider.Pk) + usersMutex := &sync.RWMutex{} users := make(map[string]*flags.UserFlags) if existing != nil { - existing.boundUsersMutex.RLock() + usersMutex = existing.boundUsersMutex + // Shallow copy, no need to lock users = existing.boundUsers - existing.boundUsersMutex.RUnlock() } providers[idx] = &ProviderInstance{ @@ -72,7 +74,7 @@ func (ls *LDAPServer) Refresh() error { authenticationFlowSlug: provider.BindFlowSlug, invalidationFlowSlug: invalidationFlow, searchAllowedGroups: []*strfmt.UUID{(*strfmt.UUID)(provider.SearchGroup.Get())}, - boundUsersMutex: sync.RWMutex{}, + boundUsersMutex: usersMutex, boundUsers: users, s: ls, log: logger,