get-service-credentials.asciidoc 2.9 KB

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