configuring-ldap-realm.asciidoc 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. [role="xpack"]
  2. [[configuring-ldap-realm]]
  3. === Configuring an LDAP realm
  4. You can configure {es} to authenticate users by communicating with a Lightweight
  5. Directory Access Protocol (LDAP) server. To integrate with LDAP, you configure
  6. an `ldap` realm and map LDAP groups to user roles.
  7. For more information about LDAP realms, see
  8. {stack-ov}/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 to `elasticsearch.yml` under the
  25. `xpack.security.authc.realms.ldap` namespace. At a minimum, you must specify
  26. the `url` of the LDAP server, and set `user_search.base_dn` to the container DN
  27. where the users are searched for.
  28. If you are configuring multiple realms, you should also explicitly set the
  29. `order` 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. ldap:
  42. ldap1:
  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. filter: "(cn={0})"
  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.ldap.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 to `elasticsearch.yml` in the
  69. `xpack.security.authc.realms.ldap` namespace. At a minimum, you must specify
  70. the `url` of the LDAP server, and specify at least one template with the
  71. `user_dn_templates` option. If you are configuring multiple realms, you should
  72. also explicitly set the `order` attribute to control the order in which the
  73. realms are consulted during authentication.
  74. See <<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. ldap:
  86. ldap1:
  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 the {security-features} interact with multiple LDAP
  102. servers.
  103. +
  104. --
  105. The `load_balance.type` setting can be used at the realm level. The {es}
  106. {security-features} support both failover and load balancing modes of operation.
  107. See <<ref-ldap-settings>>.
  108. --
  109. . (Optional) To protect passwords,
  110. <<tls-ldap,encrypt communications between {es} and the LDAP server>>.
  111. . Restart {es}.
  112. . Map LDAP groups to roles.
  113. +
  114. --
  115. The `ldap` realm enables you to map LDAP users to roles via their LDAP
  116. groups, or other metadata. This role mapping can be configured via the
  117. {ref}/security-api-put-role-mapping.html[add role mapping API] or by using a file stored
  118. on each node. When a user authenticates with LDAP, the privileges
  119. for that user are the union of all privileges defined by the roles to which
  120. the user is mapped.
  121. Within a mapping definition, you specify groups using their distinguished
  122. names. For example, the following mapping configuration maps the LDAP
  123. `admins` group to both the `monitoring` and `user` roles, and maps the
  124. `users` group to the `user` role.
  125. Configured via the role-mapping API:
  126. [source,js]
  127. --------------------------------------------------
  128. PUT /_security/role_mapping/admins
  129. {
  130. "roles" : [ "monitoring" , "user" ],
  131. "rules" : { "field" : {
  132. "groups" : "cn=admins,dc=example,dc=com" <1>
  133. } },
  134. "enabled": true
  135. }
  136. --------------------------------------------------
  137. // CONSOLE
  138. <1> The LDAP distinguished name (DN) of the `admins` group.
  139. [source,js]
  140. --------------------------------------------------
  141. PUT /_security/role_mapping/basic_users
  142. {
  143. "roles" : [ "user" ],
  144. "rules" : { "field" : {
  145. "groups" : "cn=users,dc=example,dc=com" <1>
  146. } },
  147. "enabled": true
  148. }
  149. --------------------------------------------------
  150. // CONSOLE
  151. <1> The LDAP distinguished name (DN) of the `users` group.
  152. Or, alternatively, configured via the role-mapping file:
  153. [source, yaml]
  154. ------------------------------------------------------------
  155. monitoring: <1>
  156. - "cn=admins,dc=example,dc=com" <2>
  157. user:
  158. - "cn=users,dc=example,dc=com" <3>
  159. - "cn=admins,dc=example,dc=com"
  160. ------------------------------------------------------------
  161. <1> The name of the mapped role.
  162. <2> The LDAP distinguished name (DN) of the `admins` group.
  163. <3> The LDAP distinguished name (DN) of the `users` group.
  164. For more information, see
  165. {stack-ov}/ldap-realm.html#mapping-roles-ldap[Mapping LDAP Groups to Roles]
  166. and
  167. {stack-ov}/mapping-roles.html[Mapping Users and Groups to Roles].
  168. NOTE: The LDAP realm supports
  169. {stack-ov}/realm-chains.html#authorization_realms[authorization realms] as an
  170. alternative to role mapping.
  171. --
  172. . (Optional) Configure the `metadata` setting on the LDAP realm to include extra
  173. fields in the user's metadata.
  174. +
  175. --
  176. By default, `ldap_dn` and `ldap_groups` are populated in the user's metadata.
  177. For more information, see
  178. {stack-ov}/ldap-realm.html#ldap-user-metadata[User Metadata in LDAP Realms].
  179. The example below includes the user's common name (`cn`) as an additional
  180. field in their metadata.
  181. [source,yaml]
  182. --------------------------------------------------
  183. xpack:
  184. security:
  185. authc:
  186. realms:
  187. ldap:
  188. ldap1:
  189. metadata: cn
  190. --------------------------------------------------
  191. --