Skip to content

Commit 7d64bd4

Browse files
committed
fix(cache): exclude AD computer accounts from FindUsers
simple-ldap-go's FindUsers uses (|(objectClass=user)(objectClass=inetOrgPerson)(objectClass=person)) — and in Active Directory computer accounts inherit objectClass=user, so they leak into the users cache. The /users page (and BuildGraph, BuildListGraph, anything else built on FindUsers) showed machine accounts alongside real users. Filter at the cache layer: any DN also present in the Computers cache is dropped from the user iteration. Single O(1) lookup per user via the existing dnIndex. Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
1 parent 23a2611 commit 7d64bd4

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

internal/ldap_cache/manager.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,14 +316,20 @@ func (m *Manager) Refresh() {
316316
// FindUsers returns all cached users, optionally filtering out disabled users.
317317
// When showDisabled is true, returns all users including disabled ones.
318318
// When false, returns only enabled users. Uses efficient filtering on cached data.
319+
//
320+
// Also excludes any DN present in the Computers cache. Active Directory's
321+
// `objectClass=user` filter matches computer accounts too (computers inherit
322+
// from user in the AD schema), and simple-ldap-go's FindUsers uses that
323+
// broad filter. Without this exclusion the /users list shows machine
324+
// accounts alongside real users on AD-backed deployments.
319325
func (m *Manager) FindUsers(showDisabled bool) []ldap.User {
320-
if !showDisabled {
321-
return m.Users.Filter(func(u ldap.User) bool {
322-
return u.Enabled
323-
})
324-
}
326+
return m.Users.Filter(func(u ldap.User) bool {
327+
if _, isComputer := m.Computers.FindByDN(u.DN()); isComputer {
328+
return false
329+
}
325330

326-
return m.Users.Get()
331+
return showDisabled || u.Enabled
332+
})
327333
}
328334

329335
// FindUserByDN finds a user by their Distinguished Name (DN) in the cache.

0 commit comments

Comments
 (0)