document-level-security.asciidoc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. [role="xpack"]
  2. [[document-level-security]]
  3. === Document level security
  4. Document level security restricts the documents that users have read access to.
  5. In particular, it restricts which documents can be accessed from document-based
  6. read APIs.
  7. To enable document level security, you use a query to specify the documents that
  8. each role can access. The document `query` is associated with a particular data
  9. stream, index, or wildcard (`*`) pattern and operates in conjunction with the
  10. privileges specified for the data streams and indices.
  11. The specified document `query`:
  12. * Expects the same format as if it was defined in the search request
  13. * Supports <<templating-role-query,templating a role query>> that can access
  14. the details of the currently authenticated user
  15. * Accepts queries written as either string values or nested JSON
  16. * Supports the majority of the {es}
  17. <<query-dsl,Query Domain Specific Language (DSL)>>, with <<field-document-limitations,some limitations>> for field and document level security
  18. IMPORTANT: Omitting the `query` parameter entirely disables document level
  19. security for the respective indices permission entry.
  20. The following role definition grants read access only to documents that
  21. belong to the `click` category within all the `events-*` data streams and indices:
  22. [source,console]
  23. ----
  24. POST /_security/role/click_role
  25. {
  26. "indices": [
  27. {
  28. "names": [ "events-*" ],
  29. "privileges": [ "read" ],
  30. "query": "{\"match\": {\"category\": \"click\"}}"
  31. }
  32. ]
  33. }
  34. ----
  35. You can write this same query using nested JSON syntax:
  36. [source,console]
  37. ----
  38. POST _security/role/click_role
  39. {
  40. "indices": [
  41. {
  42. "names": [ "events-*" ],
  43. "privileges": [ "read" ],
  44. "query": {
  45. "match": {
  46. "category": "click"
  47. }
  48. }
  49. }
  50. ]
  51. }
  52. ----
  53. The following role grants read access only to the documents whose
  54. `department_id` equals `12`:
  55. [source,console]
  56. ----
  57. POST /_security/role/dept_role
  58. {
  59. "indices" : [
  60. {
  61. "names" : [ "*" ],
  62. "privileges" : [ "read" ],
  63. "query" : {
  64. "term" : { "department_id" : 12 }
  65. }
  66. }
  67. ]
  68. }
  69. ----