service-tokens-command.asciidoc 4.3 KB

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