configuring-active-directory-realm.asciidoc 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. [role="xpack"]
  2. [[configuring-ad-realm]]
  3. === Configuring an Active Directory realm
  4. You can configure {es} to communicate with Active Directory to authenticate
  5. users. To integrate with Active Directory, you configure an `active_directory`
  6. realm and map Active Directory users and groups to roles in the role mapping file.
  7. For more information about Active Directory realms, see
  8. {stack-ov}/active-directory-realm.html[Active Directory User Authentication].
  9. . Add a realm configuration of type `active_directory` to `elasticsearch.yml`
  10. under the `xpack.security.authc.realms.active_directory` namespace.
  11. At a minimum, you must specify the Active Directory `domain_name`.
  12. If you are configuring multiple realms, you should also
  13. explicitly set the `order` attribute to control the order in which the realms
  14. are consulted during authentication.
  15. +
  16. --
  17. See <<ref-ad-settings>> for all of the options you can set for an
  18. `active_directory` realm.
  19. NOTE: Binding to Active Directory fails if the domain name is not mapped in DNS.
  20. If DNS is not being provided by a Windows DNS server, add a mapping for
  21. the domain in the local `/etc/hosts` file.
  22. For example, the following realm configuration configures {es} to connect
  23. to `ldaps://example.com:636` to authenticate users through Active Directory:
  24. [source, yaml]
  25. ------------------------------------------------------------
  26. xpack:
  27. security:
  28. authc:
  29. realms:
  30. active_directory:
  31. my_ad:
  32. order: 0 <1>
  33. domain_name: ad.example.com
  34. url: ldaps://ad.example.com:636 <2>
  35. ------------------------------------------------------------
  36. <1> The realm order controls the order in which the configured realms are checked
  37. when authenticating a user.
  38. <2> If you don't specify the URL, it defaults to `ldap:<domain_name>:389`.
  39. IMPORTANT: When you configure realms in `elasticsearch.yml`, only the
  40. realms you specify are used for authentication. If you also want to use the
  41. `native` or `file` realms, you must include them in the realm chain.
  42. --
  43. . If you are authenticating users across multiple domains in a forest, extra
  44. steps are required. There are a few minor differences in the configuration and
  45. the way that users authenticate.
  46. +
  47. --
  48. Set the `domain_name` setting to the forest root domain name.
  49. You must also set the `url` setting, since you must authenticate against the
  50. Global Catalog, which uses a different port and might not be running on every
  51. Domain Controller.
  52. For example, the following realm configuration configures {es} to connect
  53. to specific Domain Controllers on the Global Catalog port with the domain name
  54. set to the forest root:
  55. [source, yaml]
  56. ------------------------------------------------------------
  57. xpack:
  58. security:
  59. authc:
  60. realms:
  61. active_directory:
  62. my_ad:
  63. order: 0
  64. domain_name: example.com <1>
  65. url: ldaps://dc1.ad.example.com:3269, ldaps://dc2.ad.example.com:3269 <2>
  66. load_balance:
  67. type: "round_robin" <3>
  68. ------------------------------------------------------------
  69. <1> The `domain_name` is set to the name of the root domain in the forest.
  70. <2> The `url` value used in this example has URLs for two different Domain Controllers,
  71. which are also Global Catalog servers. Port 3268 is the default port for unencrypted
  72. communication with the Global Catalog; port 3269 is the default port for SSL connections.
  73. The servers that are being connected to can be in any domain of the forest as long as
  74. they are also Global Catalog servers.
  75. <3> A load balancing setting is provided to indicate the desired behavior when choosing
  76. the server to connect to.
  77. In this configuration, users will need to use either their full User Principal
  78. Name (UPN) or their Down-Level Logon Name. A UPN is typically a concatenation of
  79. the username with `@<DOMAIN_NAME` such as `johndoe@ad.example.com`. The Down-Level
  80. Logon Name is the NetBIOS domain name, followed by a `\` and the username, such as
  81. `AD\johndoe`. Use of Down-Level Logon Name requires a connection to the regular LDAP
  82. ports (389 or 636) in order to query the configuration container to retrieve the
  83. domain name from the NetBIOS name.
  84. --
  85. . (Optional) Configure how {es} should interact with multiple Active
  86. Directory servers.
  87. +
  88. --
  89. The `load_balance.type` setting can be used at the realm level. Two modes of
  90. operation are supported: failover and load balancing. See <<ref-ad-settings>>.
  91. --
  92. . (Optional) To protect passwords,
  93. <<tls-active-directory,encrypt communications between {es} and the Active Directory server>>.
  94. . Restart {es}.
  95. . Configure a bind user.
  96. +
  97. --
  98. The Active Directory realm authenticates users using an LDAP bind request. By
  99. default, all of the LDAP operations are run by the user that {es} is
  100. authenticating. In some cases, regular users may not be able to access all of the
  101. necessary items within Active Directory and a _bind user_ is needed. A bind user
  102. can be configured and is used to perform all operations other than the LDAP bind
  103. request, which is required to authenticate the credentials provided by the user.
  104. The use of a bind user enables the
  105. {stack-ov}/run-as-privilege.html[run as feature] to be used with the Active
  106. Directory realm and the ability to maintain a set of pooled connections to
  107. Active Directory. These pooled connection reduce the number of resources that
  108. must be created and destroyed with every user authentication.
  109. The following example shows the configuration of a bind user through the user of
  110. the `bind_dn` and `secure_bind_password` settings:
  111. [source, yaml]
  112. ------------------------------------------------------------
  113. xpack:
  114. security:
  115. authc:
  116. realms:
  117. active_directory:
  118. my_ad:
  119. order: 0
  120. domain_name: ad.example.com
  121. url: ldaps://ad.example.com:636
  122. bind_dn: es_svc_user@ad.example.com <1>
  123. ------------------------------------------------------------
  124. <1> This is the user that all Active Directory search requests are executed as.
  125. Without a bind user configured, all requests run as the user that is authenticating
  126. with {es}.
  127. The password for the `bind_dn` user should be configured by adding the
  128. appropriate `secure_bind_password` setting to the {es} keystore. For example,
  129. the following command adds the password for the example realm above:
  130. [source, shell]
  131. ------------------------------------------------------------
  132. bin/elasticsearch-keystore add \
  133. xpack.security.authc.realms.active_directory.my_ad.secure_bind_password
  134. ------------------------------------------------------------
  135. When a bind user is configured, connection pooling is enabled by default.
  136. Connection pooling can be disabled using the `user_search.pool.enabled` setting.
  137. --
  138. . Map Active Directory users and groups to roles.
  139. +
  140. --
  141. An integral part of a realm authentication process is to resolve the roles
  142. associated with the authenticated user. Roles define the privileges a user has
  143. in the cluster.
  144. Since with the `active_directory` realm the users are managed externally in the
  145. Active Directory server, the expectation is that their roles are managed there
  146. as well. In fact, Active Directory supports the notion of groups, which often
  147. represent user roles for different systems in the organization.
  148. The `active_directory` realm enables you to map Active Directory users to roles
  149. via their Active Directory groups or other metadata. This role mapping can be
  150. configured via the <<security-role-mapping-apis,role-mapping APIs>> or by using
  151. a file stored on each node. When a user authenticates against an Active
  152. Directory realm, the privileges for that user are the union of all privileges
  153. defined by the roles to which the user is mapped.
  154. Within a mapping definition, you specify groups using their distinguished
  155. names. For example, the following mapping configuration maps the Active
  156. Directory `admins` group to both the `monitoring` and `user` roles, maps the
  157. `users` group to the `user` role and maps the `John Doe` user to the `user`
  158. role.
  159. Configured via the role-mapping API:
  160. [source,js]
  161. --------------------------------------------------
  162. PUT /_security/role_mapping/admins
  163. {
  164. "roles" : [ "monitoring" , "user" ],
  165. "rules" : { "field" : {
  166. "groups" : "cn=admins,dc=example,dc=com" <1>
  167. } },
  168. "enabled": true
  169. }
  170. --------------------------------------------------
  171. // CONSOLE
  172. <1> The Active Directory distinguished name (DN) of the `admins` group.
  173. [source,js]
  174. --------------------------------------------------
  175. PUT /_security/role_mapping/basic_users
  176. {
  177. "roles" : [ "user" ],
  178. "rules" : { "any": [
  179. { "field" : {
  180. "groups" : "cn=users,dc=example,dc=com" <1>
  181. } },
  182. { "field" : {
  183. "dn" : "cn=John Doe,cn=contractors,dc=example,dc=com" <2>
  184. } }
  185. ] },
  186. "enabled": true
  187. }
  188. --------------------------------------------------
  189. // CONSOLE
  190. <1> The Active Directory distinguished name (DN) of the `users` group.
  191. <2> The Active Directory distinguished name (DN) of the user `John Doe`.
  192. Or, alternatively, configured via the role-mapping file:
  193. [source, yaml]
  194. ------------------------------------------------------------
  195. monitoring: <1>
  196. - "cn=admins,dc=example,dc=com" <2>
  197. user:
  198. - "cn=users,dc=example,dc=com" <3>
  199. - "cn=admins,dc=example,dc=com"
  200. - "cn=John Doe,cn=contractors,dc=example,dc=com" <4>
  201. ------------------------------------------------------------
  202. <1> The name of the role.
  203. <2> The Active Directory distinguished name (DN) of the `admins` group.
  204. <3> The Active Directory distinguished name (DN) of the `users` group.
  205. <4> The Active Directory distinguished name (DN) of the user `John Doe`.
  206. For more information, see
  207. {stack-ov}/mapping-roles.html[Mapping users and groups to roles].
  208. --
  209. . (Optional) Configure the `metadata` setting in the Active Directory realm to
  210. include extra properties in the user's metadata.
  211. +
  212. --
  213. By default, `ldap_dn` and `ldap_groups` are populated in the user's metadata.
  214. For more information, see
  215. {xpack-ref}/active-directory-realm.html#ad-user-metadata[User Metadata in Active Directory Realms].
  216. --