certutil.asciidoc 13 KB

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