service-tokens-command.asciidoc 4.3 KB

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