|
| 1 | +[role="xpack"] |
| 2 | +[[defining-roles]] |
| 3 | +=== Defining roles |
| 4 | + |
| 5 | +A role is defined by the following JSON structure: |
| 6 | + |
| 7 | +[source,js] |
| 8 | +----- |
| 9 | +{ |
| 10 | + "run_as": [ ... ], <1> |
| 11 | + "cluster": [ ... ], <2> |
| 12 | + "indices": [ ... ] <3> |
| 13 | +} |
| 14 | +----- |
| 15 | +<1> A list of usernames the owners of this role can <<run-as-privilege, impersonate>>. |
| 16 | +<2> A list of cluster privileges. These privileges define the |
| 17 | + cluster level actions users with this role are able to execute. This field |
| 18 | + is optional (missing `cluster` privileges effectively mean no cluster level |
| 19 | + permissions). |
| 20 | +<3> A list of indices permissions entries. This field is optional (missing `indices` |
| 21 | + privileges effectively mean no index level permissions). |
| 22 | + |
| 23 | +[[valid-role-name]] |
| 24 | +NOTE: Role names must be at least 1 and no more than 1024 characters. They can |
| 25 | + contain alphanumeric characters (`a-z`, `A-Z`, `0-9`), spaces, |
| 26 | + punctuation, and printable symbols in the https://en.wikipedia.org/wiki/Basic_Latin_(Unicode_block)[Basic Latin (ASCII) block]. |
| 27 | + Leading or trailing whitespace is not allowed. |
| 28 | + |
| 29 | +The following describes the structure of an indices permissions entry: |
| 30 | + |
| 31 | +[source,js] |
| 32 | +------- |
| 33 | +{ |
| 34 | + "names": [ ... ], <1> |
| 35 | + "privileges": [ ... ], <2> |
| 36 | + "field_security" : { ... }, <3> |
| 37 | + "query": "..." <4> |
| 38 | +} |
| 39 | +------- |
| 40 | +<1> A list of indices (or index name patterns) to which the permissions in this |
| 41 | + entry apply. |
| 42 | +<2> The index level privileges the owners of the role have on the associated |
| 43 | + indices (those indices that are specified in the `name` field) |
| 44 | +<3> Specification for document fields the owners of the role have read access to. |
| 45 | + See <<field-and-document-access-control>> for details. |
| 46 | +<4> A search query that defines the documents the owners of the role have read |
| 47 | + access to. A document within the associated indices must match this query |
| 48 | + in order for it to be accessible by the owners of the role. |
| 49 | + |
| 50 | +[TIP] |
| 51 | +============================================================================== |
| 52 | +When specifying index names, you can use indices and aliases with their full |
| 53 | +names or regular expressions that refer to multiple indices. |
| 54 | +
|
| 55 | +* Wildcard (default) - simple wildcard matching where `*` is a placeholder |
| 56 | + for zero or more characters, `?` is a placeholder for a single character |
| 57 | + and `\` may be used as an escape character. |
| 58 | +
|
| 59 | +* Regular Expressions - A more powerful syntax for matching more complex |
| 60 | + patterns. This regular expression is based on Lucene's regexp automaton |
| 61 | + syntax. To enable this syntax, it must be wrapped within a pair of |
| 62 | + forward slashes (`/`). Any pattern starting with `/` and not ending with |
| 63 | + `/` is considered to be malformed. |
| 64 | +
|
| 65 | +.Example Regular Expressions |
| 66 | +[source,yaml] |
| 67 | +------------------------------------------------------------------------------ |
| 68 | +"foo-bar": # match the literal `foo-bar` |
| 69 | +"foo-*": # match anything beginning with "foo-" |
| 70 | +"logstash-201?-*": # ? matches any one character |
| 71 | +"/.*-201[0-9]-.*/": # use a regex to match anything containing 2010-2019 |
| 72 | +"/foo": # syntax error - missing final / |
| 73 | +------------------------------------------------------------------------------ |
| 74 | +============================================================================== |
| 75 | + |
| 76 | +The following snippet shows an example definition of a `clicks_admin` role: |
| 77 | + |
| 78 | +[source,js] |
| 79 | +----------- |
| 80 | +{ |
| 81 | + "run_as": [ "clicks_watcher_1" ] |
| 82 | + "cluster": [ "monitor" ], |
| 83 | + "indices": [ |
| 84 | + { |
| 85 | + "names": [ "events-*" ], |
| 86 | + "privileges": [ "read" ], |
| 87 | + "field_security" : { |
| 88 | + "grant" : [ "category", "@timestamp", "message" ] |
| 89 | + }, |
| 90 | + "query": "{\"match\": {\"category\": \"click\"}}" |
| 91 | + } |
| 92 | + ] |
| 93 | +} |
| 94 | +----------- |
| 95 | + |
| 96 | +Based on the above definition, users owning the `clicks_admin` role can: |
| 97 | + |
| 98 | + * Impersonate the `clicks_watcher_1` user and execute requests on its behalf. |
| 99 | + * Monitor the {es} cluster |
| 100 | + * Read data from all indices prefixed with `events-` |
| 101 | + * Within these indices, only read the events of the `click` category |
| 102 | + * Within these document, only read the `category`, `@timestamp` and `message` |
| 103 | + fields. |
| 104 | + |
| 105 | +TIP: For a complete list of available <<security-privileges, cluster and indices privileges>> |
| 106 | + |
| 107 | +There are two available mechanisms to define roles: using the _Role Management APIs_ |
| 108 | +or in local files on the {es} nodes. {security} also supports implementing |
| 109 | +custom roles providers. If you need to integrate with another system to retrieve |
| 110 | +user roles, you can build a custom roles provider plugin. For more information, |
| 111 | +see <<custom-roles-provider, Custom Roles Provider Extension>>. |
| 112 | + |
| 113 | +[float] |
| 114 | +[[roles-management-ui]] |
| 115 | +=== Role management UI |
| 116 | + |
| 117 | +{security} enables you to easily manage users and roles from within {kib}. To |
| 118 | +manage roles, log in to {kib} and go to *Management / Elasticsearch / Roles*. |
| 119 | + |
| 120 | +[float] |
| 121 | +[[roles-management-api]] |
| 122 | +=== Role management API |
| 123 | + |
| 124 | +The _Role Management APIs_ enable you to add, update, remove and retrieve roles |
| 125 | +dynamically. When you use the APIs to manage roles in the `native` realm, the |
| 126 | +roles are stored in an internal {es} index. For more information and examples, |
| 127 | +see {ref}/security-api-roles.html[Role Management APIs]. |
| 128 | + |
| 129 | +[float] |
| 130 | +[[roles-management-file]] |
| 131 | +=== File-based role management |
| 132 | + |
| 133 | +Apart from the _Role Management APIs_, roles can also be defined in local |
| 134 | +`roles.yml` file located in `CONFIG_DIR`. This is a YAML file where each |
| 135 | +role definition is keyed by its name. |
| 136 | + |
| 137 | +[IMPORTANT] |
| 138 | +============================== |
| 139 | +If the same role name is used in the `roles.yml` file and through the |
| 140 | +_Role Management APIs_, the role found in the file will be used. |
| 141 | +============================== |
| 142 | + |
| 143 | +While the _Role Management APIs_ is the preferred mechanism to define roles, |
| 144 | +using the `roles.yml` file becomes useful if you want to define fixed roles that |
| 145 | +no one (beside an administrator having physical access to the {es} nodes) |
| 146 | +would be able to change. |
| 147 | + |
| 148 | +[IMPORTANT] |
| 149 | +============================== |
| 150 | +The `roles.yml` file is managed locally by the node and is not globally by the |
| 151 | +cluster. This means that with a typical multi-node cluster, the exact same |
| 152 | +changes need to be applied on each and every node in the cluster. |
| 153 | +
|
| 154 | +A safer approach would be to apply the change on one of the nodes and have the |
| 155 | +`roles.yml` distributed/copied to all other nodes in the cluster (either |
| 156 | +manually or using a configuration management system such as Puppet or Chef). |
| 157 | +============================== |
| 158 | + |
| 159 | +The following snippet shows an example of the `roles.yml` file configuration: |
| 160 | + |
| 161 | +[source,yaml] |
| 162 | +----------------------------------- |
| 163 | +click_admins: |
| 164 | + run_as: [ 'clicks_watcher_1' ] |
| 165 | + cluster: [ 'monitor' ] |
| 166 | + indices: |
| 167 | + - names: [ 'events-*' ] |
| 168 | + privileges: [ 'read' ] |
| 169 | + field_security: |
| 170 | + grant: ['category', '@timestamp', 'message' ] |
| 171 | + query: '{"match": {"category": "click"}}' |
| 172 | +----------------------------------- |
| 173 | + |
| 174 | +{security} continuously monitors the `roles.yml` file and automatically picks |
| 175 | +up and applies any changes to it. |
0 commit comments