create-roles.asciidoc 3.9 KB

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