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

[NEW] LDAP User Groups, Roles, and Channel Synchronization #14278

Merged
merged 36 commits into from
Aug 21, 2019

Conversation

wreiske
Copy link
Contributor

@wreiske wreiske commented Apr 28, 2019

Closes: #1196
Closes: #5085
Closes: #2759
Closes: #11710
Closes: #5252
Closes: #4735
Closes: #5086

This commit allows servers admins to set which LDAP groups they want to synchronize with Rocket user roles.

Automatically Assign LDAP Groups to Rocket.Chat Roles

image

Admins can choose to automatically remove users from a role if their LDAP group is removed.

role-add-remove

Role Automatically Added

role-add

Role Automatically Removed

role-remove

Example

image

Setting the new "User Data Group Map" to the following will allow users in LDAP under the group "rocket-admins" to be assigned the rocket.chat "admin" role.

{
	"rocket-admin": "admin",
	"devops": "devops"
}

Here's what the group looks like:
image

Automatically Add / Remove users in Channels based on LDAP Groups

image

For a preview, see: #14278 (comment)

Tested and working with OpenLDAP.

…nto ldap-admin-groups

* 'develop' of https://github.com/RocketChat/Rocket.Chat: (21 commits)
  Regression: Active room was not being marked (RocketChat#14276)
  Rename Cloud to Connectivity Services & split Apps in Apps and Marketplace (RocketChat#14211)
  LingoHub based on develop (RocketChat#14178)
  [IMPROVE] Replace livechat inquiry dialog with preview room (RocketChat#13986)
  Bump version to 0.74.3
  Room loading improvements (RocketChat#13471)
  [FIX] Invalid condition on getting next livechat agent over REST API endpoint (RocketChat#13360)
  [IMPROVE] Open rooms quicker (RocketChat#13417)
  [FIX] "Test Desktop Notifications" not triggering a notification (RocketChat#13457)
  [FIX] Translated and incorrect i18n variables (RocketChat#13463)
  Regression: Remove console.log on email translations (RocketChat#13456)
  [FIX] Properly escape custom emoji names for pattern matching (RocketChat#13408)
  [FIX] Not translated emails (RocketChat#13452)
  Added missing package dependency (RocketChat#13437)
  Update Russian localization (RocketChat#13244)
  [IMPROVE] Allow configure Prometheus port per process via Env Var (RocketChat#13436)
  [IMPROVE] Add API option "permissionsRequired" (RocketChat#13430)
  [FIX] Several Problems on HipChat Importer (RocketChat#13336)
  Add the missing uniqueId to the push notifications (RocketChat#13423)
  [FIX] Notify private settings changes even on public settings changed (RocketChat#13369)
  ...
@wreiske wreiske mentioned this pull request Apr 28, 2019
@snoopotic
Copy link
Contributor

Oh! This is so great! :)))

@geekgonecrazy geekgonecrazy added this to the 1.1.0 milestone Apr 28, 2019
@geekgonecrazy
Copy link
Contributor

This is super cool! :).

@wreiske
Copy link
Contributor Author

wreiske commented Apr 29, 2019

I think I'm going to also add automatic adding to channels... If you're in the "devops" group, you should also join the "devops" channel if it exists.

@wreiske
Copy link
Contributor Author

wreiske commented Apr 29, 2019

OK, Added Automatic Join / Leave channels based on LDAP group.

Example LDAP Group Channel Map

{
	"devops": "devops",
	"techsupport": [
		"helpdesk",
		"support"
	]
}

Auto Join Channel(s) based on LDAP Group

image

auto-join-channel

Auto Remove From Channel(s) if not in LDAP Group

NOTE: This requires the "Auto Remove Users from Channels" setting to be enabled. This is disabled by default because it will remove anyone in a channel that isn't part of the LDAP group. This can be useful for enforcing/locking down a channel to ONLY users in a specific LDAP group.

image

auto-remove-from-channel

@Abraka
Copy link

Abraka commented Apr 29, 2019

Looks great!
Question: It is possible to have a LDAP orgasm? Now I know the answer :)

@VipexGo
Copy link

VipexGo commented May 8, 2019

This looks awesome! This would make the user management so much better! At the moment we are using a script which give us a CSV-file that we import after.
We would appreciate this one a lot!
Cheers

@wall0404
Copy link

Thanks for the great job. I waited for this so long.

A question: Is there a way to automatically create a new channel when a new ldap group is recognized?
We constantly add new groups in ldap and it seems like a lot of work to include every ldap group manually in rocket.chat.

@wreiske
Copy link
Contributor Author

wreiske commented Sep 20, 2019

So it does work with active directory! I'm glad to hear you got it working!
Sounds like we need to add a page to docs about setting it up.

@pageb018
Copy link

Still not working for me.

Filter:

(&(sAMAccountName=#{username})(memberOf=CN=#{groupName},OU=Groups,DC=corp,DC=mydomain,DC=com))

Group Base DN:

OU=Groups,DC=corp,DC=mydomain,DC=com

User Base DN:

dc="corp",dc="mydomain",dc="com"

@Resquer
Copy link

Resquer commented Sep 20, 2019

For me, it works fine.
Active Directory, Windows Server 2008 R2 Standard

I20190920-13:22:15.043(3) LDAPSync ➔ info Syncing user data
I20190920-13:22:15.043(3) LDAPSync ➔ debug user { email: undefined, _id: 'xjZnY5coEThJ6qcRq' }
I20190920-13:22:15.044(3) LDAPSync ➔ debug ldapUser undefined
I20190920-13:22:15.044(3) TemplateVarHandler ➔ debug template found. replacing values
I20190920-13:22:15.045(3) TemplateVarHandler ➔ debug replacing template var: #{sn} with value: Sizova
I20190920-13:22:15.046(3) TemplateVarHandler ➔ debug replacing template var: #{givenName} with value: Olga
I20190920-13:22:15.048(3) LDAP ➔ Search.info Search result count 0
I20190920-13:22:15.049(3) LDAPSync ➔ debug olga.sizova is not in IT group!!!
I20190920-13:22:15.052(3) LDAP ➔ Search.info Search result count 0
I20190920-13:22:15.053(3) LDAPSync ➔ debug olga.sizova is not in Analysis group!!!
I20190920-13:22:15.055(3) LDAP ➔ Search.info Search result count 0
I20190920-13:22:15.056(3) LDAPSync ➔ debug olga.sizova is not in Accounting group!!!
I20190920-13:22:15.059(3) LDAP ➔ Search.info Search result count 0
I20190920-13:22:15.060(3) LDAPSync ➔ debug olga.sizova is not in Admins group!!!
I20190920-13:22:15.077(3) LDAP ➔ Search.info Search result count 1
I20190920-13:22:15.078(3) LDAPSync ➔ debug olga.sizova is in All group.
I20190920-13:22:15.081(3) LDAP ➔ Search.info Search result count 0
I20190920-13:22:15.082(3) LDAPSync ➔ debug olga.sizova is not in Fe group!!!
I20190920-13:22:15.089(3) LDAP ➔ Search.info Search result count 0
I20190920-13:22:15.089(3) LDAPSync ➔ debug olga.sizova is not in HR group!!!
I20190920-13:22:15.101(3) LDAP ➔ Search.info Search result count 0
I20190920-13:22:15.102(3) LDAPSync ➔ debug olga.sizova is not in HR_committee group!!!
I20190920-13:22:15.118(3) LDAP ➔ Search.info Search result count 1
I20190920-13:22:15.119(3) LDAPSync ➔ debug olga.sizova is in Khimki group.
I20190920-13:22:15.125(3) LDAP ➔ Search.info Search result count 0
I20190920-13:22:15.125(3) LDAPSync ➔ debug olga.sizova is not in Legal group!!!
I20190920-13:22:15.128(3) LDAP ➔ Search.info Search result count 0
I20190920-13:22:15.128(3) LDAPSync ➔ debug olga.sizova is not in Logistics group!!!
I20190920-13:22:15.130(3) LDAP ➔ Search.info Search result count 0
I20190920-13:22:15.131(3) LDAPSync ➔ debug olga.sizova is not in Managers group!!!
I20190920-13:22:15.135(3) LDAP ➔ Search.info Search result count 1
I20190920-13:22:15.135(3) LDAPSync ➔ debug olga.sizova is in Marketing group.
I20190920-13:22:15.138(3) LDAP ➔ Search.info Search result count 0
I20190920-13:22:15.138(3) LDAPSync ➔ debug olga.sizova is not in Planning group!!!
I20190920-13:22:15.141(3) LDAP ➔ Search.info Search result count 0
I20190920-13:22:15.141(3) LDAPSync ➔ debug olga.sizova is not in RD group!!!
I20190920-13:22:15.144(3) LDAP ➔ Search.info Search result count 0
I20190920-13:22:15.144(3) LDAPSync ➔ debug olga.sizova is not in RM group!!!
I20190920-13:22:15.147(3) LDAP ➔ Search.info Search result count 0
I20190920-13:22:15.148(3) LDAPSync ➔ debug olga.sizova is not in Salesm group!!!
I20190920-13:22:15.151(3) LDAP ➔ Search.info Search result count 0
I20190920-13:22:15.151(3) LDAPSync ➔ debug olga.sizova is not in Support service (drivers) group!!!
I20190920-13:22:15.154(3) LDAP ➔ Search.info Search result count 0
I20190920-13:22:15.155(3) LDAPSync ➔ debug olga.sizova is not in Tech group!!!
I20190920-13:22:15.159(3) LDAP ➔ Search.info Search result count 1
I20190920-13:22:15.159(3) LDAPSync ➔ debug olga.sizova is in users_1c group.
I20190920-13:22:15.161(3) LDAP ➔ Search.info Search result count 0
I20190920-13:22:15.162(3) LDAPSync ➔ debug olga.sizova is not in Warehouse_Nikolskoye group!!!
I20190920-13:22:15.165(3) LDAP ➔ Search.info Search result count 0
I20190920-13:22:15.165(3) LDAPSync ➔ debug olga.sizova is not in WEStaff group!!!
I20190920-13:22:15.168(3) LDAPSync ➔ info Synced user channel QExGW2LdmPxptvcPE from LDAP for olga.sizova
I20190920-13:22:15.170(3) LDAPSync ➔ info Synced user channel PEibNYzeMEHxtutkD from LDAP for olga.sizova
I20190920-13:22:15.171(3) LDAPSync ➔ info Synced user channel hoRd3aYGuA64mjrN2 from LDAP for olga.sizova
I20190920-13:22:15.195(3) LDAPSync ➔ info Synced user channel hS26Czw8pRT8P6hcx from LDAP for olga.sizova
I20190920-13:22:15.196(3) LDAPSync ➔ info Syncing user avatar
I20190920-13:22:15.197(3) Integrations ➔ Outgoing WebHook.debug Execute Trigger: roomJoined

But I can't understand how to create private groups instead public channels. The only way - change them by hands after automatic creation.

After change of group type from public to private it falls down to the end of a rooms list at Administration page. I see this private group after all "Direct Messages" strings. Long-time scrolling is needed or I can set checkbox "Private Groups" if needed.
But it seems it is an abnormal behavior.
2019-09-20_22-09-48

@Doordonot
Copy link

Doordonot commented Sep 26, 2019

@wreiske First of all, thanks for the contribution, I got it working with Active Directory, but it seems to try and create the channel everytime a user logs in, and then I get an error on the mobile App:

If I remove the channel, the user logs in and goes to the channel, but next log in, same error again. The user wont log in due to the channel creation attempt.
I tried adding the permission for the role to create channels, but no success.

I20190926-15:41:23.446(-3) LDAPSync ➔ debug User role exists for mapping testeni -> nucleo
I20190926-15:41:23.449(-3) LDAP ➔ Search.info Search result count 1
I20190926-15:41:23.451(-3) LDAPSync ➔ debug rocket.ni is in testeni group.
I20190926-15:41:23.463(-3) LDAP ➔ Search.info Search result count 0
I20190926-15:41:23.464(-3) LDAPSync ➔ debug rocket.ni is not in padrao group!!!
I20190926-15:41:23.910(-3) LDAPSync ➔ info Channel 'TI_Teste' doesn't exist, creating it.

edit: I removed the picture, it was too large. And the error occurs because inside the "LDAP Group Channel Map" fields, you cannot create channels with special characters, space, etc. So when user tries to log in, rocket chat tries to create a channel using invalid characters and is stuck there. Channel doesnt create, user doesnt log in. "Fixed it" by creating channels like "accounting-public","accounting-private", instead of "Accounting - Public"

@pierre-lehnen-rc
Copy link
Contributor

@Doordonot please open a new issue about this problem. I'll see if I can replicate it here.

@Gummikavalier
Copy link

Still not working for me.

Filter:

(&(sAMAccountName=#{username})(memberOf=CN=#{groupName},OU=Groups,DC=corp,DC=mydomain,DC=com))

Group Base DN:

OU=Groups,DC=corp,DC=mydomain,DC=com

User Base DN:

dc="corp",dc="mydomain",dc="com"

We got it working too with Active Directory. Comparing to your setting, in the User Group Filter setting we used user base DN in the path where you are using OU for groups. So you should leave out OU=Groups and replace it with OU=Users (assuming your users are under OU=Users):
(&(sAMAccountName=#{username})(memberOf=CN=#{groupName},OU=Users,DC=corp,DC=mydomain,DC=com))

Also of note is that the implementation does not seem to create channels or populate them during the scheduled LDAP synchronization or generally automatically, but only when users log in manually. So to actually see whether the LDAP setup is working or not, you have to logout and then log back in.

@hollwed
Copy link

hollwed commented Oct 8, 2019

We also got it working with Active Directory but have noticed the same behavior of not creating/populating channels with LDAP sync, only after login of a user.

@buso
Copy link

buso commented Oct 9, 2019

I'm running version 1.2.1, Merge pull request #14898 from RocketChat/release-1.2.1. How do I install this update? Do I have to re-install from scratch? I want to keep all my other settings. My setup is in CentOS 7. I'm new at git / github, so pardon the question if it's obvious.

@reetp
Copy link

reetp commented Oct 9, 2019

@buso you should not be following up on a PR unless your comment is strictly relevant to the PR in question.

Github is for issues (things that are broken), not support.

Please read all of the documentation.

https://rocketchat.github.io/docs/getting-support/
https://rocket.chat/docs/

@buso
Copy link

buso commented Oct 9, 2019

@reetp noted. thank you

@adocampo
Copy link

I cannot get it working..my AD is a bit more structured so instead having users on OU=Users,DC=corp,DC=mydomain,DC=com and groups on OU=Groups,DC=corp,DC=mydomain,DC=comI have the following structure:
image
I blurred the enterprise settings, and my coworker's names for privacy issues, but taking in mind my user, I'm on
CN=Angel Docampo,OU=Users,OU=IT Department,OU=company,DC=mydomain,DC=com
And I'm member of

CN=chat-admin,OU=Security Groups,OU=company,DC=mydomain,DC=com
CN=Cloud,OU=Security Groups,OU=company,DC=mydomain,DC=com
CN=Dev,OU=Security Groups,OU=company,DC=mydomain,DC=com
CN=Domain Admins,CN=Users,DC=mydomain,DC=com
CN=Gate,OU=Security Groups,OU=company,DC=mydomain,DC=com
CN=IT,OU=Security Groups,OU=company,DC=mydomain,DC=com
CN=Network Folders,OU=Security Groups,OU=company,DC=mydomain,DC=com
CN=ops,OU=Security Groups,OU=company,DC=mydomain,DC=com

Built-in users and groups are placed on CN=Users,DC=mydomain,DC=com

I want to sync the groups, and what is more important, map users to their group. My settings are:
User Group Filter (&(sAMAccountName=#{username})(memberOf=CN=#{groupName},OU=Security Groups,OU=company,DC=mydomain,DC=com))
LDAP Group BaseDN OU=Security Groups,OU=company,DC=mydomain,DC=com
User Data Group Map

{
	"chat-admin": "admin",
	"IT": "IT"
}

Auto Sync LDAP Groups to Channels True
Channel Admin rocket.cat
LDAP Group Channel Map

	"Chat": "general",
	"IT Department": "it"
}

Logs when syncing is a single line:

I20191015-15:14:50.569(2) server.js:212 LDAPSync ➔ error Error creating user { Error: Email already exists. [403]     at handleError (packages/accounts-password/password_server.js:104:17)     at checkForCaseInsensitiveDuplicates (packages/accounts-password/password_server.js:245:7)     at createUser (packages/accounts-password/password_server.js:1076:3)     at AccountsServer.Accounts.createUser (packages/accounts-password/password_server.js:1147:10)     at addLdapUser (app/ldap/server/sync.js:452:29)     at ldapUsers.forEach.ldapUser (app/ldap/server/sync.js:518:5)     at Array.forEach (<anonymous>)     at ldap.searchUsersSync.Meteor.bindEnvironment (app/ldap/server/sync.js:485:13)     at runWithEnvironment (packages/meteor.js:1286:24)   isClientSafe: true,   error: 403,   reason: 'Email already exists.',   details: undefined,   message: 'Email already exists. [403]',   errorType: 'Meteor.Error' } 

Any tip?

@wreiske
Copy link
Contributor Author

wreiske commented Oct 15, 2019

Any tip?

image

Try checking "Merge Existing users"...

@adocampo
Copy link

Is already checked...

@buso
Copy link

buso commented Oct 15, 2019

@adocampo

Is already checked...

I got my environment to work by setting the LDAP Group Base DN to my Base DN. In your case:

OU=Users,OU=IT Department,OU=company,DC=mydomain,DC=com

Try that. I also noticed that if the user has not been previously imported from AD, on first log-in you get a wrong password error, but clicking on the login button a second time allows login successfully and the auto-join to the room happens.

@adocampo
Copy link

Well, I must say I'm with RocketChat since almost a year and LDAP is working just fine ( I mean user and password import), user doesn't need to login twice or whatsoever.

I cannot use OU=Users,OU=IT Department,OU=company,DC=mydomain,DC=com because then just the people inside IT Department would login, I want all the people inside OU=company,DC=mydomain,DC=com So, I tried as well putting LDAP Group BaseDN and Base DN as OU=company,DC=mydomain,DC=com... no luck.

@buso
Copy link

buso commented Oct 15, 2019

My setup has been working fine authenticating against AD before as well. The double-login started with the channel synchronization update. If I set Sync LDAP Groups to false, then login works fine.

@adocampo
Copy link

adocampo commented Oct 15, 2019

Well, it seems is working. This afternoon I created a test user, and despite on the manual sync, didn't work, this night at 00am when the scheduled sync runs, the user has appeared on the channels I've mapped and with the roles I assigned. \o/

The "Merge existing users" seems to be not working, by the way. Tomorrow I will do more tests with it.

This test user, @buso had no problems logging in my scenario.

@iwonazytkiewicz
Copy link

I am running Rocket.Chat:2.1.0 (in a docker, using docker-compose, on a CentOS). I managed to integrate the authentication with Active Directory server to fetch members of one group to be. But I lack the option to Map LDAP groups to Rocket.Chat user roles. My admin console does not have the window for mapping roles to group, it looks like this (all the same on different browsers and in the client app):
Screen Shot 2019-11-10 at 7 56 26 PM

If this is not the proper place to report this as a bug - feel free to redirect me, I am still trying to find my way around GitHub. Thanks

@reetp
Copy link

reetp commented Nov 11, 2019

If this is not the proper place to report this as a bug - feel free to redirect me, I am still trying to find my way around GitHub. Thanks

Adding to a merge request is not a great place to do this. People will generally ignore it.

You also need to work out if it is a real bug or not.
https://rocketchat.github.io/docs/contributing/reporting-issues/

For help/support please see: https://rocket.chat/docs/getting-support

FWIW I would make sure you have at least 2.1.2 and then check any browser caching. I can see the fields on both 2.1.2 and 2.2.0 even though I do not have it enabled.

@michel-rickhaus
Copy link

I am still unsure whether this is supposed to work in both open and private channels. It certainly closes issues hat mention both but we haven‘t managed to create private groups yet.
Can someone clarify?

@Doordonot
Copy link

I am still unsure whether this is supposed to work in both open and private channels. It certainly closes issues hat mention both but we haven‘t managed to create private groups yet.
Can someone clarify?

It works for open and private Channels. However the first time it creates a Channel it will be public. You have to set it as Private manually, then all other users mapped to join that channel will do so. I have it se up like two channels for each department. One Private and one Public. Every AD user maped on each department auto join the Private and the Public Channel for his/her department.

@phatair
Copy link

phatair commented Feb 5, 2020

Hello,

we are using the following configuration
Server Setup Information
Version of Rocket.Chat Server: 2.4.2
Operating System: Ubuntu LTS
Deployment Method: snap
Number of Running Instances: 1
DB Replicaset Oplog:
NodeJS Version: v8.17.0
MongoDB Version: 3.6.14
Proxy: caddy
Firewalls involved:no

If we enable "Auto Sync LDAP Groups to Channels", one user can login. After this login the Channels are created and now no one else can login to rocket chat. They got an error message "wrong user or passwort". If i logout with this user, the user can not login anymore. I have to delete these channels with the rocket chat admin and then the same happens - i can login one time, channels are created and no login is possible after that.

If i disable LDAP Group to Channel Sync the AD Authenthication is working fine.

The Config looks like this:
Base DN
OU=KTS,DC=my,DC=domain,DC=com
User Group Filter
(&(sAMAccountName=#{username})(memberOf:1.2.840.113556.1.4.1941:=CN=#{groupName},OU=RocketChat,OU=SecurityGroups,OU=KTS,DC=my,DC=domain,DC=com))
LDAP Group BaseDN
OU=KTS,DC=my,DC=domain,DC=com
User Search filter
(&(objectCategory=person)(objectclass=user)(memberOf:1.2.840.113556.1.4.1941:=CN=RC_Users,OU=RocketChat,OU=SecurityGroup,OU=KTS,DC=my,DC=domain,DC=com))

Any Idea whats going wrong? I was doing my first tests with a earlier version and the Group Sync was working fine.

@d-sko
Copy link
Contributor

d-sko commented Jun 3, 2020

Is it possible to use the email address in the group filter?
Because of #3451 we can't use the #{username} variable because it does not match the username in the LDAP directory. The user group filter looked like this:

(&(objectCategory=Person)(sAMAccountName=#{username})(memberOf:1.2.840.113556.1.4.1941:=cn=#{groupName},OU=secGroups,DC=domain,DC=com))

and I tried to change it to

(&(objectCategory=Person)(mail=#{email})(memberOf:1.2.840.113556.1.4.1941:=cn=#{groupName},OU=secGroups,DC=domain,DC=com))

I thought this might work since the email address is synced from LDAP but it looks like it is not available as variable. I also tried changing the regex in Admin > General > UTF8 to allow umlauts in usernames, which works for manually added users, but all LDAP users get their names messed up, so the email address would be a chance to work around #3451.

We're running Rocket.Chat 3.3.0 on docker and our LDAP is an Active Directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment