service-tokens-command.asciidoc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. [[service-tokens-command]]
  2. == elasticsearch-service-tokens
  3. Use the `elasticsearch-service-tokens` command to create, list, and delete file-based service account tokens.
  4. [discrete]
  5. === Synopsis
  6. [source,shell]
  7. ----
  8. bin/elasticsearch-service-tokens
  9. ([create <service_account_principal> <token_name>]) |
  10. ([list] [<service_account_principal>]) |
  11. ([delete <service_account_principal> <token_name>])
  12. ----
  13. [discrete]
  14. === Description
  15. NOTE: The recommended way to manage <<service-accounts-tokens,service tokens>>
  16. is via the <<security-api-create-service-token>> API.
  17. File based tokens are intended for use with orchestrators such as
  18. {ece-ref}[{ece}] and {eck-ref}[{eck}]
  19. This command creates a `service_tokens` file in the `$ES_HOME/config` directory
  20. when you create the first service account token. This file does not exist by
  21. default. {es} monitors this file for changes and dynamically reloads it.
  22. This command only makes changes to the `service_tokens` file on the local node.
  23. If the service token will be used to authenticate requests against multiple nodes
  24. in the cluster then you must copy the `service_tokens` file to each node.
  25. See <<service-accounts,service accounts>> for further information about the
  26. behaviour of service accounts and the management of service tokens.
  27. IMPORTANT: To ensure that {es} can read the service account token information at
  28. startup, run `elasticsearch-service-tokens` as the same user you use to run
  29. {es}. Running this command as `root` or some other user updates the permissions
  30. for the `service_tokens` file and prevents {es} from accessing it.
  31. [discrete]
  32. [[service-tokens-command-parameters]]
  33. === Parameters
  34. `create`::
  35. Creates a service account token for the specified service account.
  36. +
  37. .Properties of `create`
  38. [%collapsible%open]
  39. ====
  40. `<service_account_principal>`:::
  41. (Required, string) Service account principal that takes the format of
  42. `<namespace>/<service>`, where the `namespace` is a top-level grouping of
  43. service accounts, and `service` is the name of the service. For example, `elastic/fleet-server`.
  44. +
  45. The service account principal must match a known service account.
  46. `<token_name>`:::
  47. (Required, string) An identifier for the token name.
  48. +
  49. --
  50. Token names must be at least 1 and no more than 256 characters. They can contain
  51. alphanumeric characters (`a-z`, `A-Z`, `0-9`), dashes (`-`), and underscores
  52. (`_`), but cannot begin with an underscore.
  53. NOTE: Token names must be unique in the context of the associated service
  54. account.
  55. --
  56. ====
  57. `list`::
  58. Lists all service account tokens defined in the `service_tokens` file. If you
  59. specify a service account principal, the command lists only the tokens that
  60. belong to the specified service account.
  61. +
  62. .Properties of `list`
  63. [%collapsible%open]
  64. ====
  65. `<service_account_principal>`:::
  66. (Optional, string) Service account principal that takes the format of
  67. `<namespace>/<service>`, where the `namespace` is a top-level grouping of
  68. service accounts, and `service` is the name of the service. For example, `elastic/fleet-server`.
  69. +
  70. The service account principal must match a known service account.
  71. ====
  72. `delete`::
  73. Deletes a service account token for the specified service account.
  74. +
  75. .Properties of `delete`
  76. [%collapsible%open]
  77. ====
  78. `<service_account_principal>`:::
  79. (Required, string) Service account principal that takes the format of
  80. `<namespace>/<service>`, where the `namespace` is a top-level grouping of
  81. service accounts, and `service` is the name of the service. For example, `elastic/fleet-server`.
  82. +
  83. The service account principal must match a known service account.
  84. ====
  85. `<token_name>`:::
  86. (Required, string) Name of an existing token.
  87. [discrete]
  88. === Examples
  89. The following command creates a service account token named `my-token` for
  90. the `elastic/fleet-server` service account.
  91. [source,shell]
  92. ----
  93. bin/elasticsearch-service-tokens create elastic/fleet-server my-token
  94. ----
  95. The output is a bearer token, which is a Base64 encoded string.
  96. [source,shell]
  97. ----
  98. SERVICE_TOKEN elastic/fleet-server/my-token = AAEAAWVsYXN0aWM...vZmxlZXQtc2VydmVyL3Rva2VuMTo3TFdaSDZ
  99. ----
  100. Use this bearer token to authenticate with your {es} cluster.
  101. [source,shell]
  102. ----
  103. curl -H "Authorization: Bearer AAEAAWVsYXN0aWM...vZmxlZXQtc2VydmVyL3Rva2VuMTo3TFdaSDZ" http://localhost:9200/_cluster/health
  104. ----
  105. // NOTCONSOLE
  106. NOTE: If your node has `xpack.security.http.ssl.enabled` set to `true`, then
  107. you must specify `https` in the request URL.
  108. The following command lists all service account tokens that are defined in the
  109. `service_tokens` file.
  110. [source,shell]
  111. ----
  112. bin/elasticsearch-service-tokens list
  113. ----
  114. A list of all service account tokens displays in your terminal:
  115. [source,txt]
  116. ----
  117. elastic/fleet-server/my-token
  118. elastic/fleet-server/another-token
  119. ----
  120. The following command deletes the `my-token` service account token for the
  121. `elastic/fleet-server` service account:
  122. [source,shell]
  123. ----
  124. bin/elasticsearch-service-tokens delete elastic/fleet-server my-token
  125. ----