configuring-ldap-realm.asciidoc 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. [role="xpack"]
  2. [[configuring-ldap-realm]]
  3. === Configuring an LDAP realm
  4. You can configure {security} to communicate with a Lightweight Directory Access
  5. Protocol (LDAP) server to authenticate users. To integrate with LDAP, you
  6. configure an `ldap` realm and map LDAP groups to user roles.
  7. For more information about LDAP realms, see
  8. {xpack-ref}/ldap-realm.html[LDAP User Authentication].
  9. . Determine which mode you want to use. The `ldap` realm supports two modes of
  10. operation, a user search mode and a mode with specific templates for user DNs.
  11. +
  12. --
  13. LDAP user search is the most common mode of operation. In this mode, a specific
  14. user with permission to search the LDAP directory is used to search for the DN
  15. of the authenticating user based on the provided username and an LDAP attribute.
  16. Once found, the user is authenticated by attempting to bind to the LDAP server
  17. using the found DN and the provided password.
  18. If your LDAP environment uses a few specific standard naming conditions for
  19. users, you can use user DN templates to configure the realm. The advantage of
  20. this method is that a search does not have to be performed to find the user DN.
  21. However, multiple bind operations might be needed to find the correct user DN.
  22. --
  23. . To configure an `ldap` realm with user search:
  24. .. Add a realm configuration of type `ldap` to `elasticsearch.yml` under the
  25. `xpack.security.authc.realms` namespace. At a minimum, you must set the realm
  26. `type` to `ldap`, specify the `url` of the LDAP server, and set
  27. `user_search.base_dn` to the container DN where the users are searched for. If
  28. you are configuring multiple realms, you should also explicitly set the `order`
  29. attribute to control the order in which the realms are consulted during
  30. authentication. See <<ref-ldap-settings>> for all of the options you can set for
  31. an `ldap` realm.
  32. +
  33. --
  34. For example, the following snippet shows an LDAP realm configured with a user search:
  35. [source, yaml]
  36. ------------------------------------------------------------
  37. xpack:
  38. security:
  39. authc:
  40. realms:
  41. ldap1:
  42. type: ldap
  43. order: 0
  44. url: "ldaps://ldap.example.com:636"
  45. bind_dn: "cn=ldapuser, ou=users, o=services, dc=example, dc=com"
  46. user_search:
  47. base_dn: "dc=example,dc=com"
  48. attribute: cn
  49. group_search:
  50. base_dn: "dc=example,dc=com"
  51. files:
  52. role_mapping: "ES_PATH_CONF/role_mapping.yml"
  53. unmapped_groups_as_roles: false
  54. ------------------------------------------------------------
  55. The password for the `bind_dn` user should be configured by adding the appropriate
  56. `secure_bind_password` setting to the {es} keystore.
  57. For example, the following command adds the password for the example realm above:
  58. [source, shell]
  59. ------------------------------------------------------------
  60. bin/elasticsearch-keystore add \
  61. xpack.security.authc.realms.ldap1.secure_bind_password
  62. ------------------------------------------------------------
  63. IMPORTANT: When you configure realms in `elasticsearch.yml`, only the
  64. realms you specify are used for authentication. If you also want to use the
  65. `native` or `file` realms, you must include them in the realm chain.
  66. --
  67. . To configure an `ldap` realm with user DN templates:
  68. .. Add a realm configuration of type `ldap` to `elasticsearch.yml` in the
  69. `xpack.security.authc.realms` namespace. At a minimum, you must set the realm
  70. `type` to `ldap`, specify the `url` of the LDAP server, and specify at least one
  71. template with the `user_dn_templates` option. If you are configuring multiple
  72. realms, you should also explicitly set the `order` attribute to control the
  73. order in which the realms are consulted during authentication. See
  74. <<ref-ldap-settings>> for all of the options you can set for an `ldap` realm.
  75. +
  76. --
  77. For example, the following snippet shows an LDAP realm configured with user DN
  78. templates:
  79. [source, yaml]
  80. ------------------------------------------------------------
  81. xpack:
  82. security:
  83. authc:
  84. realms:
  85. ldap1:
  86. type: ldap
  87. order: 0
  88. url: "ldaps://ldap.example.com:636"
  89. user_dn_templates:
  90. - "cn={0}, ou=users, o=marketing, dc=example, dc=com"
  91. - "cn={0}, ou=users, o=engineering, dc=example, dc=com"
  92. group_search:
  93. base_dn: "dc=example,dc=com"
  94. files:
  95. role_mapping: "/mnt/elasticsearch/group_to_role_mapping.yml"
  96. unmapped_groups_as_roles: false
  97. ------------------------------------------------------------
  98. IMPORTANT: The `bind_dn` setting is not used in template mode.
  99. All LDAP operations run as the authenticating user.
  100. --
  101. . (Optional) Configure how {security} should interact with multiple LDAP servers.
  102. +
  103. --
  104. The `load_balance.type` setting can be used at the realm level. {security}
  105. supports both failover and load balancing modes of operation. See
  106. <<ref-ldap-settings>>.
  107. --
  108. . (Optional) To protect passwords,
  109. <<tls-ldap,encrypt communications between {es} and the LDAP server>>.
  110. . Restart {es}.
  111. . Map LDAP groups to roles.
  112. +
  113. --
  114. The `ldap` realm enables you to map LDAP users to to roles via their LDAP
  115. groups, or other metadata. This role mapping can be configured via the
  116. {ref}/security-api-put-role-mapping.html[add role mapping API] or by using a file stored
  117. on each node. When a user authenticates with LDAP, the privileges
  118. for that user are the union of all privileges defined by the roles to which
  119. the user is mapped.
  120. Within a mapping definition, you specify groups using their distinguished
  121. names. For example, the following mapping configuration maps the LDAP
  122. `admins` group to both the `monitoring` and `user` roles, and maps the
  123. `users` group to the `user` role.
  124. Configured via the role-mapping API:
  125. [source,js]
  126. --------------------------------------------------
  127. PUT _xpack/security/role_mapping/admins
  128. {
  129. "roles" : [ "monitoring" , "user" ],
  130. "rules" : { "field" : {
  131. "groups" : "cn=admins,dc=example,dc=com" <1>
  132. } },
  133. "enabled": true
  134. }
  135. --------------------------------------------------
  136. // CONSOLE
  137. <1> The LDAP distinguished name (DN) of the `admins` group.
  138. [source,js]
  139. --------------------------------------------------
  140. PUT _xpack/security/role_mapping/basic_users
  141. {
  142. "roles" : [ "user" ],
  143. "rules" : { "field" : {
  144. "groups" : "cn=users,dc=example,dc=com" <1>
  145. } },
  146. "enabled": true
  147. }
  148. --------------------------------------------------
  149. // CONSOLE
  150. <1> The LDAP distinguished name (DN) of the `users` group.
  151. Or, alternatively, configured via the role-mapping file:
  152. [source, yaml]
  153. ------------------------------------------------------------
  154. monitoring: <1>
  155. - "cn=admins,dc=example,dc=com" <2>
  156. user:
  157. - "cn=users,dc=example,dc=com" <3>
  158. - "cn=admins,dc=example,dc=com"
  159. ------------------------------------------------------------
  160. <1> The name of the mapped role.
  161. <2> The LDAP distinguished name (DN) of the `admins` group.
  162. <3> The LDAP distinguished name (DN) of the `users` group.
  163. For more information, see
  164. {xpack-ref}/ldap-realm.html#mapping-roles-ldap[Mapping LDAP Groups to Roles]
  165. and
  166. {xpack-ref}/mapping-roles.html[Mapping Users and Groups to Roles].
  167. NOTE: The LDAP realm supports
  168. {stack-ov}/realm-chains.html#authorization_realms[authorization realms] as an
  169. alternative to role mapping.
  170. --
  171. . (Optional) Configure the `metadata` setting on the LDAP realm to include extra
  172. fields in the user's metadata.
  173. +
  174. --
  175. By default, `ldap_dn` and `ldap_groups` are populated in the user's metadata.
  176. For more information, see
  177. {xpack-ref}/ldap-realm.html#ldap-user-metadata[User Metadata in LDAP Realms].
  178. The example below includes the user's common name (`cn`) as an additional
  179. field in their metadata.
  180. [source,yaml]
  181. --------------------------------------------------
  182. xpack:
  183. security:
  184. authc:
  185. realms:
  186. ldap1:
  187. type: ldap
  188. metadata: cn
  189. --------------------------------------------------
  190. --