service-tokens-command.asciidoc 4.3 KB

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