managing-roles.asciidoc 15 KB

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