certutil.asciidoc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. [[certutil]]
  2. == elasticsearch-certutil
  3. The `elasticsearch-certutil` command simplifies the creation of certificates for
  4. use with Transport Layer Security (TLS) in the {stack}.
  5. [discrete]
  6. === Synopsis
  7. [source,shell]
  8. --------------------------------------------------
  9. bin/elasticsearch-certutil
  10. (
  11. (ca [--ca-dn <name>] [--days <n>] [--pem])
  12. | (cert ([--ca <file_path>] | [--ca-cert <file_path> --ca-key <file_path>])
  13. [--ca-dn <name>] [--ca-pass <password>] [--days <n>]
  14. [--dns <domain_name>] [--in <input_file>] [--ip <ip_addresses>]
  15. [--multiple] [--name <file_name>] [--pem] [--self-signed])
  16. | (csr [--dns <domain_name>] [--in <input_file>] [--ip <ip_addresses>]
  17. [--name <file_name>])
  18. [-E <KeyValuePair>] [--keysize <bits>] [--out <file_path>]
  19. [--pass <password>]
  20. )
  21. | http
  22. [-h, --help] ([-s, --silent] | [-v, --verbose])
  23. --------------------------------------------------
  24. [discrete]
  25. === Description
  26. You can specify one of the following modes: `ca`, `cert`, `csr`, `http`. The
  27. `elasticsearch-certutil` command also supports a silent mode of operation to
  28. enable easier batch operations.
  29. [discrete]
  30. [[certutil-ca]]
  31. ==== CA mode
  32. The `ca` mode generates a new certificate authority (CA). By default, it
  33. produces a single PKCS#12 output file, which holds the CA certificate and the
  34. private key for the CA. If you specify the `--pem` parameter, the command
  35. generates a zip file, which contains the certificate and private key in PEM
  36. format.
  37. You can subsequently use these files as input for the `cert` mode of the command.
  38. [discrete]
  39. [[certutil-cert]]
  40. ==== CERT mode
  41. The `cert` mode generates X.509 certificates and private keys. By default, it
  42. produces a single certificate and key for use on a single instance.
  43. To generate certificates and keys for multiple instances, specify the
  44. `--multiple` parameter, which prompts you for details about each instance.
  45. Alternatively, you can use the `--in` parameter to specify a YAML file that
  46. contains details about the instances.
  47. An instance is any piece of the Elastic Stack that requires a TLS or SSL
  48. certificate. Depending on your configuration, {es}, Logstash, {kib}, and Beats
  49. might all require a certificate and private key. The minimum required
  50. information for an instance is its name, which is used as the common name for
  51. the certificate. The instance name can be a hostname value or a full
  52. distinguished name. If the instance name would result in an invalid file or
  53. directory name, you must also specify a file name in the `--name` command
  54. parameter or in the `filename` field in an input YAML file.
  55. You can optionally provide IP addresses or DNS names for each instance. If
  56. neither IP addresses nor DNS names are specified, the Elastic Stack products
  57. cannot perform hostname verification and you might need to configure the
  58. `verification_mode` security setting to `certificate` only. For more information
  59. about this setting, see <<security-settings>>.
  60. All certificates that are generated by this command are signed by a CA unless
  61. the `--self-signed` parameter is specified. You must provide your own CA with the
  62. `--ca` or `--ca-cert` and `--ca-key` parameters unless `--self-signed` is specified.
  63. For more information about generating a CA, see the
  64. <<certutil-ca,CA mode of this command>>.
  65. To generate self-signed certificates, use the `--self-signed` parameter.
  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 `--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. `--keysize <bits>`::
  137. Defines the number of bits that are used in generated RSA keys. The default
  138. value is `2048`.
  139. `--multiple`::
  140. Specifies to generate files for multiple instances. This parameter cannot be
  141. used with the `ca` parameter.
  142. `--name <file_name>`::
  143. Specifies the name of the generated certificate. This parameter cannot be used
  144. with the `ca` parameter.
  145. `--out <file_path>`:: Specifies a path for the output files.
  146. `--pass <password>`:: Specifies the password for the generated private keys.
  147. +
  148. Keys stored in PKCS#12 format are always password protected, however,
  149. this password may be _blank_. If you want to specify a blank password
  150. without a prompt, use `--pass ""` (with no `=`) on the command line.
  151. +
  152. Keys stored in PEM format are password protected only if the
  153. `--pass` parameter is specified. If you do not supply an argument for the
  154. `--pass` parameter, you are prompted for a password.
  155. Encrypted PEM files do not support blank passwords (if you do not
  156. wish to password-protect your PEM keys, then do not specify
  157. `--pass`).
  158. `--pem`:: Generates certificates and keys in PEM format instead of PKCS#12. This
  159. parameter cannot be used with the `csr` parameter.
  160. `--self-signed`:: Generates self-signed certificates. This parameter is only
  161. applicable to the `cert` parameter.
  162. +
  163. --
  164. NOTE: This option is not recommended for <<encrypt-internode-communication,setting up TLS on a cluster>>.
  165. In fact, a self-signed certificate should be used only when you can be sure
  166. that a CA is definitely not needed and trust is directly given to the
  167. certificate itself.
  168. --
  169. `-s, --silent`:: Shows minimal output.
  170. `-v, --verbose`:: Shows verbose output.
  171. [discrete]
  172. === Examples
  173. The following command generates a CA certificate and private key in PKCS#12
  174. format:
  175. [source, sh]
  176. --------------------------------------------------
  177. bin/elasticsearch-certutil ca
  178. --------------------------------------------------
  179. You are prompted for an output filename and a password. Alternatively, you can
  180. specify the `--out` and `--pass` parameters.
  181. You can then generate X.509 certificates and private keys by using the new
  182. CA. For example:
  183. [source, sh]
  184. --------------------------------------------------
  185. bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12
  186. --------------------------------------------------
  187. You are prompted for the CA password and for an output filename and password.
  188. Alternatively, you can specify the `--ca-pass`, `--out`, and `--pass` parameters.
  189. By default, this command generates a file called `elastic-certificates.p12`,
  190. which you can copy to the relevant configuration directory for each Elastic
  191. product that you want to configure. For more information, see
  192. <<encrypt-internode-communication>>.
  193. [discrete]
  194. [[certutil-silent]]
  195. ==== Using `elasticsearch-certutil` in Silent Mode
  196. To use the silent mode of operation, you must create a YAML file that contains
  197. information about the instances. It must match the following format:
  198. [source, yaml]
  199. --------------------------------------------------
  200. instances:
  201. - name: "node1" <1>
  202. ip: <2>
  203. - "192.0.2.1"
  204. dns: <3>
  205. - "node1.mydomain.com"
  206. - name: "node2"
  207. ip:
  208. - "192.0.2.2"
  209. - "198.51.100.1"
  210. - name: "node3"
  211. - name: "node4"
  212. dns:
  213. - "node4.mydomain.com"
  214. - "node4.internal"
  215. - name: "CN=node5,OU=IT,DC=mydomain,DC=com"
  216. filename: "node5" <4>
  217. --------------------------------------------------
  218. <1> The name of the instance. This can be a simple string value or can be a
  219. Distinguished Name (DN). This is the only required field.
  220. <2> An optional array of strings that represent IP Addresses for this instance.
  221. Both IPv4 and IPv6 values are allowed. The values are added as Subject
  222. Alternative Names.
  223. <3> An optional array of strings that represent DNS names for this instance.
  224. The values are added as Subject Alternative Names.
  225. <4> The filename to use for this instance. This name is used as the name of the
  226. directory that contains the instance's files in the output. It is also used in
  227. the names of the files within the directory. This filename should not have an
  228. extension. Note: If the `name` provided for the instance does not represent a
  229. valid filename, then the `filename` field must be present.
  230. When your YAML file is ready, you can use the `elasticsearch-certutil` command
  231. to generate certificates or certificate signing requests. Simply use the `--in`
  232. parameter to specify the location of the file. For example:
  233. [source, sh]
  234. --------------------------------------------------
  235. bin/elasticsearch-certutil cert --silent --in instances.yml --out test1.zip --pass testpassword --ca elastic-stack-ca.p12
  236. --------------------------------------------------
  237. This command generates a compressed `test1.zip` file. After you decompress the
  238. output file, there is a directory for each instance that was listed in the
  239. `instances.yml` file. Each instance directory contains a single PKCS#12 (`.p12`)
  240. file, which contains the instance certificate, instance private key, and CA
  241. certificate.
  242. You can also use the YAML file to generate certificate signing requests. For
  243. example:
  244. [source, sh]
  245. --------------------------------------------------
  246. bin/elasticsearch-certutil csr --silent --in instances.yml --out test2.zip --pass testpassword
  247. --------------------------------------------------
  248. This command generates a compressed file, which contains a directory for each
  249. instance. Each instance directory contains a certificate signing request
  250. (`*.csr` file) and private key (`*.key` file).