-
Notifications
You must be signed in to change notification settings - Fork 10.7k
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 authentication with active directory [$10] #1491
Comments
Hello, RocketChat worked fine until I connected it to an AD server. I'm running the lastest Docker image with docker-compose. |
Hi, |
I’ve just updated to the latest build and LDAP authentication is still working properly and no crashes. Just now upgraded the production version and same result, LDAP continues to work and RC is stable, this is 2003 and its a non Docker install. So not being able to reproduce, was the LDAP working for you at all? is the time on the chat server and the AD server in sync? - Can you test your LDAP query in apache studio to confirm its correct? |
Hello,
There are more info wich can be useful.
Connection status: Open port status: Process list status: Error output from connected client browser: You can reproduce case fast, if you use tcpkill and try to login to system, it will close new created session between application and ldap server. (Rocket Chat will crash on every attempt to login) |
If using LDAP with wrong credentials is letting you in to RC then looks like there is an error in the filter and its not actually doing any LDAP. (Seen this when no bind is used) Can you post your Bind Search field (change the username and password of course) and checking your RC server can actually resolve your AD server ok? |
Ok there is Bind Search. But if filter is not correct, why login page works correctly ? {"filter": "(&(objectCategory=person)(objectclass=user)(memberOf=CN=GRP,OU=Groups,OU=LCC,DC=myorg,DC=org)(mail=#{username}))", "scope": "sub", "userDN": "myuser", "password": "mypassword"} |
I think there is a default action, when ldap initial bind fails, to accept logon, prob left over from the testing. @rodrigok best to answer that one. - we should prob add some form of testing to confirm bind is successful before accepting the changes. So looking at your bind you are using email to login with right? Here is one from my dev server: (This one can either authenticate with Email or Username and must be in the group called RC_Users) In this case: Bind Account (proxy user) = [email protected] {"filter": "(&(objectCategory=person)(objectclass=user)(memberOf=CN=RC_Users,OU=Services,DC=domain,DC=com)(|(mail=#{username})(sAMAccountName=#{username})))", "scope": "sub", "userDN": "[email protected]", "password": "password"} |
RC doesn't let me to enter to system with wrong credentials. |
Yes you are right I use email as user login parameter and authentication works fine |
ok so the issue right now for you is that after 15 minutes the session is dropped for all connected users? |
and there appears to be no handling of the closure an ldap query? |
I see here 2 issues.
|
Are you using LDAPS? or LDAP? |
I am using LDAP |
One difference is I made manual installation inside self created Docker container. I am not sure if this can be the reason. |
Strange, I can only see an initial 389 connection to the DC, if I kill it the one session will reconnect but all other sessions are still up. |
I'll try and few things see if I can reproduce it |
Thanks a lot! |
Ok I can confirm the non closure of ldap connections even on failed logon. netstat -antup | grep 389 increases over time for the same process if I enter incorrect pw over and over. - so we need to check the clean-up on connections there. I'm still not able to reproduce the session closure for all users thou, I can of course manually kill -9 the connection and this will force all clients to terminate and reconnect within a few seconds but I'm not clear why the server side is resetting this connection? - do you have any throttling or limits set on the server side? how many connections are active before it resets? |
Ok what I was able to get from AD. Now how to reproduce connection closure. Killing process will not give you what you are looking for.
tcpkill will detect TCP activity from RC to AD and will send RST to both of hosts. This will force hosts to close TCP session immediately. This will crash RC and you will see that both of clients loose connection with server. |
About amount of active sessions, it doesn't mater I happens even with 1 session. |
Ok then we need to be looking at why your server is terminating the connection? Sure we can handle this better with ldap but I cannot see the behaviour you are seeing with any of the deployments with AD. Anyone else able to reproduce this? |
I'll create a fresh install this weekend to see if I get the same results. |
As I said |
I also have the same default timeouts but no crashes.. that's why I said I will create a fresh one and see if I can reproduce it. I just jumped onto the dev domain, logged on as user X on RC - then completely disconnected the Virtual DC from the domain just after logon (to simulate network problem, restart of AD etc..) and the user did not disconnect nor did RC crash - of course no more users can logon at that stage (as expected) but I do not see any crashes when a DC is removed from RC. |
if I use tcpkill -i eth0 host "ldapserverIP" and let it listen and kill the connection as it comes in then yep I can confirm RC crashes in that instance, so that defo needs further investigation and should be marked as a BUG. @rodrigok is the best to comment on the ldap code. |
Related to auto-connect on socket error (seems undocumented but possible to handle it gracefully?) |
Hi, I use only LDAP-Users for testing. My miscs LDAP entry has [email protected] as mail and miscs as sAMAccountName. So I use this LDAP Query to enable login with miscs OR [email protected] for my user. As I said using miscs works but [email protected] crahses RC.
Rocket Log output for login with [email protected] is the same as in my comment above:
But even if I simplify my LDAP search to
RC crahses with the same error when I try to login with [email protected]. But in that case it should return "User not found".
Using miscs works fine (using LDAP and it´s even the same LDAP user). So I think RC has a problem if LDAP can´t map any user? |
That seems to be the problem. If i use "ANonExistingUsername" RC always crashes. |
hi @miscs - i think your LDAP queries may not be quite right, from the looks of this you are using openldap but you are also using the attribute sAMAccountName=#{username} sAMAccountName is Active Directory specific. Shouldn't you be using the following? uid=#{username} making your simplified ldap query this: {"filter": "(&(objectCategory=person)(objectclass=user)(memberOf=CN=Employees,OU=Groups,DC=corp,DC=xxx,DC=com)(uid=#{username}))", "scope": "sub", "userDN": "[email protected]", "password": "mypass"} also, just a note, openldap doesn't natively use the overlay "memberOf" - so did you add this yeah? easiest confirmation is to use apache directory studio to confirm the queries. |
The LDAP queries are working. We use Samba4 as backend which supports sAMAccountName=#{username} - if the query would not work I would not be able to login using only "miscs". I use these queries in a lot of other applications and they are working everywhere just fine :) Even in RC they are working as long as I use an existing LDAP user. The crash only occurs if I use a username which is not in LDAP and therefore cannot be mapped... |
hmm, ok, what is Samba4 sending back to RC as a response? can you inspect the traffic and post back? Ive just tested the latest 0.10 and caused a failed lookup and an incorrect config just results in the correct LDAP response of user not found prompting the following: Guess we need to know a bit more about how samba is responding to find out why RC crashes. |
Thanks @engelgabriel |
with debug-level all I get
So if I am reading the log the right way I have no user (null) which is correct since I used a non existing login. But then [methods] UserPresence:online -> userId: null , arguments: {} is called which won´t work with userId: null ... |
to intercept the samba4/ldap response I have to wait for our admin :( sorry. but maybe we can log the response using RC? |
i'll spin up a samba4 ldap tomo when I get to the office tomo and see if I can help ya out. |
thank you for all your help to figure this out! |
Happy new year to all of you! We just testet a little bit more and checked responses with wireshark. What we see is the following: Samba4 Backend, Using LDAP LogIn with existing User (Success)
LogIn with non-existing User (Server-Crash)
What RC should do is test is if the result set for User-Search is exactly 1 - if not throw error User not found and abort login. Hope this helps :) |
@Megatronic79 yes, I need :) I'm trying to simulate this with some online "demo" server but without success. |
sure thing :) , will get this online when I get to the office in the morning and will pm the details to ya. |
@rodrigok if you have an static IP I can also open our Samba4/LDAP server for that IP. Maybe thats the easiest? |
cool. btw @miscs what kind of setup is your samba4\ldap? |
@Megatronic79 thanks @miscs I do not have an static IP, I can inform you my dynamic IP that can work for some time |
If I read the code at https://github.com/RocketChat/Rocket.Chat/blob/develop/packages/rocketchat-ldap/ldap_server.js#L158 correctly, I cannot see any check, if the returned search result is not empty. Could that be it? |
I just modified the from @hameno mentioned code a bit (inside my docker image) and the server won't crash any more :)
But my changes are very dirty and additionally I am too stupid to return a correct LDAP error in case res_count != 1 (this is why the else flow is commented out). |
Great! Maybe @rodrigok can clean that code up for you and pass the correct LDAP value back but looks like you found the issue. :) |
@miscs I implemented your code. As far as I know the error returned is not relevant, will just cancel de login. |
cool. thanks a lot!!! |
We push changes to master on mondays, is that ok? |
of course, thanks for the feedback! |
I just pulled the latest develop docker image and everything works fine!!! |
Hello,
We try to integrate rocketchat with AD using LDAP.
Login works, but we have problem with active sessions.
Seems main.js creates new session with LDAP server for each user login and keeps connection up.
After 15 minutes LDAP server sends RST packet to application and drop established connection.
As soon as LDAP server drop session with application, all connected clients lose connection with rocketchat server.
There is what I get from logs when it happens
Error: read ECONNRESET
at errnoException (net.js:905:11)
at TCP.onread (net.js:559:19)
/var/www/rocket.chat/bundle/programs/server/packages/meteor.js:974
throw new Error("Meteor code must always run within a Fiber. " +
^
Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.
at Object.Meteor.nodeCodeMustBeInFiber (packages/meteor/dynamics_nodejs.js:9:1)
at [object Object]..extend.get (packages/meteor/dynamics_nodejs.js:21:1)
at Object.Meteor.isRestricted (packages/dispatch_run-as-user/packages/dispatch_run-as-user.js:137:1)
at [object Object].Mongo.Collection.(anonymous function) as update
at Object.UserPresence.removeConnectionsByInstanceId (packages/konecty_user-presence/packages/konecty_user-presence.js:88:1)
at process. (packages/konecty_user-presence/packages/konecty_user-presence.js:223:1)
at process.emit (events.js:117:20)
at process.exit (node.js:740:17)
at process.catchException (/usr/lib/node_modules/pm2/node_modules/pmx/lib/notify.js:52:15)
at process.g (events.js:180:16)
There is a $10 open bounty on this issue. Add to the bounty at Bountysource.
The text was updated successfully, but these errors were encountered: