outpost/ldap: delay user information removal upon closing of connection
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
cc2cd6919f
commit
048467e97d
|
@ -0,0 +1,32 @@
|
||||||
|
package ldap
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (ls *LDAPServer) Close(boundDN string, conn net.Conn) error {
|
||||||
|
for _, p := range ls.providers {
|
||||||
|
p.delayDeleteUserInfo(boundDN)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pi *ProviderInstance) delayDeleteUserInfo(dn string) {
|
||||||
|
ticker := time.NewTicker(30 * time.Second)
|
||||||
|
quit := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ticker.C:
|
||||||
|
pi.boundUsersMutex.Lock()
|
||||||
|
delete(pi.boundUsers, dn)
|
||||||
|
pi.boundUsersMutex.Unlock()
|
||||||
|
close(quit)
|
||||||
|
case <-quit:
|
||||||
|
ticker.Stop()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/getsentry/sentry-go"
|
"github.com/getsentry/sentry-go"
|
||||||
goldap "github.com/go-ldap/ldap/v3"
|
goldap "github.com/go-ldap/ldap/v3"
|
||||||
|
@ -83,7 +82,6 @@ func (pi *ProviderInstance) Bind(username string, req BindRequest) (ldap.LDAPRes
|
||||||
}
|
}
|
||||||
uisp.Finish()
|
uisp.Finish()
|
||||||
defer pi.boundUsersMutex.Unlock()
|
defer pi.boundUsersMutex.Unlock()
|
||||||
pi.delayDeleteUserInfo(username)
|
|
||||||
return ldap.LDAPResultSuccess, nil
|
return ldap.LDAPResultSuccess, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,25 +98,6 @@ func (pi *ProviderInstance) SearchAccessCheck(user api.UserSelf) *string {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pi *ProviderInstance) delayDeleteUserInfo(dn string) {
|
|
||||||
ticker := time.NewTicker(30 * time.Second)
|
|
||||||
quit := make(chan struct{})
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-ticker.C:
|
|
||||||
pi.boundUsersMutex.Lock()
|
|
||||||
delete(pi.boundUsers, dn)
|
|
||||||
pi.boundUsersMutex.Unlock()
|
|
||||||
close(quit)
|
|
||||||
case <-quit:
|
|
||||||
ticker.Stop()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pi *ProviderInstance) TimerFlowCacheExpiry() {
|
func (pi *ProviderInstance) TimerFlowCacheExpiry() {
|
||||||
fe := outpost.NewFlowExecutor(context.Background(), pi.flowSlug, pi.s.ac.Client.GetConfig(), log.Fields{})
|
fe := outpost.NewFlowExecutor(context.Background(), pi.flowSlug, pi.s.ac.Client.GetConfig(), log.Fields{})
|
||||||
fe.Params.Add("goauthentik.io/outpost/ldap", "true")
|
fe.Params.Add("goauthentik.io/outpost/ldap", "true")
|
||||||
|
|
|
@ -83,5 +83,6 @@ func NewServer(ac *ak.APIController) *LDAPServer {
|
||||||
ls.defaultCert = &defaultCert
|
ls.defaultCert = &defaultCert
|
||||||
s.BindFunc("", ls)
|
s.BindFunc("", ls)
|
||||||
s.SearchFunc("", ls)
|
s.SearchFunc("", ls)
|
||||||
|
s.CloseFunc("", ls)
|
||||||
return ls
|
return ls
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue