service-accounts.asciidoc 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. [role="xpack"]
  2. [[service-accounts]]
  3. === Service accounts
  4. The {stack-security-features} provide _service accounts_ specifically for
  5. integration with external services that connect to {es}, such as {fleet} server.
  6. Service accounts have a fixed set of privileges and cannot authenticate
  7. until you create a service account token for them. Additionally, service
  8. accounts are predefined in code, and are always enabled.
  9. A service account corresponds to a specific external service. You create service
  10. account tokens for a service account. The service can then authenticate with the
  11. token and perform relevant actions. For example, {fleet} server can use its
  12. service token to authenticate with {es} and then manage its own API keys.
  13. You can create multiple service tokens for the same service account, which
  14. prevents credential sharing between multiple instances of the same
  15. external service. Each instance can assume the same identity while using
  16. their own distinct service token for authentication.
  17. Service accounts provide flexibility over <<built-in-users,built-in users>>
  18. because they:
  19. * Do not rely on the <<native-realm,internal `native` realm>>, and aren't
  20. always required to rely on the `.security` index
  21. * Use a <<security-api-create-api-key-request-body,role descriptor>> named after the service account principal instead of
  22. traditional roles
  23. * Support multiple credentials through service account tokens
  24. Service accounts are not included in the response of the
  25. <<security-api-get-user,get users API>>. To retrieve a service account, use the
  26. <<security-api-get-service-accounts,get service accounts API>>. Use the
  27. <<security-api-get-service-credentials,get service account credentials API>>
  28. to retrieve all service credentials for a service account.
  29. [discrete]
  30. [[service-accounts-explanation]]
  31. === Service accounts usage
  32. Service accounts have a
  33. <<security-api-get-service-accounts-path-params,unique principal>> that takes
  34. the format of `<namespace>/<service>`, where the `namespace` is a top-level
  35. grouping of service accounts, and `service` is the name of the service and
  36. must be unique within its namespace.
  37. Service accounts are predefined in code. The following service accounts are
  38. available:
  39. `elastic/fleet-server`:: The service account used by the {fleet} server to
  40. communicate with {es}.
  41. `elastic/kibana`:: The service account used by {kib} to communicate with
  42. {es}.
  43. `elastic/enterprise-search-server`:: The service account used by Enterprise Search
  44. to communicate with {es}.
  45. // tag::service-accounts-usage[]
  46. IMPORTANT: Do not attempt to use service accounts for authenticating individual
  47. users. Service accounts can only be authenticated with service tokens, which are
  48. not applicable to regular users.
  49. // end::service-accounts-usage[]
  50. [discrete]
  51. [[service-accounts-tokens]]
  52. === Service account tokens
  53. A service account token, or service token, is a unique string that a
  54. service uses to authenticate with {es}. For a given service account, each token
  55. must have a unique name. Because tokens include access credentials, they should
  56. always be kept secret by whichever client is using them.
  57. Service tokens can be backed by either the `.security` index (recommended) or
  58. the `service_tokens` file. You can create multiple service tokens for a single
  59. service account, which enables multiple instances of the same service to run
  60. with different credentials.
  61. You must create a service token to use a service account. You can
  62. create a service token using either:
  63. * The <<security-api-create-service-token,create service account token API>>,
  64. which saves the new service token in the `.security` index and returns
  65. the bearer token in the HTTP response.
  66. * The <<service-tokens-command,elasticsearch-service-tokens>> CLI tool, which
  67. saves the new service token in the `$ES_HOME/config/service_tokens` file
  68. and outputs the bearer token to your terminal
  69. We recommend that you create service tokens via the REST API rather than the CLI.
  70. The API stores service tokens within the `.security` index which means that the
  71. tokens are available for authentication on all nodes, and will be backed up within
  72. cluster snapshots.
  73. The use of the CLI is intended for cases where there is an external orchestration
  74. process (such as {ece-ref}[{ece}] or {eck-ref}[{eck}]) that will manage the
  75. creation and distribution of the `service_tokens` file.
  76. Both of these methods (API and CLI) create a service token with a guaranteed
  77. secret string length of `22`.
  78. The minimal, acceptable length of a secret string for a service token is `10`.
  79. If the secret string doesn't meet this minimal length, authentication with {es}
  80. will fail without even checking the value of the service token.
  81. Service tokens never expire. You must actively
  82. <<security-api-delete-service-token,delete>> them if they are no longer needed.
  83. [discrete]
  84. [[authenticate-with-service-account-token]]
  85. === Authenticate with service tokens
  86. NOTE: Service accounts currently do not support basic authentication.
  87. To use a service account token, include the generated token value in a request
  88. with an `Authorization: Bearer` header:
  89. [source,shell]
  90. ----
  91. curl -H "Authorization: Bearer AAEAAWVsYXN0aWM...vZmxlZXQtc2VydmVyL3Rva2VuMTo3TFdaSDZ" http://localhost:9200/_security/_authenticate
  92. ----
  93. // NOTCONSOLE
  94. A successful authentication response includes a `token` field, which contains a
  95. `name` field for the name of the service token and a `type` field for the
  96. type of the service token:
  97. [source,js]
  98. ----
  99. {
  100. "username": "elastic/fleet-server",
  101. "roles": [],
  102. "full_name": "Service account - elastic/fleet-server",
  103. "email": null,
  104. "token": {
  105. "name": "token1", <1>
  106. "type": "_service_account_index" <2>
  107. },
  108. "metadata": {
  109. "_elastic_service_account": true
  110. },
  111. "enabled": true,
  112. "authentication_realm": {
  113. "name": "_service_account",
  114. "type": "_service_account"
  115. },
  116. "lookup_realm": {
  117. "name": "_service_account",
  118. "type": "_service_account"
  119. },
  120. "authentication_type": "token"
  121. }
  122. ----
  123. // NOTCONSOLE
  124. <1> Name of the service account token.
  125. <2> Type of service account token. The value always begins with
  126. `_service_account_` and is followed by a string that indicates the service
  127. token backend in use (can be either `file` or `index`).