get-service-credentials.asciidoc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. [role="xpack"]
  2. [[security-api-get-service-credentials]]
  3. === Get service account credentials API
  4. ++++
  5. <titleabbrev>Get service account credentials</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 all service credentials for a <<service-accounts,service account>>.
  13. [[security-api-get-service-credentials-request]]
  14. ==== {api-request-title}
  15. `GET /_security/service/<namespace>/<service>/credential`
  16. [[security-api-get-service-credentials-prereqs]]
  17. ==== {api-prereq-title}
  18. * To use this API, you must have at least the `read_security`
  19. <<privileges-list-cluster,cluster privilege>> (or a greater privilege
  20. such as `manage_service_account` or `manage_security`).
  21. [[security-api-get-service-credentials-desc]]
  22. ==== {api-description-title}
  23. Use this API to retrieve a list of credentials for a service account.
  24. The response includes service account tokens that were created with the
  25. <<security-api-create-service-token,create service account tokens API>>
  26. as well as file-backed tokens from all nodes of the cluster.
  27. NOTE: For tokens backed by the `service_tokens` file, the API collects
  28. them from all nodes of the cluster. Tokens with the same name from
  29. different nodes are assumed to be the same token and are only counted once
  30. towards the total number of service tokens.
  31. [[security-api-get-service-credentials-path-params]]
  32. ==== {api-path-parms-title}
  33. `namespace`::
  34. (Required, string) Name of the namespace.
  35. `service`::
  36. (Required, string) Name of the service name.
  37. [[security-api-get-service-credentials-example]]
  38. ==== {api-examples-title}
  39. The following request uses the <<security-api-create-service-token,create service account token API>> to create a service account token named `token1`
  40. in the `elastic/fleet-server` service account:
  41. [source,console]
  42. ----
  43. POST /_security/service/elastic/fleet-server/credential/token/token1
  44. ----
  45. The following request returns all credentials for the `elastic/fleet-server`
  46. service account:
  47. [source,console]
  48. ----
  49. GET /_security/service/elastic/fleet-server/credential
  50. ----
  51. // TEST[continued]
  52. The response includes all credentials related to the specified service account:
  53. [source,js]
  54. ----
  55. {
  56. "service_account": "elastic/fleet-server",
  57. "count": 3,
  58. "tokens": {
  59. "token1": {}, <1>
  60. "token42": {} <2>
  61. },
  62. "nodes_credentials": { <3>
  63. "_nodes": { <4>
  64. "total": 3,
  65. "successful": 3,
  66. "failed": 0
  67. },
  68. "file_tokens": { <5>
  69. "my-token": {
  70. "nodes": [ "node0", "node1" ] <6>
  71. }
  72. }
  73. }
  74. }
  75. ----
  76. // NOTCONSOLE
  77. <1> A new service account token backed by the `.security` index
  78. <2> An existing service account token backed by the `.security` index
  79. <3> This section contains service account credentials collected from all nodes of the cluster
  80. <4> General status showing how nodes respond to the above collection request
  81. <5> File-backed tokens collected from all nodes
  82. <6> List of nodes that (file-backed) `my-token` is found