put-app-privileges.asciidoc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. [role="xpack"]
  2. [[security-api-put-privileges]]
  3. === Create or update application privileges API
  4. ++++
  5. <titleabbrev>Create or update application privileges</titleabbrev>
  6. ++++
  7. .New API reference
  8. [sidebar]
  9. --
  10. For the most up-to-date API details, refer to {api-es}/group/endpoint-security[Security APIs].
  11. --
  12. Adds or updates <<application-privileges,application privileges>>.
  13. [[security-api-put-privileges-request]]
  14. ==== {api-request-title}
  15. `POST /_security/privilege` +
  16. `PUT /_security/privilege`
  17. [[security-api-put-privileges-prereqs]]
  18. ==== {api-prereq-title}
  19. To use this API, you must have either:
  20. - the `manage_security` cluster privilege (or a greater privilege such as `all`); _or_
  21. - the _"Manage Application Privileges"_ global privilege for the application
  22. being referenced in the request
  23. [[security-api-put-privileges-desc]]
  24. ==== {api-description-title}
  25. This API creates or updates privileges. To remove privileges, use the
  26. <<security-api-delete-privilege,delete application privilege API>>.
  27. For more information, see <<roles-application-priv>>.
  28. To check a user's application privileges, use the
  29. <<security-api-has-privileges,has privileges API>>.
  30. [[security-api-put-privileges-request-body]]
  31. ==== {api-request-body-title}
  32. The body is a JSON object where the names of the fields are the application
  33. names and the value of each field is an object. The fields in this inner
  34. object are the names of the privileges and each value is a JSON object that
  35. includes the following fields:
  36. `actions`:: (array-of-string) A list of action names that are granted by this
  37. privilege. This field must exist and cannot be an empty array.
  38. `metadata`:: (object) Optional meta-data. Within the `metadata` object, keys
  39. that begin with `_` are reserved for system usage.
  40. [[security-api-app-privileges-validation]]
  41. ==== Validation
  42. Application names::
  43. Application names are formed from a _prefix_, with an optional _suffix_ that
  44. conform to the following rules:
  45. * The prefix must begin with a lowercase ASCII letter
  46. * The prefix must contain only ASCII letters or digits
  47. * The prefix must be at least 3 characters long
  48. * If the suffix exists, it must begin with either `-` or `_`
  49. * The suffix cannot contain any of the following characters:
  50. `\\`, `/`, `*`, `?`, `"`, `<`, `>`, `|`, `,`, `*`
  51. * No part of the name can contain whitespace.
  52. Privilege names::
  53. Privilege names must begin with a lowercase ASCII letter and must contain
  54. only ASCII letters and digits along with the characters `_`, `-` and `.`
  55. Action names::
  56. Action names can contain any number of printable ASCII characters and must
  57. contain at least one of the following characters: `/` `*`, `:`
  58. [[security-api-put-privileges-response-body]]
  59. ==== {api-response-body-title}
  60. A successful call returns a JSON structure that shows whether the privilege has
  61. been created or updated.
  62. [[security-api-put-privileges-example]]
  63. ==== {api-examples-title}
  64. To add a single privilege, submit a PUT or POST request to the
  65. `/_security/privilege/` endpoint. For example:
  66. [source,console]
  67. --------------------------------------------------
  68. PUT /_security/privilege
  69. {
  70. "myapp": {
  71. "read": {
  72. "actions": [ <1>
  73. "data:read/*" , <2>
  74. "action:login" ],
  75. "metadata": { <3>
  76. "description": "Read access to myapp"
  77. }
  78. }
  79. }
  80. }
  81. --------------------------------------------------
  82. <1> These strings have significance within the "myapp" application. {es} does not
  83. assign any meaning to them.
  84. <2> The use of a wildcard here (`*`) means that this privilege grants access to
  85. all actions that start with `data:read/`. {es} does not assign any meaning
  86. to these actions. However, if the request includes an application privilege
  87. such as `data:read/users` or `data:read/settings`, the
  88. <<security-api-has-privileges,has privileges API>> respects the use of a
  89. wildcard and returns `true`.
  90. <3> The metadata object is optional.
  91. [source,console-result]
  92. --------------------------------------------------
  93. {
  94. "myapp": {
  95. "read": {
  96. "created": true <1>
  97. }
  98. }
  99. }
  100. --------------------------------------------------
  101. <1> When an existing privilege is updated, `created` is set to false.
  102. To add multiple privileges, submit a POST request to the
  103. `/_security/privilege/` endpoint. For example:
  104. [source,console]
  105. --------------------------------------------------
  106. PUT /_security/privilege
  107. {
  108. "app01": {
  109. "read": {
  110. "actions": [ "action:login", "data:read/*" ]
  111. },
  112. "write": {
  113. "actions": [ "action:login", "data:write/*" ]
  114. }
  115. },
  116. "app02": {
  117. "all": {
  118. "actions": [ "*" ]
  119. }
  120. }
  121. }
  122. --------------------------------------------------
  123. A successful call returns a JSON structure that shows whether the privileges
  124. have been created or updated.
  125. [source,console-result]
  126. --------------------------------------------------
  127. {
  128. "app02": {
  129. "all": {
  130. "created": true
  131. }
  132. },
  133. "app01": {
  134. "read": {
  135. "created": true
  136. },
  137. "write": {
  138. "created": true
  139. }
  140. }
  141. }
  142. --------------------------------------------------