# Failed to assign role via role mapping API ldap realm

**URL:** <https://discuss.elastic.co/t/failed-to-assign-role-via-role-mapping-api-ldap-realm/331039>\
**Category:** Kibana\
**Created:** [April 28, 2023, 9:59am UTC](https://discuss.elastic.co/t/failed-to-assign-role-via-role-mapping-api-ldap-realm/331039 "2023-04-28T09:59:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![GaetanCia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gaetancia/32/120123_2.png) [@GaetanCia](https://discuss.elastic.co/u/GaetanCia)\
**Post date:** [April 28, 2023, 9:59am UTC](https://discuss.elastic.co/t/failed-to-assign-role-via-role-mapping-api-ldap-realm/331039/1 "2023-04-28T09:59:04Z")

</div>

Hi,  
I have issue to assign a role via the role-mapping setting.

I tried to assign a role to a certain group of people who connect from the ldap realm.  
If i use the native role mapping file, it work fine

My role\_mapping.yml look like this:

```auto
Role mapping configuration file which has elasticsearch roles as keys
# that map to one or more user or group distinguished names

#roleA: this is an elasticsearch role
# - groupA-DN this is a group distinguished name
# - groupB-DN
# - user1-DN this is the full user distinguished name

#power_user:
# - "cn=admins,dc=example,dc=com"
#user:
# - "cn=users,dc=example,dc=com"
# - "cn=admins,dc=example,dc=com"
# - "cn=John Doe,cn=other users,dc=example,dc=com"
My-role:
   - "cn=the_groupe,ou=mother_group,ou=um,ou=groups,dc=mydomain,dc=com"

```

My role mapped from the API :

```auto
 "Agent-viewer": {
    "enabled": true,
    "roles": [
      "My-role"
    ],
    "rules": {
      "field": {
        "dn": "cn=the_groupe,ou=mother_group,ou=um,ou=groups,dc=mydomain,dc=com"
      }
    },
    "metadata": {}
  }

```

log when i'm not using role\_mapping.yml :

```auto
[2023-04-28T11:43:26,174][DEBUG][o.e.x.s.a.l.LdapUserSearchSessionFactory] [elastic-mydomain.com] Resolved 6 LDAP groups [[#MY group]] for user [uid=xxxxxx,ou=people,dc=mydomain,dc=com]
[2023-04-28T11:43:26,174][DEBUG][o.e.x.s.a.s.DnRoleMapper] [elastic-mydomain.com] the roles [[]], are mapped from the user [uid=xxxxxx,ou=people,dc=mydomain,dc=com] using file [role_mapping.yml] for realm [ldap/ldap1]

```

log when i suer role\_mapping.yml:

```auto
[2023-04-28T11:49:45,480][DEBUG][o.e.x.s.a.s.DnRoleMapper] [elastic-mydomain.com] the roles [[My-role]], are mapped from these [ldap] groups [[MYGROUP]] using file [role_mapping.yml] for realm [ldap/ldap1]
[2023-04-28T11:49:45,486][DEBUG][o.e.x.s.a.l.LdapRealm] [prodelastic-hot1.infra.umontpellier.fr] realm [ldap1] authenticated user [xxxxx], with roles [[My-role]] (cached)

```

I have tried to create the role mapping with the api and kibana (stack-management/role-mapping).

If i copy paste the dn given in my role\_mapping.yml in the API or kibana tool the user cannot loggin. SO i suppose it's not a problem of syntax.

How should i approche this issue ?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 26, 2023, 9:59am UTC](https://discuss.elastic.co/t/failed-to-assign-role-via-role-mapping-api-ldap-realm/331039/2 "2023-05-26T09:59:19Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
