token-authentication-services.asciidoc 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. [role="xpack"]
  2. [[token-authentication-services]]
  3. === Token-based authentication services
  4. The {stack-security-features} authenticate users by using realms and one or
  5. more token-based authentication services. The token-based authentication
  6. services are used for authenticating and managing tokens. You can attach these
  7. tokens to requests that are sent to {es} and use them as credentials. When {es}
  8. receives a request that must be authenticated, it consults the token-based
  9. authentication services first, and then the realm chain.
  10. The {security-features} provide the following built-in token-based
  11. authentication services, which are listed in the order they are consulted:
  12. _service-accounts_::
  13. +
  14. --
  15. The <<service-accounts,service accounts>> use either the
  16. <<security-api-create-service-token,create service account token API>>
  17. or the <<service-tokens-command,elasticsearch-service-tokens>> CLI tool to
  18. generate service account tokens.
  19. To use a service account token, include the generated token value in a request
  20. with an `Authorization: Bearer` header:
  21. [source,shell]
  22. ----
  23. curl -H "Authorization: Bearer AAEAAWVsYXN0aWMvZ...mXQtc2VydmMTpyNXdkYmRib1FTZTl2R09Ld2FKR0F3" http://localhost:9200/_cluster/health
  24. ----
  25. // NOTCONSOLE
  26. include::service-accounts.asciidoc[tag=service-accounts-usage]
  27. --
  28. [[token-authentication-access-token]]
  29. _token-service_::
  30. The token service uses the <<security-api-get-token,get token API>> to
  31. generate access tokens and refresh tokens based on the OAuth2 specification.
  32. The access token is a short-lived token. By default, it expires after 20 minutes
  33. but it can be configured to last a maximum of 1 hour. It can be refreshed by
  34. using a refresh token, which has a lifetime of 24 hours. The access token is a
  35. bearer token. You can use it by sending a request with an `Authorization`
  36. header with a value that has the prefix "Bearer " followed by the value of the
  37. access token. For example:
  38. +
  39. --
  40. [source,shell]
  41. --------------------------------------------------
  42. curl -H "Authorization: Bearer dGhpcyBpcyBub3Qx5...F0YS4gZG8gbm90IHRyeSB0byByZWFkIHRva2VuIQ==" http://localhost:9200/_cluster/health
  43. --------------------------------------------------
  44. // NOTCONSOLE
  45. --
  46. [[token-authentication-api-key]]
  47. _api-key-service_::
  48. The API key service uses the
  49. <<security-api-create-api-key,create API key API>> to generate API keys.
  50. By default, the API keys do not expire. When you make a request to create API
  51. keys, you can specify an expiration and permissions for the API key. The
  52. permissions are limited by the authenticated user's permissions. You can use the
  53. API key by sending a request with an `Authorization` header with a value that
  54. has the prefix "ApiKey " followed by the credentials. The credentials are the
  55. base64 encoding of the API key ID and the API key joined by a colon. For example:
  56. +
  57. --
  58. [source,shell]
  59. --------------------------------------------------
  60. curl -H "Authorization: ApiKey VnVhQ2ZHY0JDZGJrU...W0tZTVhT3g6dWkybHAyYXhUTm1zeWFrd0dk5udw==" http://localhost:9200/_cluster/health
  61. --------------------------------------------------
  62. // NOTCONSOLE
  63. --
  64. Depending on your use case, you may want to decide on the lifetime of the tokens
  65. generated by these services. You can then use this information to decide which
  66. service to use to generate and manage the tokens. Non-expiring API keys may seem
  67. like the easy option but you must consider the security implications that come
  68. with non-expiring keys. Both the _token-service_ and _api-key-service_ permit
  69. you to invalidate the tokens. See
  70. <<security-api-invalidate-token,invalidate token API>> and
  71. <<security-api-invalidate-api-key,invalidate API key API>>.
  72. IMPORTANT: Authentication support for JWT bearer tokens was introduced in {es}
  73. 8.2 through the <<jwt-auth-realm>>, which cannot be enabled through
  74. token-authentication services. Realms offer flexible order and configurations of
  75. zero, one, or multiple JWT realms.