get-roles.asciidoc 2.8 KB

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