create-roles.asciidoc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. [role="xpack"]
  2. [[security-api-put-role]]
  3. === Create or update roles API
  4. Adds and updates roles in the native realm.
  5. ==== Request
  6. `POST /_xpack/security/role/<name>` +
  7. `PUT /_xpack/security/role/<name>`
  8. ==== Description
  9. The role API is generally the preferred way to manage roles, rather than using
  10. file-based role management. For more information about the native realm, see
  11. {stack-ov}/realms.html[Realms] and <<configuring-native-realm>>.
  12. ==== Path Parameters
  13. `name`::
  14. (string) The name of the role.
  15. ==== Request Body
  16. The following parameters can be specified in the body of a PUT or POST request
  17. and pertain to adding a role:
  18. `applications`:: (list) A list of application privilege entries.
  19. `application` (required)::: (string) The name of the application to which this entry applies
  20. `privileges`::: (list) A list of strings, where each element is the name of an application
  21. privilege or action.
  22. `resources`::: (list) A list resources to which the privileges are applied.
  23. `cluster`:: (list) A list of cluster privileges. These privileges define the
  24. cluster level actions that users with this role are able to execute.
  25. `global`:: (object) An object defining global privileges. A global privilege is
  26. a form of cluster privilege that is request-aware. Support for global privileges
  27. is currently limited to the management of application privileges.
  28. This field is optional.
  29. `indices`:: (list) A list of indices permissions entries.
  30. `field_security`::: (list) The document fields that the owners of the role have
  31. read access to. For more information, see
  32. {stack-ov}/field-and-document-access-control.html[Setting up field and document level security].
  33. `names` (required)::: (list) A list of indices (or index name patterns) to which the
  34. permissions in this entry apply.
  35. `privileges`(required)::: (list) The index level privileges that the owners of the role
  36. have on the specified indices.
  37. `query`::: A search query that defines the documents the owners of the role have
  38. read access to. A document within the specified indices must match this query in
  39. order for it to be accessible by the owners of the role.
  40. `metadata`:: (object) Optional meta-data. Within the `metadata` object, keys
  41. that begin with `_` are reserved for system usage.
  42. `run_as`:: (list) A list of users that the owners of this role can impersonate.
  43. For more information, see
  44. {stack-ov}/run-as-privilege.html[Submitting requests on behalf of other users].
  45. For more information, see {stack-ov}/defining-roles.html[Defining roles].
  46. ==== Authorization
  47. To use this API, you must have at least the `manage_security` cluster
  48. privilege.
  49. ==== Examples
  50. The following example adds a role called `my_admin_role`:
  51. [source,js]
  52. --------------------------------------------------
  53. POST /_xpack/security/role/my_admin_role
  54. {
  55. "cluster": ["all"],
  56. "indices": [
  57. {
  58. "names": [ "index1", "index2" ],
  59. "privileges": ["all"],
  60. "field_security" : { // optional
  61. "grant" : [ "title", "body" ]
  62. },
  63. "query": "{\"match\": {\"title\": \"foo\"}}" // optional
  64. }
  65. ],
  66. "applications": [
  67. {
  68. "application": "myapp",
  69. "privileges": [ "admin", "read" ],
  70. "resources": [ "*" ]
  71. }
  72. ],
  73. "run_as": [ "other_user" ], // optional
  74. "metadata" : { // optional
  75. "version" : 1
  76. }
  77. }
  78. --------------------------------------------------
  79. // CONSOLE
  80. A successful call returns a JSON structure that shows whether the role has been
  81. created or updated.
  82. [source,js]
  83. --------------------------------------------------
  84. {
  85. "role": {
  86. "created": true <1>
  87. }
  88. }
  89. --------------------------------------------------
  90. // TESTRESPONSE
  91. <1> When an existing role is updated, `created` is set to false.