-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Use service bind for searching LDAP groups #2534
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
71fd6e8
Updating the ldap backend to address issue #2387
7583c60
Addressing lines 127 and 129 from @shomron's comments
ab7f99c
Changing 'bind' to 're-bind'.
ee62b8f
Addressing line 136 of @shomron's comments
286c3b8
Addressing @somron's review requests on formatting and clarity.
9ec9434
Updating the docs to add a little more clarity on which user is perfo…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,25 +104,36 @@ func (b *backend) Login(req *logical.Request, username string, password string) | |
// Clean connection | ||
defer c.Close() | ||
|
||
bindDN, err := b.getBindDN(cfg, c, username) | ||
userBindDN, err := b.getUserBindDN(cfg, c, username) | ||
if err != nil { | ||
return nil, logical.ErrorResponse(err.Error()), nil | ||
} | ||
|
||
if b.Logger().IsDebug() { | ||
b.Logger().Debug("auth/ldap: BindDN fetched", "username", username, "binddn", bindDN) | ||
b.Logger().Debug("auth/ldap: BindDN fetched", "username", username, "binddn", userBindDN) | ||
} | ||
|
||
if cfg.DenyNullBind && len(password) == 0 { | ||
return nil, logical.ErrorResponse("password cannot be of zero length when passwordless binds are being denied"), nil | ||
} | ||
|
||
// Try to bind as the login user. This is where the actual authentication takes place. | ||
if err = c.Bind(bindDN, password); err != nil { | ||
if err = c.Bind(userBindDN, password); err != nil { | ||
return nil, logical.ErrorResponse(fmt.Sprintf("LDAP bind failed: %v", err)), nil | ||
} | ||
|
||
userDN, err := b.getUserDN(cfg, c, bindDN) | ||
// We re-bind to the BindDN if it's defined because we assume | ||
// the BindDN should be the one to search, not the user logging in. | ||
if cfg.BindDN != "" && cfg.BindPassword != "" { | ||
if err := c.Bind(cfg.BindDN, cfg.BindPassword); err != nil { | ||
return nil, logical.ErrorResponse("Encountered an error while attempting to re-bind with the BindDN User: " + err.Error()), nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: use
|
||
} | ||
if b.Logger().IsDebug() { | ||
b.Logger().Debug("auth/ldap: Re-Bound to original BindDN") | ||
} | ||
} | ||
|
||
userDN, err := b.getUserDN(cfg, c, userBindDN) | ||
if err != nil { | ||
return nil, logical.ErrorResponse(err.Error()), nil | ||
} | ||
|
@@ -165,7 +176,7 @@ func (b *backend) Login(req *logical.Request, username string, password string) | |
policies = append(policies, group.Policies...) | ||
} | ||
} | ||
if user !=nil && user.Policies != nil { | ||
if user != nil && user.Policies != nil { | ||
policies = append(policies, user.Policies...) | ||
} | ||
// Policies from each group may overlap | ||
|
@@ -218,7 +229,7 @@ func (b *backend) getCN(dn string) string { | |
* 2. If upndomain is set, the user dn is constructed as 'username@upndomain'. See https://msdn.microsoft.com/en-us/library/cc223499.aspx | ||
* | ||
*/ | ||
func (b *backend) getBindDN(cfg *ConfigEntry, c *ldap.Conn, username string) (string, error) { | ||
func (b *backend) getUserBindDN(cfg *ConfigEntry, c *ldap.Conn, username string) (string, error) { | ||
bindDN := "" | ||
if cfg.DiscoverDN || (cfg.BindDN != "" && cfg.BindPassword != "") { | ||
if err := c.Bind(cfg.BindDN, cfg.BindPassword); err != nil { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Debug message does not reflect
binddn->userbinddn
.