managing-roles.asciidoc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. [role="xpack"]
  2. [[defining-roles]]
  3. === Defining roles
  4. A role is defined by the following JSON structure:
  5. [source,js]
  6. -----
  7. {
  8. "run_as": [ ... ], <1>
  9. "cluster": [ ... ], <2>
  10. "global": { ... }, <3>
  11. "indices": [ ... ], <4>
  12. "applications": [ ... ], <5>
  13. "remote_indices": [ ... ], <6>
  14. "remote_cluster": [ ... ] <7>
  15. }
  16. -----
  17. // NOTCONSOLE
  18. <1> A list of usernames the owners of this role can <<run-as-privilege, impersonate>>.
  19. <2> A list of cluster privileges. These privileges define the
  20. cluster level actions users with this role are able to execute. This field
  21. is optional (missing `cluster` privileges effectively mean no cluster level
  22. permissions).
  23. <3> An object defining global privileges. A global privilege is a form of
  24. cluster privilege that is request sensitive. A standard cluster privilege
  25. makes authorization decisions based solely on the action being executed.
  26. A global privilege also considers the parameters included in the request.
  27. Support for global privileges is currently limited to the management of
  28. application privileges. This field is optional.
  29. <4> A list of indices permissions entries. This field is optional (missing `indices`
  30. privileges effectively mean no index level permissions).
  31. <5> A list of application privilege entries. This field is optional.
  32. <6> A list of indices permissions entries for
  33. <<remote-clusters-api-key,remote clusters configured with the API key based model>>.
  34. This field is optional (missing `remote_indices` privileges effectively mean
  35. no index level permissions for any API key based remote clusters).
  36. <7> A list of cluster permissions entries for
  37. <<remote-clusters-api-key,remote clusters configured with the API key based model>>.
  38. This field is optional (missing `remote_cluster` privileges effectively means
  39. no additional cluster permissions for any API key based remote clusters).
  40. [[valid-role-name]]
  41. NOTE: Role names must be at least 1 and no more than 507 characters. They can
  42. contain alphanumeric characters (`a-z`, `A-Z`, `0-9`), spaces,
  43. punctuation, and printable symbols in the {wikipedia}/Basic_Latin_(Unicode_block)[Basic Latin (ASCII) block].
  44. Leading or trailing whitespace is not allowed.
  45. [[roles-indices-priv]]
  46. ==== Indices privileges
  47. The following describes the structure of an indices permissions entry:
  48. [source,js]
  49. -------
  50. {
  51. "names": [ ... ], <1>
  52. "privileges": [ ... ], <2>
  53. "field_security" : { ... }, <3>
  54. "query": "...", <4>
  55. "allow_restricted_indices": false <5>
  56. }
  57. -------
  58. // NOTCONSOLE
  59. <1> A list of data streams, indices, and aliases to which the permissions
  60. in this entry apply. Supports wildcards (`*`).
  61. <2> The index level privileges the owners of the role have on the associated
  62. data streams and indices specified in the `names` argument.
  63. <3> Specification for document fields the owners of the role have read access to.
  64. See <<field-and-document-access-control>> for details.
  65. <4> A search query that defines the documents the owners of the role have read
  66. access to. A document within the associated data streams and indices must match this query
  67. in order for it to be accessible by the owners of the role.
  68. <5> Restricted indices are a special category of indices that are used
  69. internally to store configuration data and should not be directly accessed.
  70. Only internal system roles should normally grant privileges over the restricted indices.
  71. **Toggling this flag is very strongly discouraged because it could effectively grant unrestricted
  72. operations on critical data, making the entire system unstable or leaking sensitive information.**
  73. If however, for administrative purposes, you need to create a role with privileges covering
  74. restricted indices, you must set this field to `true` (default is `false`), and then the
  75. `names` field will cover the restricted indices as well.
  76. [TIP]
  77. ==============================================================================
  78. The `names` parameter accepts wildcard and regular expressions that may refer to
  79. multiple data streams, indices, and aliases.
  80. * Wildcard (default) - simple wildcard matching where `*` is a placeholder
  81. for zero or more characters, `?` is a placeholder for a single character
  82. and `\` may be used as an escape character.
  83. * Regular Expressions - A more powerful syntax for matching more complex
  84. patterns. This regular expression is based on Lucene's regexp automaton
  85. syntax. To enable this syntax, it must be wrapped within a pair of
  86. forward slashes (`/`). Any pattern starting with `/` and not ending with
  87. `/` is considered to be malformed.
  88. .Example Regular Expressions
  89. [source,yaml]
  90. ------------------------------------------------------------------------------
  91. "foo-bar": # match the literal `foo-bar`
  92. "foo-*": # match anything beginning with "foo-"
  93. "logstash-201?-*": # ? matches any one character
  94. "/.*-201[0-9]-.*/": # use a regex to match anything containing 2010-2019
  95. "/foo": # syntax error - missing final /
  96. ------------------------------------------------------------------------------
  97. ==============================================================================
  98. [[roles-global-priv]]
  99. ==== Global privileges
  100. The following describes the structure of the global privileges entry:
  101. [source,js]
  102. -------
  103. {
  104. "application": {
  105. "manage": { <1>
  106. "applications": [ ... ] <2>
  107. }
  108. },
  109. "profile": {
  110. "write": { <3>
  111. "applications": [ ... ] <4>
  112. }
  113. }
  114. }
  115. -------
  116. // NOTCONSOLE
  117. <1> The privilege for the ability to manage application privileges
  118. <2> The list of application names that may be managed. This list supports
  119. wildcards (e.g. `"myapp-*"`) and regular expressions (e.g.
  120. `"/app[0-9]*/"`)
  121. <3> The privilege for the ability to write the `access` and `data` of any user profile
  122. <4> The list of names, wildcards and regular expressions to which the write
  123. privilege is restricted to
  124. [[roles-application-priv]]
  125. ==== Application privileges
  126. The following describes the structure of an application privileges entry:
  127. [source,js]
  128. -------
  129. {
  130. "application": "my_app", <1>
  131. "privileges": [ ... ], <2>
  132. "resources": [ ... ] <3>
  133. }
  134. -------
  135. // NOTCONSOLE
  136. <1> The name of the application.
  137. <2> The list of the names of the application privileges to grant to this role.
  138. <3> The resources to which those privileges apply. These are handled in the same
  139. way as index name pattern in `indices` permissions. These resources do not
  140. have any special meaning to the {es} {security-features}.
  141. For details about the validation rules for these fields, see the
  142. <<security-api-put-privileges,add application privileges API>>.
  143. A role may refer to application privileges that do not exist - that is, they
  144. have not yet been defined through the add application privileges API (or they
  145. were defined, but have since been deleted). In this case, the privilege has
  146. no effect, and will not grant any actions in the
  147. <<security-api-has-privileges,has privileges API>>.
  148. [[roles-remote-indices-priv]]
  149. ==== Remote indices privileges
  150. For <<remote-clusters-api-key,remote clusters configured with the API key based model>>, remote indices privileges
  151. can be used to specify desired indices privileges for matching remote clusters. The final
  152. effective index privileges will be an intersection of the remote indices privileges
  153. and the <<security-api-create-cross-cluster-api-key,cross-cluster API key>>'s indices privileges.
  154. NOTE: Remote indices are effective for remote clusters configured with the API key based model.
  155. They have no effect for remote clusters configured with the certificate based model.
  156. The remote indices privileges entry has an extra mandatory `clusters` field compared to
  157. an <<roles-indices-priv,indices privileges entry>>. Otherwise the two have identical structure.
  158. The following describes the structure of a remote indices permissions entry:
  159. [source,js]
  160. -------
  161. {
  162. "clusters": [ ... ], <1>
  163. "names": [ ... ], <2>
  164. "privileges": [ ... ], <3>
  165. "field_security" : { ... }, <4>
  166. "query": "...", <5>
  167. "allow_restricted_indices": false <6>
  168. }
  169. -------
  170. // NOTCONSOLE
  171. <1> A list of remote cluster aliases. It supports literal strings as well as
  172. <<api-multi-index,wildcards>> and <<regexp-syntax,regular expressions>>.
  173. This field is required.
  174. <2> A list of data streams, indices, and aliases to which the permissions
  175. in this entry apply. Supports wildcards (`*`).
  176. <3> The index level privileges the owners of the role have on the associated
  177. data streams and indices specified in the `names` argument.
  178. <4> Specification for document fields the owners of the role have read access to.
  179. See <<field-and-document-access-control>> for details.
  180. <5> A search query that defines the documents the owners of the role have read
  181. access to. A document within the associated data streams and indices must match this query
  182. in order for it to be accessible by the owners of the role.
  183. <6> Restricted indices are a special category of indices that are used
  184. internally to store configuration data and should not be directly accessed.
  185. Only internal system roles should normally grant privileges over the restricted indices.
  186. **Toggling this flag is very strongly discouraged because it could effectively grant unrestricted
  187. operations on critical data, making the entire system unstable or leaking sensitive information.**
  188. If however, for administrative purposes, you need to create a role with privileges covering
  189. restricted indices, you must set this field to `true` (default is `false`), and then the
  190. `names` field will cover the restricted indices as well.
  191. [[roles-remote-cluster-priv]]
  192. ==== Remote cluster privileges
  193. For <<remote-clusters-api-key,remote clusters configured with the API key based model>>, remote cluster privileges
  194. can be used to specify additional cluster privileges for matching remote clusters.
  195. NOTE: Remote cluster privileges are only effective for remote clusters configured with the API key based model.
  196. They have no effect on remote clusters configured with the certificate based model.
  197. The following describes the structure of a remote cluster permissions entry:
  198. [source,js]
  199. -------
  200. {
  201. "clusters": [ ... ], <1>
  202. "privileges": [ ... ] <2>
  203. }
  204. -------
  205. // NOTCONSOLE
  206. <1> A list of remote cluster aliases. It supports literal strings as well as
  207. <<api-multi-index,wildcards>> and <<regexp-syntax,regular expressions>>.
  208. This field is required.
  209. <2> The cluster level privileges for the remote cluster. The allowed values here are a subset of the
  210. <<privileges-list-cluster,cluster privileges>>. This field is required.
  211. The `monitor_enrich` privilege for remote clusters was introduced in version
  212. 8.15.0. Currently, this is the only privilege available for remote clusters and
  213. is required to enable users to use the `ENRICH` keyword in ES|QL queries across
  214. clusters.
  215. ==== Example
  216. The following snippet shows an example definition of a `clicks_admin` role:
  217. [source,console]
  218. -----------
  219. POST /_security/role/clicks_admin
  220. {
  221. "run_as": [ "clicks_watcher_1" ],
  222. "cluster": [ "monitor" ],
  223. "indices": [
  224. {
  225. "names": [ "events-*" ],
  226. "privileges": [ "read" ],
  227. "field_security" : {
  228. "grant" : [ "category", "@timestamp", "message" ]
  229. },
  230. "query": "{\"match\": {\"category\": \"click\"}}"
  231. }
  232. ]
  233. }
  234. -----------
  235. Based on the above definition, users owning the `clicks_admin` role can:
  236. * Impersonate the `clicks_watcher_1` user and execute requests on its behalf.
  237. * Monitor the {es} cluster
  238. * Read data from all indices prefixed with `events-`
  239. * Within these indices, only read the events of the `click` category
  240. * Within these document, only read the `category`, `@timestamp` and `message`
  241. fields.
  242. TIP: For a complete list of available <<security-privileges, cluster and indices privileges>>
  243. There are two available mechanisms to define roles: using the _Role Management APIs_
  244. or in local files on the {es} nodes. You can also implement
  245. custom roles providers. If you need to integrate with another system to retrieve
  246. user roles, you can build a custom roles provider plugin. For more information,
  247. see <<custom-roles-authorization>>.
  248. [discrete]
  249. [[roles-management-ui]]
  250. === Role management UI
  251. You can manage users and roles easily in {kib}. To
  252. manage roles, log in to {kib} and go to *Management / Security / Roles*.
  253. [discrete]
  254. [[roles-management-api]]
  255. === Role management API
  256. The _Role Management APIs_ enable you to add, update, remove and retrieve roles
  257. dynamically. When you use the APIs to manage roles in the `native` realm, the
  258. roles are stored in an internal {es} index. For more information and examples,
  259. see <<security-role-apis>>.
  260. [discrete]
  261. [[roles-management-file]]
  262. === File-based role management
  263. Apart from the _Role Management APIs_, roles can also be defined in local
  264. `roles.yml` file located in `ES_PATH_CONF`. This is a YAML file where each
  265. role definition is keyed by its name.
  266. [IMPORTANT]
  267. ==============================
  268. If the same role name is used in the `roles.yml` file and through the
  269. _Role Management APIs_, the role found in the file will be used.
  270. ==============================
  271. While the _Role Management APIs_ is the preferred mechanism to define roles,
  272. using the `roles.yml` file becomes useful if you want to define fixed roles that
  273. no one (beside an administrator having physical access to the {es} nodes)
  274. would be able to change. Please note however, that the `roles.yml` file is provided as a
  275. minimal administrative function and is not intended to cover and be used
  276. to define roles for all use cases.
  277. [IMPORTANT]
  278. ==============================
  279. You cannot view, edit, or remove any roles that are defined in `roles.yml` by
  280. using the <<roles-management-ui,role management UI>> or the
  281. <<roles-management-api,role management APIs>>.
  282. ==============================
  283. [IMPORTANT]
  284. ==============================
  285. The `roles.yml` file is managed locally by the node and is not globally by the
  286. cluster. This means that with a typical multi-node cluster, the exact same
  287. changes need to be applied on each and every node in the cluster.
  288. A safer approach would be to apply the change on one of the nodes and have the
  289. `roles.yml` distributed/copied to all other nodes in the cluster (either
  290. manually or using a configuration management system such as Puppet or Chef).
  291. ==============================
  292. The following snippet shows an example of the `roles.yml` file configuration:
  293. [source,yaml]
  294. -----------------------------------
  295. click_admins:
  296. run_as: [ 'clicks_watcher_1' ]
  297. cluster: [ 'monitor' ]
  298. indices:
  299. - names: [ 'events-*' ]
  300. privileges: [ 'read' ]
  301. field_security:
  302. grant: ['category', '@timestamp', 'message' ]
  303. query: '{"match": {"category": "click"}}'
  304. -----------------------------------
  305. {es} continuously monitors the `roles.yml` file and automatically picks
  306. up and applies any changes to it.