field-level-security.asciidoc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. [role="xpack"]
  2. [[field-level-security]]
  3. === Field level security
  4. Field level security restricts the fields that users have read access to.
  5. In particular, it restricts which fields can be accessed from document-based
  6. read APIs.
  7. To enable field level security, specify the fields that each role can access
  8. as part of the indices permissions in a role definition. Field level security is
  9. thus bound to a well-defined set of data streams or indices (and potentially a set of
  10. <<document-level-security, documents>>).
  11. The following role definition grants read access only to the `category`,
  12. `@timestamp`, and `message` fields in all the `events-*` data streams and indices.
  13. [source,console]
  14. --------------------------------------------------
  15. POST /_security/role/test_role1
  16. {
  17. "indices": [
  18. {
  19. "names": [ "events-*" ],
  20. "privileges": [ "read" ],
  21. "field_security" : {
  22. "grant" : [ "category", "@timestamp", "message" ]
  23. }
  24. }
  25. ]
  26. }
  27. --------------------------------------------------
  28. Access to the following metadata fields is always allowed: `_id`,
  29. `_type`, `_parent`, `_routing`, `_timestamp`, `_ttl`, `_size` and `_index`. If
  30. you specify an empty list of fields, only these metadata fields are accessible.
  31. NOTE: Omitting the fields entry entirely disables field level security.
  32. You can also specify field expressions. For example, the following
  33. example grants read access to all fields that start with an `event_` prefix:
  34. [source,console]
  35. --------------------------------------------------
  36. POST /_security/role/test_role2
  37. {
  38. "indices" : [
  39. {
  40. "names" : [ "*" ],
  41. "privileges" : [ "read" ],
  42. "field_security" : {
  43. "grant" : [ "event_*" ]
  44. }
  45. }
  46. ]
  47. }
  48. --------------------------------------------------
  49. Use the dot notations to refer to nested fields in more complex documents. For
  50. example, assuming the following document:
  51. [source,js]
  52. --------------------------------------------------
  53. {
  54. "customer": {
  55. "handle": "Jim",
  56. "email": "jim@mycompany.com",
  57. "phone": "555-555-5555"
  58. }
  59. }
  60. --------------------------------------------------
  61. // NOTCONSOLE
  62. The following role definition enables only read access to the customer `handle`
  63. field:
  64. [source,console]
  65. --------------------------------------------------
  66. POST /_security/role/test_role3
  67. {
  68. "indices" : [
  69. {
  70. "names" : [ "*" ],
  71. "privileges" : [ "read" ],
  72. "field_security" : {
  73. "grant" : [ "customer.handle" ]
  74. }
  75. }
  76. ]
  77. }
  78. --------------------------------------------------
  79. This is where wildcard support shines. For example, use `customer.*` to enable
  80. only read access to the `customer` data:
  81. [source,console]
  82. --------------------------------------------------
  83. POST /_security/role/test_role4
  84. {
  85. "indices" : [
  86. {
  87. "names" : [ "*" ],
  88. "privileges" : [ "read" ],
  89. "field_security" : {
  90. "grant" : [ "customer.*" ]
  91. }
  92. }
  93. ]
  94. }
  95. --------------------------------------------------
  96. You can deny permission to access fields with the following syntax:
  97. [source,console]
  98. --------------------------------------------------
  99. POST /_security/role/test_role5
  100. {
  101. "indices" : [
  102. {
  103. "names" : [ "*" ],
  104. "privileges" : [ "read" ],
  105. "field_security" : {
  106. "grant" : [ "*"],
  107. "except": [ "customer.handle" ]
  108. }
  109. }
  110. ]
  111. }
  112. --------------------------------------------------
  113. The following rules apply:
  114. * The absence of `field_security` in a role is equivalent to * access.
  115. * If permission has been granted explicitly to some fields, you can specify
  116. denied fields. The denied fields must be a subset of the fields to which
  117. permissions were granted.
  118. * Defining denied and granted fields implies access to all granted fields except
  119. those which match the pattern in the denied fields.
  120. For example:
  121. [source,console]
  122. --------------------------------------------------
  123. POST /_security/role/test_role6
  124. {
  125. "indices" : [
  126. {
  127. "names" : [ "*" ],
  128. "privileges" : [ "read" ],
  129. "field_security" : {
  130. "except": [ "customer.handle" ],
  131. "grant" : [ "customer.*" ]
  132. }
  133. }
  134. ]
  135. }
  136. --------------------------------------------------
  137. In the above example, users can read all fields with the prefix "customer."
  138. except for "customer.handle".
  139. An empty array for `grant` (for example, `"grant" : []`) means that access has
  140. not been granted to any fields.
  141. When a user has several roles that specify field level permissions, the
  142. resulting field level permissions per data stream or index are the union of the individual role
  143. permissions. For example, if these two roles are merged:
  144. [source,console]
  145. --------------------------------------------------
  146. POST /_security/role/test_role7
  147. {
  148. "indices" : [
  149. {
  150. "names" : [ "*" ],
  151. "privileges" : [ "read" ],
  152. "field_security" : {
  153. "grant": [ "a.*" ],
  154. "except" : [ "a.b*" ]
  155. }
  156. }
  157. ]
  158. }
  159. POST /_security/role/test_role8
  160. {
  161. "indices" : [
  162. {
  163. "names" : [ "*" ],
  164. "privileges" : [ "read" ],
  165. "field_security" : {
  166. "grant": [ "a.b*" ],
  167. "except" : [ "a.b.c*" ]
  168. }
  169. }
  170. ]
  171. }
  172. --------------------------------------------------
  173. The resulting permission is equal to:
  174. [source,js]
  175. --------------------------------------------------
  176. {
  177. // role 1 + role 2
  178. ...
  179. "indices" : [
  180. {
  181. "names" : [ "*" ],
  182. "privileges" : [ "read" ],
  183. "field_security" : {
  184. "grant": [ "a.*" ],
  185. "except" : [ "a.b.c*" ]
  186. }
  187. }
  188. ]
  189. }
  190. --------------------------------------------------
  191. // NOTCONSOLE
  192. NOTE: Field-level security should not be set on <<field-alias,`alias`>> fields.
  193. To secure a
  194. concrete field, its field name must be used directly.
  195. For more information, see <<field-and-document-access-control>>.