has-privileges.asciidoc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. [role="xpack"]
  2. [[security-api-has-privileges]]
  3. === Has privileges API
  4. ++++
  5. <titleabbrev>Has privileges</titleabbrev>
  6. ++++
  7. [[security-api-has-privilege]]
  8. .New API reference
  9. [sidebar]
  10. --
  11. For the most up-to-date API details, refer to {api-es}/group/endpoint-security[Security APIs].
  12. --
  13. Determines whether the logged in user has a specified list of privileges.
  14. [[security-api-has-privileges-request]]
  15. ==== {api-request-title}
  16. `GET /_security/user/_has_privileges`
  17. `POST /_security/user/_has_privileges`
  18. [[security-api-has-privileges-prereqs]]
  19. ==== {api-prereq-title}
  20. * All users can use this API, but only to determine their own privileges.
  21. To check the privileges of other users, you must use the run as feature. For
  22. more information, see
  23. <<run-as-privilege>>.
  24. [[security-api-has-privileges-desc]]
  25. ==== {api-description-title}
  26. For a list of the privileges that you can specify in this API,
  27. see <<security-privileges>>.
  28. A successful call returns a JSON structure that shows whether each specified
  29. privilege is assigned to the user.
  30. [[security-api-has-privileges-request-body]]
  31. ==== {api-request-body-title}
  32. `cluster`:: (list) A list of the cluster privileges that you want to check.
  33. `index`::
  34. `names`::: (list) A list of indices.
  35. `allow_restricted_indices`::: (Boolean) This needs to be set to `true` (default
  36. is `false`) if using wildcards or regexps for patterns that cover restricted
  37. indices. Implicitly, restricted indices do not match index patterns because
  38. restricted indices usually have limited privileges and including them in
  39. pattern tests would render most such tests `false`. If restricted indices are
  40. explicitly included in the `names` list, privileges will be checked against
  41. them regardless of the value of `allow_restricted_indices`.
  42. `privileges`::: (list) A list of the privileges that you want to check for the
  43. specified indices.
  44. `application`::
  45. `application`::: (string) The name of the application.
  46. `privileges`::: (list) A list of the privileges that you want to check for the
  47. specified resources. May be either application privilege names, or the names of
  48. actions that are granted by those privileges
  49. `resources`::: (list) A list of resource names against which the privileges
  50. should be checked
  51. [[security-api-has-privileges-example]]
  52. ==== {api-examples-title}
  53. The following example checks whether the current user has a specific set of
  54. cluster, index, and application privileges:
  55. [source,console]
  56. --------------------------------------------------
  57. GET /_security/user/_has_privileges
  58. {
  59. "cluster": [ "monitor", "manage" ],
  60. "index" : [
  61. {
  62. "names": [ "suppliers", "products" ],
  63. "privileges": [ "read" ]
  64. },
  65. {
  66. "names": [ "inventory" ],
  67. "privileges" : [ "read", "write" ]
  68. }
  69. ],
  70. "application": [
  71. {
  72. "application": "inventory_manager",
  73. "privileges" : [ "read", "data:write/inventory" ],
  74. "resources" : [ "product/1852563" ]
  75. }
  76. ]
  77. }
  78. --------------------------------------------------
  79. The following example output indicates which privileges the "rdeniro" user has:
  80. [source,console-result]
  81. --------------------------------------------------
  82. {
  83. "username": "rdeniro",
  84. "has_all_requested" : false,
  85. "cluster" : {
  86. "monitor" : true,
  87. "manage" : false
  88. },
  89. "index" : {
  90. "suppliers" : {
  91. "read" : true
  92. },
  93. "products" : {
  94. "read" : true
  95. },
  96. "inventory" : {
  97. "read" : true,
  98. "write" : false
  99. }
  100. },
  101. "application" : {
  102. "inventory_manager" : {
  103. "product/1852563" : {
  104. "read": false,
  105. "data:write/inventory": false
  106. }
  107. }
  108. }
  109. }
  110. --------------------------------------------------
  111. // TESTRESPONSE[s/"rdeniro"/"$body.username"/]
  112. // TESTRESPONSE[s/: false/: true/]