# LDAP sync makes all users admins

**URL:** <https://forums.rocket.chat/t/ldap-sync-makes-all-users-admins/11477>\
**Category:** Community Support\
**Created:** [June 24, 2021, 8:41pm UTC](https://forums.rocket.chat/t/ldap-sync-makes-all-users-admins/11477 "2021-06-24T20:41:23Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![MattBerryWWT](https://avatars.discourse-cdn.com/v4/letter/m/dc4da7/32.png) [@MattBerryWWT](https://forums.rocket.chat/u/MattBerryWWT)\
**Post date:** [June 24, 2021, 8:41pm UTC](https://forums.rocket.chat/t/ldap-sync-makes-all-users-admins/11477/1 "2021-06-24T20:41:23Z")

</div>

### Description

New Rocket chat installation. When I run an LDAP sync, every imported account is set as an administrator. Not good. So I followed instructions to drop all my LDAP users from the MongoDB.

I have gone back and set the “User Data Group Map” to map LDAP groups to Rocket’s admin roles, but that’s not working either. Any idea on what I am doing wrong here?

{  
“Team01”: “user”,  
“Team02”: “user”,  
“Team03”: “user”,  
“Team04”: “user”,  
“Team05”: “user”,  
“Team06”: “user”,  
“ChatAdmins”: “admin”  
}

### Server Setup Information

- Version of Rocket.Chat Server: 3.15.1
- Operating System: Ubuntu 20
- Deployment Method: Install guide on rocket.chat
- Number of Running Instances: 1
- DB Replicaset Oplog:
- NodeJS Version:
- MongoDB Version: Latest
- Proxy: None
- Firewalls involved: None

### Any additional Information

---

<div class="post-metadata">

**Author:** ![john.crisp](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/john.crisp/32/2711_2.png) [@john.crisp](https://forums.rocket.chat/u/john.crisp)\
**Post date:** [June 24, 2021, 9:47pm UTC](https://forums.rocket.chat/t/ldap-sync-makes-all-users-admins/11477/2 "2021-06-24T21:47:09Z")

</div>

What errors do you get in your logs?

---

<div class="post-metadata">

**Author:** ![MattBerryWWT](https://avatars.discourse-cdn.com/v4/letter/m/dc4da7/32.png) [@MattBerryWWT](https://forums.rocket.chat/u/MattBerryWWT)\
**Post date:** [June 24, 2021, 10:00pm UTC](https://forums.rocket.chat/t/ldap-sync-makes-all-users-admins/11477/3 "2021-06-24T22:00:34Z")

</div>

I’m not really seeing any errors that point to an issue during import. I just wonder if it’s a configuration problem.

---

<div class="post-metadata">

**Author:** ![john.crisp](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/john.crisp/32/2711_2.png) [@john.crisp](https://forums.rocket.chat/u/john.crisp)\
**Post date:** [June 24, 2021, 10:06pm UTC](https://forums.rocket.chat/t/ldap-sync-makes-all-users-admins/11477/4 "2021-06-24T22:06:49Z")

</div>

There will almost certainly be an error in your logs somewhere.

Check your log levels and then have a good look as you run the command to sync.

If you are on snaps there is information in the docs on how to check you your logs.

---

<div class="post-metadata">

**Author:** ![MattBerryWWT](https://avatars.discourse-cdn.com/v4/letter/m/dc4da7/32.png) [@MattBerryWWT](https://forums.rocket.chat/u/MattBerryWWT)\
**Post date:** [June 25, 2021, 2:17pm UTC](https://forums.rocket.chat/t/ldap-sync-makes-all-users-admins/11477/5 "2021-06-25T14:17:22Z")

</div>

See the debug below for one particular user (tm03-usr2). I have verified that in AD this user is only a member of Domain Users and Team03. However, if you look at the debug below, it tells me that it matches for a bunch of other teams (Team01-Team06) and an admin role.

I20210625-09:09:45.818(-5) LDAPSync ➔ info Syncing user data  
I20210625-09:09:45.818(-5) LDAPSync ➔ debug user { email: ‘tm03-usr2@atccrl.com’, \_id: ‘XsQa8rrN73xFwbAER’ }  
I20210625-09:09:45.819(-5) LDAPSync ➔ debug ldapUser undefined  
I20210625-09:09:45.820(-5) LDAPSync ➔ debug user.name changed to: tm03-usr2  
I20210625-09:09:45.821(-5) LDAPSync ➔ debug User role exists for mapping Team01 → user  
I20210625-09:09:45.832(-5) LDAP ➔ Search.info Search result count 7  
I20210625-09:09:45.832(-5) LDAPSync ➔ debug tm03-usr2 is in Team01 group.  
I20210625-09:09:45.833(-5) LDAPSync ➔ debug User role exists for mapping Team02 → user  
I20210625-09:09:45.838(-5) LDAP ➔ Search.info Search result count 7  
I20210625-09:09:45.838(-5) LDAPSync ➔ debug tm03-usr2 is in Team02 group.  
I20210625-09:09:45.838(-5) LDAPSync ➔ debug User role exists for mapping Team03 → user  
I20210625-09:09:45.844(-5) LDAP ➔ Search.info Search result count 7  
I20210625-09:09:45.844(-5) LDAPSync ➔ debug tm03-usr2 is in Team03 group.  
I20210625-09:09:45.845(-5) LDAPSync ➔ debug User role exists for mapping Team04 → user  
I20210625-09:09:45.850(-5) LDAP ➔ Search.info Search result count 7  
I20210625-09:09:45.850(-5) LDAPSync ➔ debug tm03-usr2 is in Team04 group.  
I20210625-09:09:45.850(-5) LDAPSync ➔ debug User role exists for mapping Team05 → user  
I20210625-09:09:45.857(-5) LDAP ➔ Search.info Search result count 7  
I20210625-09:09:45.857(-5) LDAPSync ➔ debug tm03-usr2 is in Team05 group.  
I20210625-09:09:45.858(-5) LDAPSync ➔ debug User role exists for mapping Team06 → user  
I20210625-09:09:45.863(-5) LDAP ➔ Search.info Search result count 7  
I20210625-09:09:45.863(-5) LDAPSync ➔ debug tm03-usr2 is in Team06 group.  
I20210625-09:09:45.864(-5) LDAPSync ➔ debug User role exists for mapping ChatAdmins → admin  
I20210625-09:09:45.870(-5) LDAP ➔ Search.info Search result count 7  
I20210625-09:09:45.870(-5) LDAPSync ➔ debug tm03-usr2 is in ChatAdmins group.  
I20210625-09:09:45.870(-5) server.js:204 LDAPSync ➔ error Unexpected error : Unexpected string in JSON at position 71  
I20210625-09:09:45.871(-5) LDAPSync ➔ debug setting { “name”: “tm03-usr2”, “emails”: [{ “address”: “[tm03-usr2@atccrl.com](mailto:tm03-usr2@atccrl.com)”, “verified”: true } ], “services.ldap.id”: “6881ce36be6ede4a9ab316d05fa92c82”, “services.ldap.idAttribute”: “objectGUID”, “ldap”: true }  
I20210625-09:09:45.876(-5) LDAPSync ➔ info Synced user group user from LDAP for tm03-usr2  
I20210625-09:09:45.878(-5) LDAPSync ➔ info Synced user group user from LDAP for tm03-usr2  
I20210625-09:09:45.881(-5) LDAPSync ➔ info Synced user group user from LDAP for tm03-usr2  
I20210625-09:09:45.882(-5) LDAPSync ➔ info Synced user group user from LDAP for tm03-usr2  
I20210625-09:09:45.885(-5) LDAPSync ➔ info Synced user group user from LDAP for tm03-usr2  
I20210625-09:09:45.888(-5) LDAPSync ➔ info Synced user group user from LDAP for tm03-usr2  
I20210625-09:09:45.890(-5) LDAPSync ➔ info Synced user group admin from LDAP for tm03-usr2

---

<div class="post-metadata">

**Author:** ![MattBerryWWT](https://avatars.discourse-cdn.com/v4/letter/m/dc4da7/32.png) [@MattBerryWWT](https://forums.rocket.chat/u/MattBerryWWT)\
**Post date:** [June 25, 2021, 7:38pm UTC](https://forums.rocket.chat/t/ldap-sync-makes-all-users-admins/11477/6 "2021-06-25T19:38:29Z")

</div>

@john.crisp - Any ideas here?

---

<div class="post-metadata">

**Author:** ![john.crisp](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/john.crisp/32/2711_2.png) [@john.crisp](https://forums.rocket.chat/u/john.crisp)\
**Post date:** [June 28, 2021, 9:24am UTC](https://forums.rocket.chat/t/ldap-sync-makes-all-users-admins/11477/7 "2021-06-28T09:24:35Z")

</div>

Please don’t @ - it isn’t necessary. I read everything here…

I have asked a dev about this. I’ll let you know when I hear back.

---

<div class="post-metadata">

**Author:** ![john.crisp](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/john.crisp/32/2711_2.png) [@john.crisp](https://forums.rocket.chat/u/john.crisp)\
**Post date:** [June 28, 2021, 3:53pm UTC](https://forums.rocket.chat/t/ldap-sync-makes-all-users-admins/11477/8 "2021-06-28T15:53:05Z")

</div>

OK, I had a word with a dev on this.

He thing it is a mis-configuration in your group settings.

Can you check those and paste/screen shot anything here.

Also note that 3.16 is just released so it might be worth a quick test is possible.

---

<div class="post-metadata">

**Author:** ![MattBerryWWT](https://avatars.discourse-cdn.com/v4/letter/m/dc4da7/32.png) [@MattBerryWWT](https://forums.rocket.chat/u/MattBerryWWT)\
**Post date:** [June 28, 2021, 9:51pm UTC](https://forums.rocket.chat/t/ldap-sync-makes-all-users-admins/11477/9 "2021-06-28T21:51:40Z")

</div>

First things first. I upgraded to 3.16 to reduce the possibility of a software bug. Same behavior.

I gathered the following group settings from the LDAP section.

**User Group Filter**  
(&(sAMAccountName=#{username})(memberOf:1.2.840.113556.1.4.1941:=CN=Chat\*,DC=wwtvcf,DC=local)(objectCategory=person)(objectClass=user))

**LDAP Group BaseDN**  
DC=wwtvcf,DC=local

**User Data Group Map**  
{“ChatAdmins”:“admin”, “ChatPlayers”:“user”}

**LDAP Group Channel Map**  
{  
“ChatPlayers”: [“notifications”,“town-square”,“helpdesk”]  
“ChatAdmins”: [“notifications”,“town-square”,“helpdesk”,“range-admins”]  
}

**Frozen Spider ADMIN “frozenspider” AD Membership**

 ![image](https://us1.discourse-cdn.com/flex021/uploads/rocketchat/original/2X/0/0ef5c4de6d7a11f011f9d08bacde4eae85ff6701.png)

**Behavior 1**  
Every user imported is now a _user_ but those in the _ChatAdmins_ group do not get defined as_admins_.

**Behavior 2**  
Users are not getting their channel mappings that I defined. They all have just the town-square

Let me know if you want anything else not included. Thanks, John.

**Fresh Logging Follows**  
[https://pastebin.com/raw/2T7qXFV0](https://pastebin.com/raw/2T7qXFV0)

---

<div class="post-metadata">

**Author:** ![john.crisp](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/john.crisp/32/2711_2.png) [@john.crisp](https://forums.rocket.chat/u/john.crisp)\
**Post date:** [June 29, 2021, 12:34pm UTC](https://forums.rocket.chat/t/ldap-sync-makes-all-users-admins/11477/10 "2021-06-29T12:34:53Z")

</div>

The dev commented:

> The logs says there’s an invalid json, and they seem to be missing a comma on the ‘LDAP Group Channel Map’ json

---

<div class="post-metadata">

**Author:** ![MattBerryWWT](https://avatars.discourse-cdn.com/v4/letter/m/dc4da7/32.png) [@MattBerryWWT](https://forums.rocket.chat/u/MattBerryWWT)\
**Post date:** [June 29, 2021, 1:10pm UTC](https://forums.rocket.chat/t/ldap-sync-makes-all-users-admins/11477/11 "2021-06-29T13:10:44Z")

</div>

How would I fix an invalid JSON? This is a plain vanilla install with no customizations outside of what has been configured in the GUI. I can check on the missing comma in the interim.

---

<div class="post-metadata">

**Author:** ![MattBerryWWT](https://avatars.discourse-cdn.com/v4/letter/m/dc4da7/32.png) [@MattBerryWWT](https://forums.rocket.chat/u/MattBerryWWT)\
**Post date:** [June 29, 2021, 1:18pm UTC](https://forums.rocket.chat/t/ldap-sync-makes-all-users-admins/11477/12 "2021-06-29T13:18:46Z")

</div>

I believe I fixed the command issue. You didn’t tell me where the comma was missing so I guessed.

![image](https://us1.discourse-cdn.com/flex021/uploads/rocketchat/original/2X/0/0a0de9d549d54deaee4c83e108aca36023d6efd9.png)

After making the change, I deleted my users from the database and reimported.

Still have the same issue.

Any suggestion on how to fix the invalid JSON?

---

<div class="post-metadata">

**Author:** ![john.crisp](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/john.crisp/32/2711_2.png) [@john.crisp](https://forums.rocket.chat/u/john.crisp)\
**Post date:** [June 29, 2021, 1:38pm UTC](https://forums.rocket.chat/t/ldap-sync-makes-all-users-admins/11477/13 "2021-06-29T13:38:12Z")

</div>

Regrading your first part we think

The `User Group Filter` setting is used to validate if the user is in the group, the value they are using is:

`(&(sAMAccountName=#{username})(memberOf:1.2.840.113556.1.4.1941:=CN=Chat*,DC=wwtvcf,DC=local)(objectCategory=person)(objectClass=user))`

This is probably not what they want, since this query is not using the groupname variable  
(`#{groupName}`)

This query is executed for each group in the json.

My guess is that they need to replace `Chat*` with `#{groupName}`

---

<div class="post-metadata">

**Author:** ![pierre.lehnen](https://avatars.discourse-cdn.com/v4/letter/p/ccd318/32.png) [@pierre.lehnen](https://forums.rocket.chat/u/pierre.lehnen)\
**Post date:** [June 29, 2021, 2:27pm UTC](https://forums.rocket.chat/t/ldap-sync-makes-all-users-admins/11477/14 "2021-06-29T14:27:59Z")

</div>

It looks correct now, do you still get the Invalid JSON error on the logs?

---

<div class="post-metadata">

**Author:** ![MattBerryWWT](https://avatars.discourse-cdn.com/v4/letter/m/dc4da7/32.png) [@MattBerryWWT](https://forums.rocket.chat/u/MattBerryWWT)\
**Post date:** [June 29, 2021, 4:03pm UTC](https://forums.rocket.chat/t/ldap-sync-makes-all-users-admins/11477/15 "2021-06-29T16:03:28Z")

</div>

Gents, I finally gave up. I decided to just use a single channel/room to avoid all the headaches.

Thanks for the assistance, but I ran out of time to troubleshoot further.
