mapping-roles.asciidoc 7.6 KB

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