put-app-privileges.asciidoc 5.0 KB

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