put-app-privileges.asciidoc 4.7 KB

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