mapping-roles.asciidoc 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. [role="xpack"]
  2. [[mapping-roles]]
  3. === Mapping users and groups to roles
  4. If you authenticate users with the `native` or `file` realms, you can manage
  5. role assignment by using the <<managing-native-users, User Management APIs>> or
  6. the {ref}/users-command.html[users] command-line tool respectively.
  7. For other types of realms, you must create _role-mappings_ that define which
  8. roles should be assigned to each user based on their username, groups, or
  9. other metadata.
  10. You can define role-mappings via an
  11. <<mapping-roles-api, API>> or manage them through <<mapping-roles-file, files>>.
  12. These two sources of role-mapping are combined inside of the {es}
  13. {security-features}, so it is
  14. possible for a single user to have some roles that have been mapped through
  15. the API, and other roles that are mapped through files.
  16. When you use role-mappings, you assign existing roles to users.
  17. The available roles should either be added using the
  18. {ref}/security-api.html#security-role-apis[role management APIs] or defined in the
  19. <<roles-management-file, roles file>>. Either role-mapping method can use
  20. either role management method. For example, when you use the role mapping API,
  21. you are able to map users to both API-managed roles and file-managed roles
  22. (and likewise for file-based role-mappings).
  23. NOTE: The PKI, LDAP, Kerberos and SAML realms support using
  24. <<authorization_realms, authorization realms>> as an alternative to role mapping.
  25. NOTE: When <<anonymous-access, anonymous access>> is enabled, the roles
  26. of the anonymous user are assigned to all the other users as well.
  27. NOTE: Users with no roles assigned will be unauthorized for any action.
  28. [[mapping-roles-api]]
  29. ==== Using the role mapping API
  30. You can define role-mappings through the
  31. {ref}/security-api-put-role-mapping.html[add role mapping API].
  32. [[mapping-roles-file]]
  33. ==== Using role mapping files
  34. To use file based role-mappings, you must configure the mappings in a YAML file
  35. and copy it to each node in the cluster. Tools like Puppet or Chef can help with
  36. this.
  37. By default, role mappings are stored in `ES_PATH_CONF/role_mapping.yml`,
  38. where `ES_PATH_CONF` is `ES_HOME/config` (zip/tar installations) or
  39. `/etc/elasticsearch` (package installations). To specify a different location,
  40. you configure the `files.role_mapping` setting in the
  41. {ref}/security-settings.html#ref-ad-settings[Active Directory],
  42. {ref}/security-settings.html#ref-ldap-settings[LDAP], and
  43. {ref}/security-settings.html#ref-pki-settings[PKI] realm settings in
  44. `elasticsearch.yml`.
  45. Within the role mapping file, the security roles are keys and groups and users
  46. are values. The mappings can have a many-to-many relationship. When you map roles
  47. to groups, the roles of a user in that group are the combination of the roles
  48. assigned to that group and the roles assigned to that user.
  49. By default, {es} checks role mapping files for changes every 5 seconds.
  50. You can change this default behavior by changing the
  51. `resource.reload.interval.high` setting in the `elasticsearch.yml` file. Since
  52. this is a common setting in Elasticsearch, changing its value might effect other
  53. schedules in the system.
  54. While the _role mapping APIs_ is he preferred way to manage role mappings, using
  55. the `role_mappings.yml` file becomes useful in a couple of use cases:
  56. . If you want to define fixed role mappings that no one (besides an administrator
  57. with physical access to the {es} nodes) would be able to change.
  58. . If cluster administration depends on users from external realms and these users
  59. need to have their roles mapped to them even when the cluster is RED. For instance
  60. an administrator that authenticates via LDAP or PKI and gets assigned an
  61. administrator role so that they can perform corrective actions.
  62. Please note however, that the role_mappings.yml file is provided
  63. as a minimal administrative function and is not intended to cover and be used to
  64. define roles for all use cases.
  65. IMPORTANT: You cannot view, edit, or remove any roles that are defined in the role
  66. mapping files by using the the role mapping APIs.
  67. ==== Realm specific details
  68. [float]
  69. [[ldap-role-mapping]]
  70. ===== Active Directory and LDAP realms
  71. To specify users and groups in the role mappings, you use their
  72. _Distinguished Names_ (DNs). A DN is a string that uniquely identifies the user
  73. or group, for example `"cn=John Doe,cn=contractors,dc=example,dc=com"`.
  74. NOTE: The {es} {security-features} support only Active Directory security groups.
  75. You cannot map distribution groups to roles.
  76. For example, the following snippet uses the file-based method to map the
  77. `admins` group to the `monitoring` role and map the `John Doe` user, the
  78. `users` group, and the `admins` group to the `user` role.
  79. [source, yaml]
  80. ------------------------------------------------------------
  81. monitoring: <1>
  82. - "cn=admins,dc=example,dc=com" <2>
  83. user:
  84. - "cn=John Doe,cn=contractors,dc=example,dc=com" <3>
  85. - "cn=users,dc=example,dc=com"
  86. - "cn=admins,dc=example,dc=com"
  87. ------------------------------------------------------------
  88. <1> The name of a role.
  89. <2> The distinguished name of an LDAP group or an Active Directory security group.
  90. <3> The distinguished name of an LDAP or Active Directory user.
  91. You can use the role-mapping API to define equivalent mappings as follows:
  92. [source,console]
  93. --------------------------------------------------
  94. PUT /_security/role_mapping/admins
  95. {
  96. "roles" : [ "monitoring", "user" ],
  97. "rules" : { "field" : { "groups" : "cn=admins,dc=example,dc=com" } },
  98. "enabled": true
  99. }
  100. --------------------------------------------------
  101. [source,console]
  102. --------------------------------------------------
  103. PUT /_security/role_mapping/basic_users
  104. {
  105. "roles" : [ "user" ],
  106. "rules" : { "any" : [
  107. { "field" : { "dn" : "cn=John Doe,cn=contractors,dc=example,dc=com" } },
  108. { "field" : { "groups" : "cn=users,dc=example,dc=com" } }
  109. ] },
  110. "enabled": true
  111. }
  112. --------------------------------------------------
  113. [float]
  114. [[pki-role-mapping]]
  115. ===== PKI realms
  116. PKI realms support mapping users to roles, but you cannot map groups as
  117. the PKI realm has no notion of a group.
  118. This is an example using a file-based mapping:
  119. [source, yaml]
  120. ------------------------------------------------------------
  121. monitoring:
  122. - "cn=Admin,ou=example,o=com"
  123. user:
  124. - "cn=John Doe,ou=example,o=com"
  125. ------------------------------------------------------------
  126. The following example creates equivalent mappings using the API:
  127. [source,console]
  128. --------------------------------------------------
  129. PUT /_security/role_mapping/admin_user
  130. {
  131. "roles" : [ "monitoring" ],
  132. "rules" : { "field" : { "dn" : "cn=Admin,ou=example,o=com" } },
  133. "enabled": true
  134. }
  135. --------------------------------------------------
  136. [source,console]
  137. --------------------------------------------------
  138. PUT /_security/role_mapping/basic_user
  139. {
  140. "roles" : [ "user" ],
  141. "rules" : { "field" : { "dn" : "cn=John Doe,ou=example,o=com" } },
  142. "enabled": true
  143. }
  144. --------------------------------------------------