Rocket.Chat icon indicating copy to clipboard operation
Rocket.Chat copied to clipboard

[New Feature] Advanced LDAP filtering in login handler

Open Wirone opened this issue 8 years ago • 12 comments

Description:

In our organization we use RocketChat with LDAP authentication. We have this case: we want to keep Rocket open for IT while only half-open for people outside IT - these people could only log in from local IPs (inside company). So we would like to determine if user is a member of some LDAP group (IT employee) and if not, additionaly check client's IP and if it's external, deny logging in.

First, I would like to ask if you're interested in extending LDAP configuration screen for handling such scenario (I think it can be done in a way to be flexible and re-usable in multiple related scenarios) because we could work on it and make MR.

Second, if you don't want such changes in the core, please make suggestions how we can hook into LDAP authorization process in best way to keep possibility of upgrading RocketChat from TAR release while maintaining custom LDAP login handler.

Server Setup Information:

  • Version of Rocket.Chat Server: 0.60.4
  • Operating System: Ubuntu 16.04.3 LTS
  • Deployment Method(snap/docker/tar/etc): TAR
  • Number of Running Instances: 1

Wirone avatar Jan 26 '18 12:01 Wirone

We've implemented it on our own on top of 0.60.4, using custom configuration fields and by modifying some packages/rocketchat-ldap/server/* files.

We're using 2 fields (and enable/disable flag):

  • group DN which is allowed to log in regardless of remote IP
  • comma-separated IP whitelist using ip-range-check package (used also in 0.61.0)

Let me know if you're interested in getting this feature.

PS. What is the best way to determine client's remote IP cyclically (some kind of request listener)? Because now we only check this thing on logging in, so user can log in inside company's network and then go outside and still be logged in, which is some kind of security issue for us.

Wirone avatar Feb 08 '18 15:02 Wirone

We are very interested in getting that feature. We made workaround with nginx and white-listing ip for authenticated users. But this is very ugly workaround and we prefer to implement that feature from sever side back-end. We have version Rocket.Chat Version 0.73.1 I'm tried to find mentioned folder but without success.

[root@rocketchat opt]#cd /opt/rocket/
[root@rocketchat rocket]#find -type d -name '*ldap*'
./Rocket.Chat/programs/server/npm/node_modules/ldapjs
./Rocket.Chat/programs/server/npm/node_modules/ldap-filter
./Rocket.Chat/bundle/programs/server/npm/node_modules/ldapjs
./Rocket.Chat/bundle/programs/server/npm/node_modules/ldap-filter
./bundle/programs/server/npm/node_modules/ldapjs
./bundle/programs/server/npm/node_modules/ldap-filter

I think it can be good feature to put some shell-hook which can have affect on authentication process. As variable send there interested information (ip username and so on) and analyse exit code.

P.S. Main thing for us is to check if user logged in from internal company's network or outside. So we want to have restriction allowed ips/nets assigned for user or ldap group. But if feature will be implemented as i said: authentication process will call some external bash/python/js file which will have all interested information about connection (user name, remote ip, dont forget about nginx X-Real-IP) - everybody can make his own implementation of limitations. Allow,Deny or Deny,Allow etc.

justalreadytaken avatar Feb 14 '19 16:02 justalreadytaken

If RockerChat team is interested in this feature I can prepare PR with our changes (if I get company's permission of course). We also made resource which is cyclically requested by client so IP is checked while user is logged in and if it doesn't match to rules, user is logged out.

Wirone avatar Feb 15 '19 07:02 Wirone

Hello, we are interested in that feature very much and use the same way like justalreadytaken, ngnix with white-listing.

georgyip avatar Feb 15 '19 12:02 georgyip

@Wirone Did you get visitors remote IP before authentication?

justalreadytaken avatar Feb 19 '19 15:02 justalreadytaken

@justalreadytaken Not before, but while authenticating.

In packages/rocketchat-ldap/server/loginHandler.js we used const remoteIp = this.connection.httpHeaders['x-forwarded-for'] || this.connection.clientAddress; and we compare this IP against our custom config (using ip-range-check package).

Wirone avatar Feb 20 '19 13:02 Wirone

@Wirone I was played with Rocket.Chat Version: 0.74.3 and found that in the "Accounts.registerLoginHandler" property "this.connection" is assigned only when connection is coming from web browser. and "this.connection" is undefined when user trying to connect from mobile or desktop app.

Also re-connection is not coming to this module. So user can login from office then switch-off wifi and had access from public IP. :)

Also found that exception inside "Accounts.registerLoginHandler" trowing execution over Fallback handler and user can login ignoring ldap auth. But this can be easyly fixed with option disabled fallback handler.

Now starting play with meteor and building app from git repo. :)

justalreadytaken avatar Mar 24 '19 17:03 justalreadytaken

@justalreadytaken we're using desktop client and mobile apps and last time I was really verificating this, it was working correctly ;-)

Also, we have additional resource registered from server side and we periodically (interval is configurable as far as I remember) request it from client's side, so if IP does not match criteria AFTER user logs in, it will be logged out automatically. Of course it does not work for mobile app, but AFAIR works for desktop client, which is a bundled web client.

We're currently moving to 0.74.3 after some problems with Internal Hubot. I'll check all LDAP business requirements again before production deploy ;-)

Wirone avatar Mar 24 '19 17:03 Wirone

@justalreadytaken FYI today I've checked our custom LDAP integration and it's working properly for desktop client and in regular browser. I found out that changing our custom configurations does not reload LDAP connection in our server method so old logic (from server's start) is applied, so I fixed it right away ;)

Wirone avatar Mar 25 '19 15:03 Wirone

Did you try mobile client? I'm still having issue connection from mobile client has not defined this.connection.httpHeaders and this.connection.clientAddress

my debug code returning this => App running at: http://localhost:3000/ I20190327-11:30:18.893(1)? taking real visitor's ip I20190327-11:30:18.895(1)? Object this.connection.httpHeaders is not defined I20190327-11:30:18.896(1)? Object this.connection.clientAddress is not dfined too. I20190327-11:30:18.897(1)? (visitor's ip [undefined]) I20190327-11:30:18.901(1)? We are outside I20190327-11:30:18.902(1)? Ip was checked with ip-range-check.

justalreadytaken avatar Mar 27 '19 10:03 justalreadytaken

@justalreadytaken We decided to not handle mobile client since we don't have build process for it and we can't force people to install our version. Since user can login to the mobile app inside office (using wifi) and periodic IP checking does not work there without changes to the client, it does not make sense to waste time on it (only for logging in). Never tested how our custom business logic works with mobile client, but I use Android app every day and I don't have problems.

Wirone avatar Mar 27 '19 11:03 Wirone

Closing this issue as we've had this feature for a long time now.

pierre-lehnen-rc avatar Sep 28 '21 23:09 pierre-lehnen-rc