alias-privileges.asciidoc 4.9 KB

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