alias-privileges.asciidoc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. [role="xpack"]
  2. [[securing-aliases]]
  3. === Granting privileges for data streams and index aliases
  4. {es} {security-features} allow you to secure operations executed against
  5. <<data-streams,data streams>> and <<indices-aliases,index aliases>>.
  6. [[data-stream-privileges]]
  7. ==== Data stream privileges
  8. A data stream consists of one or more backing indices, which store the stream's
  9. data. Most requests sent to a data stream are routed to one or more of these
  10. backing indices.
  11. Similar to an index, you can use <<privileges-list-indices,indices privileges>>
  12. to control access to a data stream. Any role or user granted privileges to a
  13. data stream are automatically granted the same privileges to its backing
  14. indices.
  15. .*Example*
  16. [%collapsible]
  17. ====
  18. `logs` is a data stream that consists of two backing indices: `.ds-logs-000001`
  19. and `.ds-logs-000002`.
  20. A user is granted the `read` privilege to the `logs` data stream.
  21. [source,js]
  22. --------------------------------------------------
  23. {
  24. "names" : [ "logs" ],
  25. "privileges" : [ "read" ]
  26. }
  27. --------------------------------------------------
  28. // NOTCONSOLE
  29. Because the user is automatically granted the same privileges to the stream's
  30. backing indices, the user can retrieve a document directly from `.ds-logs-000002`:
  31. ////
  32. [source,console]
  33. ----
  34. PUT /_index_template/logs_data_stream
  35. {
  36. "index_patterns": [ "logs*" ],
  37. "data_stream": { }
  38. }
  39. PUT /_data_stream/logs
  40. POST /logs/_rollover/
  41. PUT /logs/_create/2?refresh=wait_for
  42. {
  43. "@timestamp": "2020-12-07T11:06:07.000Z"
  44. }
  45. ----
  46. ////
  47. [source,console]
  48. ----
  49. GET /.ds-logs-000002/_doc/2
  50. ----
  51. // TEST[continued]
  52. Later the `logs` data stream <<manually-roll-over-a-data-stream,rolls over>>.
  53. This creates a new backing index: `.ds-logs-000003`. Because the user still has
  54. the `read` privilege for the `logs` data stream, the user can retrieve documents
  55. directly from `.ds-logs-000003`:
  56. ////
  57. [source,console]
  58. ----
  59. POST /logs/_rollover/
  60. PUT /logs/_create/2?refresh=wait_for
  61. {
  62. "@timestamp": "2020-12-07T11:06:07.000Z"
  63. }
  64. ----
  65. // TEST[continued]
  66. ////
  67. [source,console]
  68. ----
  69. GET /.ds-logs-000003/_doc/2
  70. ----
  71. // TEST[continued]
  72. ////
  73. [source,console]
  74. ----
  75. DELETE /_data_stream/*
  76. DELETE /_index_template/*
  77. ----
  78. // TEST[continued]
  79. ////
  80. ====
  81. [[index-alias-privileges]]
  82. ==== Index alias privileges
  83. An index alias points to one or more indices,
  84. holds metadata and potentially a filter. The {es} {security-features} treat
  85. aliases and indices
  86. the same. Privileges for indices actions are granted on specific indices or
  87. aliases. In order for an indices action to be authorized, the user that executes
  88. it needs to have permissions for that action on all the specific indices or
  89. aliases that the request relates to.
  90. Let's look at an example. Assuming we have an index called `2015`, an alias that
  91. points to it called `current_year`, and a user with the following role:
  92. [source,js]
  93. --------------------------------------------------
  94. {
  95. "names" : [ "2015" ],
  96. "privileges" : [ "read" ]
  97. }
  98. --------------------------------------------------
  99. // NOTCONSOLE
  100. The user attempts to retrieve a document from `current_year`:
  101. [source,console]
  102. -------------------------------------------------------------------------------
  103. GET /current_year/_doc/1
  104. -------------------------------------------------------------------------------
  105. // TEST[s/^/PUT 2015\n{"aliases": {"current_year": {}}}\nPUT 2015\/_doc\/1\n{}\n/]
  106. The above request gets rejected, although the user has `read` privilege on the
  107. concrete index that the `current_year` alias points to. The correct permission
  108. would be as follows:
  109. [source,js]
  110. --------------------------------------------------
  111. {
  112. "names" : [ "current_year" ],
  113. "privileges" : [ "read" ]
  114. }
  115. --------------------------------------------------
  116. // NOTCONSOLE
  117. [float]
  118. ==== Managing aliases
  119. Unlike creating indices, which requires the `create_index` privilege, adding,
  120. removing and retrieving aliases requires the `manage` permission. Aliases can be
  121. added to an index directly as part of the index creation:
  122. [source,console]
  123. -------------------------------------------------------------------------------
  124. PUT /2015
  125. {
  126. "aliases" : {
  127. "current_year" : {}
  128. }
  129. }
  130. -------------------------------------------------------------------------------
  131. or via the dedicated aliases api if the index already exists:
  132. [source,console]
  133. -------------------------------------------------------------------------------
  134. POST /_aliases
  135. {
  136. "actions" : [
  137. { "add" : { "index" : "2015", "alias" : "current_year" } }
  138. ]
  139. }
  140. -------------------------------------------------------------------------------
  141. // TEST[s/^/PUT 2015\n/]
  142. The above requests both require the `manage` privilege on the alias name as well
  143. as the targeted index, as follows:
  144. [source,js]
  145. --------------------------------------------------
  146. {
  147. "names" : [ "20*", "current_year" ],
  148. "privileges" : [ "manage" ]
  149. }
  150. --------------------------------------------------
  151. // NOTCONSOLE
  152. The index aliases api also allows also to delete aliases from existing indices.
  153. The privileges required for such a request are the same as above. Both index and
  154. alias need the `manage` permission.
  155. [float]
  156. ==== Filtered aliases
  157. Aliases can hold a filter, which allows to select a subset of documents that can
  158. be accessed out of all the documents that the physical index contains. These
  159. filters are not always applied and should not be used in place of
  160. <<document-level-security,document level security>>.