has-privileges-user-profile.asciidoc 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. [role="xpack"]
  2. [[security-api-has-privileges-user-profile]]
  3. === Has privileges user profile API
  4. ++++
  5. <titleabbrev>Has privileges user profile</titleabbrev>
  6. ++++
  7. NOTE: The user profile feature is designed only for use by {kib} and
  8. Elastic’s {observability}, {ents}, and {elastic-sec} solutions. Individual
  9. users and external applications should not call this API directly. Elastic reserves
  10. the right to change or remove this feature in future releases without prior notice.
  11. Determines whether the users associated with the specified <<user-profile, user profile>> IDs
  12. have all the requested privileges.
  13. [[security-api-has-privileges-user-profile-request]]
  14. ==== {api-request-title}
  15. `GET /_security/profile/_has_privileges`
  16. `POST /_security/profile/_has_privileges`
  17. [[security-api-has-privileges-user-profile-prereqs]]
  18. ==== {api-prereq-title}
  19. To use this API, you must have _at least_ the `read_security`
  20. <<privileges-list-cluster,cluster privilege>> (or a greater privilege
  21. such as `manage_user_profile` or `manage_security`).
  22. [[security-api-has-privileges-user-profile-desc]]
  23. ==== {api-description-title}
  24. This API uses the profile IDs, as returned by <<security-api-activate-user-profile>>,
  25. to identify the users for which to check the privileges of.
  26. It is similar to the <<security-api-has-privileges>> API, but unlike it, this API
  27. checks the privileges of other users, not of the user that's calling it.
  28. See <<security-privileges>> for the list of privileges that can be specified in this API.
  29. A successful call returns the subset list of profile IDs that have **all** the requested privileges.
  30. [[security-api-has-privileges-user-profile-request-body]]
  31. ==== {api-request-body-title}
  32. `uids`:: (list) A list of <<security-api-activate-user-profile-response-body, profile IDs>>. The privileges are checked for associated users of the profiles.
  33. `privileges`:: The object containing all the privileges to be checked.
  34. `cluster`::: (list) A list of the cluster privileges that you want to check.
  35. `index`:::
  36. `names`:::: (list) A list of indices.
  37. `allow_restricted_indices`:::: (Boolean) This needs to be set to `true` (default
  38. is `false`) if using wildcards or regexps for patterns that cover restricted
  39. indices. Implicitly, restricted indices do not match index patterns because
  40. restricted indices usually have limited privileges and including them in
  41. pattern tests would render most such tests `false`. If restricted indices are
  42. explicitly included in the `names` list, privileges will be checked against
  43. them regardless of the value of `allow_restricted_indices`.
  44. `privileges`:::: (list) A list of the privileges that you want to check for the
  45. specified indices.
  46. `application`:::
  47. `application`:::: (string) The name of the application.
  48. `privileges`:::: (list) A list of the privileges that you want to check for the
  49. specified resources. May be either application privilege names, or the names of
  50. actions that are granted by those privileges.
  51. `resources`:::: (list) A list of resource names against which the privileges
  52. should be checked.
  53. Note that the `privileges` section above is identical to the
  54. <<security-api-has-privileges-request-body, request body of the other Has Privileges API>>.
  55. [[security-api-has-privileges-user-profile-response-body]]
  56. ==== {api-response-body-title}
  57. A successful has privileges user profile API call returns a JSON structure that contains
  58. two fields:
  59. `has_privilege_uids`:: (list) The subset of the requested profile IDs of the users that have
  60. **all** the requested privileges.
  61. `errors`:: (object) Errors encountered while fulfilling the request. This field is absent if there is no error.
  62. It does **not** include the profile IDs of the users that do not have all the requested privileges.
  63. +
  64. .Properties of objects in `errors`
  65. [%collapsible%open]
  66. ====
  67. `count`:: (number) Total number of errors
  68. `details`:: (object) The detailed error report with keys being profile IDs and values being the exact errors.
  69. ====
  70. [[security-api-has-privileges-user-profile-example]]
  71. ==== {api-examples-title}
  72. The following example checks whether the two users associated with the specified profiles have all the
  73. requested set of cluster, index, and application privileges:
  74. [source,console]
  75. --------------------------------------------------
  76. POST /_security/profile/_has_privileges
  77. {
  78. "uids": [
  79. "u_LQPnxDxEjIH0GOUoFkZr5Y57YUwSkL9Joiq-g4OCbPc_0",
  80. "u_rzRnxDgEHIH0GOUoFkZr5Y27YUwSk19Joiq=g4OCxxB_1",
  81. "u_does-not-exist_0"
  82. ],
  83. "privileges": {
  84. "cluster": [ "monitor", "create_snapshot", "manage_ml" ],
  85. "index" : [
  86. {
  87. "names": [ "suppliers", "products" ],
  88. "privileges": [ "create_doc"]
  89. },
  90. {
  91. "names": [ "inventory" ],
  92. "privileges" : [ "read", "write" ]
  93. }
  94. ],
  95. "application": [
  96. {
  97. "application": "inventory_manager",
  98. "privileges" : [ "read", "data:write/inventory" ],
  99. "resources" : [ "product/1852563" ]
  100. }
  101. ]
  102. }
  103. }
  104. --------------------------------------------------
  105. // TEST[skip:TODO setup and tests will be possible once the profile uid is predictable]
  106. The following example output indicates that only one of the three users has all the privileges
  107. and one of them is not found:
  108. [source,js]
  109. --------------------------------------------------
  110. {
  111. "has_privilege_uids": ["u_rzRnxDgEHIH0GOUoFkZr5Y27YUwSk19Joiq=g4OCxxB_1"],
  112. "errors": {
  113. "count": 1,
  114. "details": {
  115. "u_does-not-exist_0": {
  116. "type": "resource_not_found_exception",
  117. "reason": "profile document not found"
  118. }
  119. }
  120. }
  121. }
  122. --------------------------------------------------
  123. // NOTCONSOLE