managing-roles.asciidoc 13 KB

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