certutil.asciidoc 12 KB

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