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

connector/ldap: Add LDAP simple bind mode. #1585

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

batatch
Copy link

@batatch batatch commented Nov 18, 2019

Supports LDAP simple bind mode
If BindDNPrefix or BindDNSuffix are set, BindDNPrefix username BindDNSuffix is used as BindDN.

@batatch batatch force-pushed the feature/ldap_simple_bind branch from 1b8f320 to 19b6e28 Compare December 9, 2019 17:24
@batatch batatch force-pushed the feature/ldap_simple_bind branch 2 times, most recently from eb23e4d to 814af60 Compare March 30, 2020 05:39
@batatch batatch force-pushed the feature/ldap_simple_bind branch from 814af60 to dfb6185 Compare April 8, 2020 09:33
@batatch batatch force-pushed the feature/ldap_simple_bind branch 2 times, most recently from e7f9b09 to cfa232e Compare July 6, 2020 23:35
@batatch batatch force-pushed the feature/ldap_simple_bind branch from cfa232e to 0c437aa Compare July 16, 2020 00:24
@the-maldridge
Copy link

This is a feature I'd really like to have. Is there anything I can do to assist with testing? My environment is very service-principal-averse, so all our other services besides dex bind directly as the user they're authenticating. Would be nice to have that here as well.

@batatch batatch force-pushed the feature/ldap_simple_bind branch from 0c437aa to 74a6281 Compare October 18, 2021 01:26
@batatch
Copy link
Author

batatch commented Oct 19, 2021

Hi, the-maldridge. Thanks for your comment.
I'd be glad you to try it in your environment if you possible.

@batatch batatch force-pushed the feature/ldap_simple_bind branch from 74a6281 to 19bc17c Compare November 4, 2021 10:19
@batatch batatch force-pushed the feature/ldap_simple_bind branch from 19bc17c to 87acab5 Compare June 27, 2022 10:11
@batatch batatch force-pushed the feature/ldap_simple_bind branch from 87acab5 to 2b7e509 Compare August 29, 2022 01:19
bindPW = string(c.pass)
}

c.logger.Debugf("ldap: - bindDN=<%s>", bindDN)

Check failure

Code scanning / CodeQL

Log entries created from user input

This log write receives unsanitized user input from [here](1). This log write receives unsanitized user input from [here](2).
@tooptoop4
Copy link

@sagikazarmark @seankhliao @vsychov @nabokihms can you please merge?

I'm setting suffix as '@my.company.domain' so I can use incoming ActiveDirectory user creds to bind to ldap instead of relying on a common service/generic account to bind for all incoming users

Copy link
Member

@sagikazarmark sagikazarmark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

Can you please take a look at my comment?

Also, can you please add tests making sure this feature works? Thanks!

connector/ldap/ldap.go Outdated Show resolved Hide resolved
@tooptoop4
Copy link

@batatch are u still working on this?

@batatch
Copy link
Author

batatch commented Aug 9, 2023

@tooptoop4 ok, i'll try it.

@batatch batatch force-pushed the feature/ldap_simple_bind branch from 6771505 to c6e974b Compare August 9, 2023 15:03
@batatch batatch force-pushed the feature/ldap_simple_bind branch from c6e974b to 0bd9cd5 Compare August 14, 2023 07:26
@batatch batatch force-pushed the feature/ldap_simple_bind branch from 0bd9cd5 to c77c83f Compare August 25, 2023 23:37
@batatch
Copy link
Author

batatch commented Aug 25, 2023

@sagikazarmark
I processed some steps were required.
Can you please merge it?

@batatch batatch requested a review from sagikazarmark August 28, 2023 07:21
@sagikazarmark
Copy link
Member

Thanks for making the changes and sorry for the long delay.

The PR looks good to me, but I'd like to raise a question before we merge it (bear in mind I'm not that familiar with how apps generally integrate LDAP):

I'm a little bit concerned that it may be too easy to provide invalid data in the configuration that could result in errors.

For example: if you don't provide a prefix, but you provide a suffix, the DN could look something like this: username,cn=users

Another concern (and again, not sure how other applications do it:

What if the username contains special characters? For example: myuser,cn=admins?

Then the DN will look like this: uid=myuser,cn=admins

Here comes the question: would it make sense to add some better validation and/or escaping to make sure the DN is correct?

Also (and once again, no idea if this is an accepted practice or not), I'm thinking maybe we should introduce these options instead:

bindDN: "uid={username},cn=users..."
simpleBind: true

When simpleBind is true, the DN would become a template string replacing {username} with the actual username. That way we need less validation/rely less on the presence of a prefix/suffix. (We probably still need escaping)

What do you think?

@batatch
Copy link
Author

batatch commented Oct 8, 2023

Thank you for your comment, sagikazarmark-san.

The configuration method for specifying prefix and suffix is based on the most commonly found PostgreSQL example and more.
(eg. https://www.postgresql.org/docs/current/auth-ldap.html)

If we use templates, I couldn't determine which template method to use, as it requires an uniform rules in configuration.
(like printf style, parameter name in braces style, go-lang template, and original style)

I think the boolean flag of simpleBind=true and the template setting definitions to be redundant,
since it requires a decision based on a combination of two parameters.
(if set simpleBind=true, but template undefined, then it is fail of configuration.)
If we use template definition, I think it would be better to make the decision based on exist or not the template definition.

In the validation of prohibited characters in usernames, "," might be better to be checked.
and other than that, I think it is fine to left to the LDAP server.
since the dexidp itself does not store usernames and only relays user inputs to the LDAP server.

@sagikazarmark
Copy link
Member

If we use templates, I couldn't determine which template method to use

Obviously, it would have to be documented.

I think the boolean flag of simpleBind=true and the template setting definitions to be redundant,

I don't think it's any more redundant than the current proposal. Simple bind setting would essentially change the behavior of how the other parameter is used.

and other than that, I think it is fine to left to the LDAP server.

I would argue this is actually a potential security issue, since usernames are accepted as an input entered by a user. This could essentially be the LDAP version of an SQL injection, so the user name MUST be escaped somehow. No idea if there is any builtin tool for that in the LDAP library (ie. something like prepared statements in SQL).

@tooptoop4
Copy link

🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants