Skip to content

Commit 4ab08a0

Browse files
committed
providers/ldap: avoid negative caching on flow errors
- direct: map flow/transport errors to LDAPResultOperationsError instead of InvalidCredentials. - memory: cache only non-OperationsError results; guard against missing flags/session when deriving TTL. This prevents transient backend/flow failures from being cached as invalid credentials for a DN/password combination. Successful binds and genuine InvalidCredentials/access outcomes continue to be cached as before, preserving intended behavior. Signed-off-by: Christian Albrecht <christian.albrecht@mayflower.de>
1 parent 7a23055 commit 4ab08a0

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

internal/outpost/ldap/bind/direct/bind.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (db *DirectBinder) Bind(username string, req *bind.Request) (ldap.LDAPResul
4646
"app": db.si.GetAppSlug(),
4747
}).Inc()
4848
req.Log().WithError(err).Warning("failed to execute flow")
49-
return ldap.LDAPResultInvalidCredentials, nil
49+
return ldap.LDAPResultOperationsError, nil
5050
}
5151
if !passed {
5252
metrics.RequestsRejected.With(prometheus.Labels{

internal/outpost/ldap/bind/memory/memory.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ func (sb *SessionBinder) Bind(username string, req *bind.Request) (ldap.LDAPResu
5454
}
5555
sb.log.Debug("No session found for user, executing flow")
5656
result, err := sb.DirectBinder.Bind(username, req)
57-
// Only cache the result if there's been an error
58-
if err == nil {
57+
// Cache all non-OperationsError results to preserve positive/negative caching
58+
// semantics, but avoid caching transient backend/flow failures which surface
59+
// as LDAPResultOperationsError.
60+
if err == nil && result != ldap.LDAPResultOperationsError {
5961
flags := sb.si.GetFlags(req.BindDN)
60-
if flags == nil {
61-
sb.log.Error("user flags not set after bind")
62+
if flags == nil || flags.Session == nil {
63+
sb.log.Error("user flags/session not set after bind")
6264
return result, err
6365
}
6466
sb.sessions.Set(Credentials{

0 commit comments

Comments
 (0)