put-app-privileges.asciidoc 4.9 KB

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