get-roles.asciidoc 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. [role="xpack"]
  2. [[security-api-get-role]]
  3. === Get roles API
  4. ++++
  5. <titleabbrev>Get roles</titleabbrev>
  6. ++++
  7. Retrieves roles in the native realm.
  8. [[security-api-get-role-request]]
  9. ==== {api-request-title}
  10. `GET /_security/role` +
  11. `GET /_security/role/<name>` +
  12. [[security-api-get-role-prereqs]]
  13. ==== {api-prereq-title}
  14. * To use this API, you must have at least the `read_security` cluster privilege.
  15. [[security-api-get-role-desc]]
  16. ==== {api-description-title}
  17. The role management APIs are generally the preferred way to manage roles, rather than using
  18. <<roles-management-file,file-based role management>>. The get roles
  19. API cannot retrieve roles that are defined in roles files.
  20. [[security-api-get-role-path-params]]
  21. ==== {api-path-parms-title}
  22. `name`::
  23. (Optional, string) The name of the role. You can specify multiple roles as a
  24. comma-separated list. If you do not specify this parameter, the API
  25. returns information about all roles.
  26. [[security-api-get-role-response-body]]
  27. ==== {api-response-body-title}
  28. A successful call returns an array of roles with the JSON representation of the
  29. role.
  30. [[security-api-get-role-response-codes]]
  31. ==== {api-response-codes-title}
  32. If the role is not defined in the native realm, the request returns 404.
  33. [[security-api-get-role-example]]
  34. ==== {api-examples-title}
  35. The following example retrieves information about the `my_admin_role` role in
  36. the native realm:
  37. [source,console]
  38. --------------------------------------------------
  39. GET /_security/role/my_admin_role
  40. --------------------------------------------------
  41. // TEST[setup:admin_role]
  42. [source,console-result]
  43. --------------------------------------------------
  44. {
  45. "my_admin_role": {
  46. "description": "Grants full access to all management features within the cluster.",
  47. "cluster" : [ "all" ],
  48. "indices" : [
  49. {
  50. "names" : [ "index1", "index2" ],
  51. "privileges" : [ "all" ],
  52. "allow_restricted_indices" : false,
  53. "field_security" : {
  54. "grant" : [ "title", "body" ]}
  55. }
  56. ],
  57. "applications" : [ ],
  58. "run_as" : [ "other_user" ],
  59. "metadata" : {
  60. "version" : 1
  61. },
  62. "transient_metadata": {
  63. "enabled": true
  64. }
  65. }
  66. }
  67. --------------------------------------------------
  68. To retrieve all roles, omit the role name:
  69. [source,console]
  70. --------------------------------------------------
  71. GET /_security/role
  72. --------------------------------------------------
  73. // TEST[continued]