@@ -34,10 +34,10 @@ import (
34
34
// bindDN: uid=serviceaccount,cn=users,dc=example,dc=com
35
35
// bindPW: password
36
36
// userSearch:
37
- // # Would translate to the query "(&(objectClass=person)(uid=<username>))"
37
+ // # Would translate to the query "(&(objectClass=person)(!( uid=<username>)|(mail=<username>) ))"
38
38
// baseDN: cn=users,dc=example,dc=com
39
39
// filter: "(objectClass=person)"
40
- // username: uid
40
+ // username: uid,mail
41
41
// idAttr: uid
42
42
// emailAttr: mail
43
43
// nameAttr: name
@@ -108,8 +108,8 @@ type Config struct {
108
108
// Optional filter to apply when searching the directory. For example "(objectClass=person)"
109
109
Filter string `json:"filter"`
110
110
111
- // Attribute to match against the inputted username. This will be translated and combined
112
- // with the other filter as "(<attr >=<username>)".
111
+ // Attributes (comma-separated) to match (OR) against the inputted username. This will be translated and combined
112
+ // with the other filter as "(!(<attr1 >=<username>)|(<attr2>=<username>) )".
113
113
Username string `json:"username"`
114
114
115
115
// Can either be:
@@ -414,7 +414,21 @@ func (c *ldapConnector) identityFromEntry(user ldap.Entry) (ident connector.Iden
414
414
}
415
415
416
416
func (c * ldapConnector ) userEntry (conn * ldap.Conn , username string ) (user ldap.Entry , found bool , err error ) {
417
- filter := fmt .Sprintf ("(%s=%s)" , c .UserSearch .Username , ldap .EscapeFilter (username ))
417
+ var filter string
418
+ escapedUsername := ldap .EscapeFilter (username )
419
+
420
+ // Split username attribute by comma to support multiple search attributes
421
+ usernameAttrs := strings .Split (c .UserSearch .Username , "," )
422
+
423
+ attrFilters := make ([]string , 0 , len (usernameAttrs ))
424
+ for _ , attr := range usernameAttrs {
425
+ attr = strings .TrimSpace (attr )
426
+ if attr != "" {
427
+ attrFilters = append (attrFilters , fmt .Sprintf ("(%s=%s)" , attr , escapedUsername ))
428
+ }
429
+ }
430
+ filter = fmt .Sprintf ("(|%s)" , strings .Join (attrFilters , "" ))
431
+
418
432
if c .UserSearch .Filter != "" {
419
433
filter = fmt .Sprintf ("(&%s%s)" , c .UserSearch .Filter , filter )
420
434
}
@@ -432,6 +446,11 @@ func (c *ldapConnector) userEntry(conn *ldap.Conn, username string) (user ldap.E
432
446
},
433
447
}
434
448
449
+ for _ , attr := range usernameAttrs {
450
+ attr = strings .TrimSpace (attr )
451
+ req .Attributes = append (req .Attributes , attr )
452
+ }
453
+
435
454
for _ , matcher := range c .GroupSearch .UserMatchers {
436
455
req .Attributes = append (req .Attributes , matcher .UserAttr )
437
456
}
0 commit comments