get-roles.asciidoc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. "cluster" : [ "all" ],
  47. "indices" : [
  48. {
  49. "names" : [ "index1", "index2" ],
  50. "privileges" : [ "all" ],
  51. "allow_restricted_indices" : false,
  52. "field_security" : {
  53. "grant" : [ "title", "body" ]}
  54. }
  55. ],
  56. "applications" : [ ],
  57. "run_as" : [ "other_user" ],
  58. "metadata" : {
  59. "version" : 1
  60. },
  61. "transient_metadata": {
  62. "enabled": true
  63. }
  64. }
  65. }
  66. --------------------------------------------------
  67. To retrieve all roles, omit the role name:
  68. [source,console]
  69. --------------------------------------------------
  70. GET /_security/role
  71. --------------------------------------------------
  72. // TEST[continued]