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

Support unauthenticated and anonymous bind #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion glide.yaml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package: github.com/kismatic/kubernetes-ldap
import:
- package: github.com/go-ldap/ldap
version: 0e7db8eb77695b5a952f0e5d78df9ab160050c73
version: 0ae9f2495c4a9e5d436bc9a2b13a71a2fb06ddf3
subpackages:
- github.com\go-ldap\ldap
- package: github.com/golang/glog
Expand Down
21 changes: 13 additions & 8 deletions ldap/client.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,17 @@ func (c *Client) Authenticate(username, password string) (*ldap.Entry, error) {
defer conn.Close()

// Bind user to perform the search
if c.SearchUserDN != "" && c.SearchUserPassword != "" {
err = conn.Bind(c.SearchUserDN, c.SearchUserPassword)
if c.SearchUserDN != "" {
if c.SearchUserPassword != "" {
// Authenticated bind
err = conn.Bind(c.SearchUserDN, c.SearchUserPassword)
} else {
// Unauthenticated bind (only username)
err = conn.UnauthenticatedBind(c.SearchUserDN)
}
} else {
err = conn.Bind(username, password)
// Anonymous bind
err = conn.UnauthenticatedBind("")
}
if err != nil {
return nil, fmt.Errorf("Error binding user to LDAP server: %v", err)
Expand All @@ -63,11 +70,9 @@ func (c *Client) Authenticate(username, password string) (*ldap.Entry, error) {
// Now that we know the user exists within the BaseDN scope
// let's do user bind to check credentials using the full DN instead of
// the attribute used for search
if c.SearchUserDN != "" && c.SearchUserPassword != "" {
err = conn.Bind(res.Entries[0].DN, password)
if err != nil {
return nil, fmt.Errorf("Error binding user %s, invalid credentials: %v", username, err)
}
err = conn.Bind(res.Entries[0].DN, password)
if err != nil {
return nil, fmt.Errorf("Error binding user %s, invalid credentials: %v", username, err)
}

// Single user entry found
Expand Down