alias-privileges.asciidoc 5.3 KB

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