configuring-ldap-realm.asciidoc 7.0 KB

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