Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LDAP via simple auth separate bind user and search base #5055

Merged
merged 6 commits into from
Dec 27, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor findUserDN func; pull BindDN code out
Pull BindDN code out of findUserDN function so it is more universal. It is only called once so the bind now occurs just before the call.

Signed-off-by: Tony Homrich <[email protected]>
  • Loading branch information
tenacubus committed Oct 9, 2018
commit 9924b9c53063df87845f6c984f06017a6656d955
22 changes: 12 additions & 10 deletions modules/auth/ldap/ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,6 @@ func (ls *Source) sanitizedUserDN(username string) (string, bool) {

func (ls *Source) findUserDN(l *ldap.Conn, name string) (string, bool) {
log.Trace("Search for LDAP user: %s", name)
if ls.BindDN != "" && ls.BindPassword != "" {
err := l.Bind(ls.BindDN, ls.BindPassword)
if err != nil {
log.Debug("Failed to bind as BindDN[%s]: %v", ls.BindDN, err)
return "", false
}
log.Trace("Bound as BindDN %s", ls.BindDN)
} else {
log.Trace("Proceeding with anonymous LDAP search.")
}

// A search for the user.
userFilter, ok := ls.sanitizedUserQuery(name)
Expand Down Expand Up @@ -210,6 +200,18 @@ func (ls *Source) SearchEntry(name, passwd string, directBind bool) *SearchResul
log.Trace("LDAP will use BindDN.")

var found bool

if ls.BindDN != "" && ls.BindPassword != "" {
err := l.Bind(ls.BindDN, ls.BindPassword)
if err != nil {
log.Debug("Failed to bind as BindDN[%s]: %v", ls.BindDN, err)
return nil
}
log.Trace("Bound as BindDN %s", ls.BindDN)
} else {
log.Trace("Proceeding with anonymous LDAP search.")
}

userDN, found = ls.findUserDN(l, name)
if !found {
return nil
Expand Down