certutil.asciidoc 13 KB

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