certutil.asciidoc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. [role="xpack"]
  2. [testenv="gold+"]
  3. [[certutil]]
  4. == elasticsearch-certutil
  5. The `elasticsearch-certutil` command simplifies the creation of certificates for
  6. use with Transport Layer Security (TLS) in the Elastic Stack.
  7. [float]
  8. === Synopsis
  9. [source,shell]
  10. --------------------------------------------------
  11. bin/elasticsearch-certutil
  12. (
  13. (ca [--ca-dn <name>] [--days <n>] [--pem])
  14. | (cert ([--ca <file_path>] | [--ca-cert <file_path> --ca-key <file_path>])
  15. [--ca-dn <name>] [--ca-pass <password>] [--days <n>]
  16. [--dns <domain_name>] [--in <input_file>] [--ip <ip_addresses>]
  17. [--keep-ca-key] [--multiple] [--name <file_name>] [--pem])
  18. | (csr [--dns <domain_name>] [--in <input_file>] [--ip <ip_addresses>]
  19. [--name <file_name>])
  20. [-E <KeyValuePair>] [--keysize <bits>] [--out <file_path>]
  21. [--pass <password>]
  22. )
  23. [-h, --help] ([-s, --silent] | [-v, --verbose])
  24. --------------------------------------------------
  25. [float]
  26. === Description
  27. You can specify one of the following modes: `ca`, `cert`, `csr`. The
  28. `elasticsearch-certutil` command also supports a silent mode of operation to
  29. enable easier batch operations.
  30. [float]
  31. [[certutil-ca]]
  32. ==== CA mode
  33. The `ca` mode generates a new certificate authority (CA). By default, it
  34. produces a single PKCS#12 output file, which holds the CA certificate and the
  35. private key for the CA. If you specify the `--pem` parameter, the command
  36. generates a zip file, which contains the certificate and private key in PEM
  37. format.
  38. You can subsequently use these files as input for the `cert` mode of the command.
  39. [float]
  40. [[certutil-cert]]
  41. ==== CERT mode
  42. The `cert` mode generates X.509 certificates and private keys. By default, it
  43. produces a single certificate and key for use on a single instance.
  44. To generate certificates and keys for multiple instances, specify the
  45. `--multiple` parameter, which prompts you for details about each instance.
  46. Alternatively, you can use the `--in` parameter to specify a YAML file that
  47. contains details about the instances.
  48. An instance is any piece of the Elastic Stack that requires a TLS or SSL
  49. certificate. Depending on your configuration, {es}, Logstash, {kib}, and Beats
  50. might all require a certificate and private key. The minimum required
  51. information for an instance is its name, which is used as the common name for
  52. the certificate. The instance name can be a hostname value or a full
  53. distinguished name. If the instance name would result in an invalid file or
  54. directory name, you must also specify a file name in the `--name` command
  55. parameter or in the `filename` field in an input YAML file.
  56. You can optionally provide IP addresses or DNS names for each instance. If
  57. neither IP addresses nor DNS names are specified, the Elastic stack products
  58. cannot perform hostname verification and you might need to configure the
  59. `verification_mode` security setting to `certificate` only. For more information
  60. about this setting, see <<security-settings>>.
  61. All certificates that are generated by this command are signed by a CA. You can
  62. provide your own CA with the `--ca` or `--ca-cert` parameters. Otherwise, the
  63. command automatically generates a new CA for you. For more information about
  64. generating a CA, see the <<certutil-ca,CA mode of this command>>.
  65. By default, the `cert` mode produces a single PKCS#12 output file which holds
  66. the instance certificate, the instance private key, and the CA certificate. If
  67. you specify the `--pem` parameter, the command generates PEM formatted
  68. certificates and keys and packages them into a zip file.
  69. If you specify the `--keep-ca-key`, `--multiple` or `--in` parameters,
  70. the command produces a zip file containing the generated certificates and keys.
  71. [float]
  72. [[certutil-csr]]
  73. ==== CSR mode
  74. The `csr` mode generates certificate signing requests (CSRs) that you can send
  75. to a trusted certificate authority to obtain signed certificates. The signed
  76. certificates must be in PEM or PKCS#12 format to work with {es}
  77. {security-features}.
  78. By default, the command produces a single CSR for a single instance.
  79. To generate CSRs for multiple instances, specify the `--multiple` parameter,
  80. which prompts you for details about each instance. Alternatively, you can use
  81. the `--in` parameter to specify a YAML file that contains details about the
  82. instances.
  83. The `csr` mode produces a single zip file which contains the CSRs and the
  84. private keys for each instance. Each CSR is provided as a standard PEM
  85. encoding of a PKCS#10 CSR. Each key is provided as a PEM encoding of an RSA
  86. private key.
  87. [float]
  88. === Parameters
  89. `ca`:: Specifies to generate a new local certificate authority (CA). This
  90. parameter cannot be used with the `csr` or `cert` parameters.
  91. `cert`:: Specifies to generate new X.509 certificates and keys.
  92. This parameter cannot be used with the `csr` or `ca` parameters.
  93. `csr`:: Specifies to generate certificate signing requests. This parameter
  94. cannot be used with the `ca` or `cert` parameters.
  95. `--ca <file_path>`:: Specifies the path to an existing CA key pair
  96. (in PKCS#12 format). This parameter cannot be used with the `ca` or `csr` parameters.
  97. `--ca-cert <file_path>`:: Specifies the path to an existing CA certificate (in
  98. PEM format). You must also specify the `--ca-key` parameter. The `--ca-cert`
  99. parameter cannot be used with the `ca` or `csr` parameters.
  100. `--ca-dn <name>`:: Defines the _Distinguished Name_ (DN) that is used for the
  101. generated CA certificate. The default value is
  102. `CN=Elastic Certificate Tool Autogenerated CA`. This parameter cannot be used
  103. with the `csr` parameter.
  104. `--ca-key <file_path>`:: Specifies the path to an existing CA private key (in
  105. PEM format). You must also specify the `--ca-cert` parameter. The `--ca-key`
  106. parameter cannot be used with the `ca` or `csr` parameters.
  107. `--ca-pass <password>`:: Specifies the password for an existing CA private key
  108. or the generated CA private key. This parameter cannot be used with the `ca` or
  109. `csr` parameters.
  110. `--days <n>`:: Specifies an integer value that represents the number of days the
  111. generated certificates are valid. The default value is `1095`. This parameter
  112. cannot be used with the `csr` parameter.
  113. `--dns <domain_name>`:: Specifies a comma-separated list of DNS names. This
  114. parameter cannot be used with the `ca` parameter.
  115. `-E <KeyValuePair>`:: Configures a setting.
  116. `-h, --help`:: Returns all of the command parameters.
  117. `--in <input_file>`:: Specifies the file that is used to run in silent mode. The
  118. input file must be a YAML file. This parameter cannot be used with the `ca`
  119. parameter.
  120. `--ip <IP_addresses>`:: Specifies a comma-separated list of IP addresses. This
  121. parameter cannot be used with the `ca` parameter.
  122. `--keep-ca-key`:: When running in `cert` mode with an automatically-generated
  123. CA, specifies to retain the CA private key for future use.
  124. `--keysize <bits>`::
  125. Defines the number of bits that are used in generated RSA keys. The default
  126. value is `2048`.
  127. `--multiple`::
  128. Specifies to generate files for multiple instances. This parameter cannot be
  129. used with the `ca` parameter.
  130. `--name <file_name>`::
  131. Specifies the name of the generated certificate. This parameter cannot be used
  132. with the `ca` parameter.
  133. `--out <file_path>`:: Specifies a path for the output files.
  134. `--pass <password>`:: Specifies the password for the generated private keys.
  135. +
  136. Keys stored in PKCS#12 format are always password protected, however,
  137. this password may be _blank_. If you want to specify a blank password
  138. without a prompt, use `--pass ""` (with no `=`) on the command line.
  139. +
  140. Keys stored in PEM format are password protected only if the
  141. `--pass` parameter is specified. If you do not supply an argument for the
  142. `--pass` parameter, you are prompted for a password.
  143. Encrypted PEM files do not support blank passwords (if you do not
  144. wish to password-protect your PEM keys, then do not specify
  145. `--pass`).
  146. `--pem`:: Generates certificates and keys in PEM format instead of PKCS#12. This
  147. parameter cannot be used with the `csr` parameter.
  148. `-s, --silent`:: Shows minimal output.
  149. `-v, --verbose`:: Shows verbose output.
  150. [float]
  151. === Examples
  152. The following command generates a CA certificate and private key in PKCS#12
  153. format:
  154. [source, sh]
  155. --------------------------------------------------
  156. bin/elasticsearch-certutil ca
  157. --------------------------------------------------
  158. You are prompted for an output filename and a password. Alternatively, you can
  159. specify the `--out` and `--pass` parameters.
  160. You can then generate X.509 certificates and private keys by using the new
  161. CA. For example:
  162. [source, sh]
  163. --------------------------------------------------
  164. bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12
  165. --------------------------------------------------
  166. You are prompted for the CA password and for an output filename and password.
  167. Alternatively, you can specify the `--ca-pass`, `--out`, and `--pass` parameters.
  168. By default, this command generates a file called `elastic-certificates.p12`,
  169. which you can copy to the relevant configuration directory for each Elastic
  170. product that you want to configure. For more information, see
  171. {xpack-ref}/ssl-tls.html[Setting Up TLS on a Cluster].
  172. [float]
  173. [[certutil-silent]]
  174. ==== Using `elasticsearch-certutil` in Silent Mode
  175. To use the silent mode of operation, you must create a YAML file that contains
  176. information about the instances. It must match the following format:
  177. [source, yaml]
  178. --------------------------------------------------
  179. instances:
  180. - name: "node1" <1>
  181. ip: <2>
  182. - "192.0.2.1"
  183. dns: <3>
  184. - "node1.mydomain.com"
  185. - name: "node2"
  186. ip:
  187. - "192.0.2.2"
  188. - "198.51.100.1"
  189. - name: "node3"
  190. - name: "node4"
  191. dns:
  192. - "node4.mydomain.com"
  193. - "node4.internal"
  194. - name: "CN=node5,OU=IT,DC=mydomain,DC=com"
  195. filename: "node5" <4>
  196. --------------------------------------------------
  197. <1> The name of the instance. This can be a simple string value or can be a
  198. Distinguished Name (DN). This is the only required field.
  199. <2> An optional array of strings that represent IP Addresses for this instance.
  200. Both IPv4 and IPv6 values are allowed. The values are added as Subject
  201. Alternative Names.
  202. <3> An optional array of strings that represent DNS names for this instance.
  203. The values are added as Subject Alternative Names.
  204. <4> The filename to use for this instance. This name is used as the name of the
  205. directory that contains the instance's files in the output. It is also used in
  206. the names of the files within the directory. This filename should not have an
  207. extension. Note: If the `name` provided for the instance does not represent a
  208. valid filename, then the `filename` field must be present.
  209. When your YAML file is ready, you can use the `elasticsearch-certutil` command
  210. to generate certificates or certificate signing requests. Simply use the `--in`
  211. parameter to specify the location of the file. For example:
  212. [source, sh]
  213. --------------------------------------------------
  214. bin/elasticsearch-certutil cert --silent --in instances.yml --out test1.zip --pass testpassword
  215. --------------------------------------------------
  216. This command generates a compressed `test1.zip` file. After you decompress the
  217. output file, there is a directory for each instance that was listed in the
  218. `instances.yml` file. Each instance directory contains a single PKCS#12 (`.p12`)
  219. file, which contains the instance certificate, instance private key, and CA
  220. certificate.
  221. You an also use the YAML file to generate certificate signing requests. For
  222. example:
  223. [source, sh]
  224. --------------------------------------------------
  225. bin/elasticsearch-certutil csr --silent --in instances.yml --out test2.zip --pass testpassword
  226. --------------------------------------------------
  227. This command generates a compressed file, which contains a directory for each
  228. instance. Each instance directory contains a certificate signing request
  229. (`*.csr` file) and private key (`*.key` file).