Create new cert and key from existing ca.crt : elasticsearch-certutil

Initially when I created the ELK cluster I missed to include the Logstash and filebeat servers to generate the certificates:

Created certificates and key files using this command :

bin/elasticsearch-certutil cert ca --pem --in ~/tmp/cert_blog/instance.yml --out ~/tmp/cert_blog/

I saw this old discussion : Elasticsearch didn't create ca.key. How can i create new key/crt for new instances?
The blog article isn't updated on how to create new certificates using existing ca.crt.

I tried to run the above command with --keep-ca-key which create ca.crt and ca.key, however when i try to create new certificates for new servers added to the instance.yml it gives me this error message:

    /usr/share/elasticsearch/bin/elasticsearch-certutil cert ca --pem --in ~/tmp/cert_blog/instance.yml --out ~/tmp/cert_blog/ --ca-cert ~/tmp/cert_blog/certs/ca/ca.crt --ca-key ~/tmp/cert_blog/certs/ca/ca.key
This tool assists you in the generation of X.509 certificates and certificate
signing requests for use with SSL/TLS in the Elastic stack.

The 'cert' mode generates X.509 certificate and private keys.
    * By default, this generates a single certificate and key for use
       on a single instance.
    * The '-multiple' option will prompt you to enter details for multiple
       instances and will generate a certificate and key for each one
    * The '-in' option allows for the certificate generation to be automated by describing
       the details of each instance in a YAML file

    * An instance is any piece of the Elastic Stack that requires an SSL certificate.
      Depending on your configuration, Elasticsearch, Logstash, Kibana, and Beats
      may all require a certificate and private key.
    * The minimum required value for each instance is a name. This can simply be the
      hostname, which will be used as the Common Name of the certificate. A full
      distinguished name may also be used.
    * A filename value may be required for each instance. This is necessary when the
      name would result in an invalid file or directory name. The name provided here
      is used as the directory name (within the zip) and the prefix for the key and
      certificate files. The filename is required if you are prompted and the name
      is not displayed in the prompt.
    * IP addresses and DNS names are optional. Multiple values can be specified as a
      comma separated string. If no IP addresses or DNS names are provided, you may
      disable hostname verification in your SSL configuration.

    * All certificates generated by this tool will be signed by a certificate authority (CA).
    * The tool can automatically generate a new CA for you, or you can provide your own with the
         -ca or -ca-cert command line options.

By default the 'cert' mode produces a single PKCS#12 output file which holds:
    * The instance certificate
    * The private key for the instance certificate
    * The CA certificate

If you specify any of the following options:
    * -pem (PEM formatted output)
    * -keep-ca-key (retain generated CA key)
    * -multiple (generate multiple certificates)
    * -in (generate certificates from an input file)
then the output will be be a zip file containing individual certificate/key files

Exception in thread "main" java.lang.IllegalStateException: Error parsing Private Key from: /root/tmp/cert_blog/certs/ca/ca.key. File did not contain a supported key format
	at org.elasticsearch.xpack.core.ssl.PemUtils.readPrivateKey(
	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(
	at org.elasticsearch.cli.MultiCommand.execute(
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(
	at org.elasticsearch.cli.Command.main(

There is no way to create certificates using only an existing CA certificate, the blog would be updated to add a warning about this , not to add instructions about how to do something like this , as it cannot be done.

I tried to run the above command with --keep-ca-key which create ca.crt and ca.key

This created a new CA key and certificate, it did not reuse the old one , just so that we are clear.

a. You don't need to pass the ca parameter, you don;t need to generate a CA again, you have one.
b. Your --ca-key ~/tmp/cert_blog/certs/ca/ca.key seems to be malformed somehow. What is the first line of that file?

first line of ca.key : "-----BEGIN CERTIFICATE-----"

We ended up creating new certificates for all nodes and updating the config files to reflect to these while adding the new nodes. Sorry for late reply.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.