# Which certificate should I prepare when enabling mutual tls authentication?

**URL:** <https://discuss.elastic.co/t/which-certificate-should-i-prepare-when-enabling-mutual-tls-authentication/227593>\
**Category:** Elasticsearch\
**Created:** [April 11, 2020, 10:20am UTC](https://discuss.elastic.co/t/which-certificate-should-i-prepare-when-enabling-mutual-tls-authentication/227593 "2020-04-11T10:20:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![YuWatanabe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuwatanabe/32/13259_2.png) [@YuWatanabe](https://discuss.elastic.co/u/YuWatanabe)\
**Post date:** [April 11, 2020, 10:20am UTC](https://discuss.elastic.co/t/which-certificate-should-i-prepare-when-enabling-mutual-tls-authentication/227593/1 "2020-04-11T10:20:46Z")

</div>

Hello .

I am trying to setup mutual authenticatation by setting [xpack.security.http.ssl.client\_authentication](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-settings.html#http-tls-ssl-settings) to **true**.

However, I am getting below error on elasticsearch (_v7.6.2_) side .

```auto
Caused by: javax.net.ssl.SSLHandshakeException: Empty server certificate chain
        at sun.security.ssl.Alert.createSSLException(Alert.java:131) ~[?:?]
        at sun.security.ssl.Alert.createSSLException(Alert.java:117) ~[?:?]
        at sun.security.ssl.TransportContext.fatal(TransportContext.java:311) ~[?:?]
        at sun.security.ssl.TransportContext.fatal(TransportContext.java:267) ~[?:?]
        at sun.security.ssl.TransportContext.fatal(TransportContext.java:258) ~[?:?]
        at sun.security.ssl.CertificateMessage$T12CertificateConsumer.onCertificate(CertificateMessage.java:381) ~[?:?]
        at sun.security.ssl.CertificateMessage$T12CertificateConsumer.consume(CertificateMessage.java:366) ~[?:?]
        at sun.security.ssl.SSLHandshake.consume(SSLHandshake.java:396) ~[?:?]
        at sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:444) ~[?:?]
        at sun.security.ssl.SSLEngineImpl$DelegatedTask$DelegatedAction.run(SSLEngineImpl.java:1260) ~[?:?]
        at sun.security.ssl.SSLEngineImpl$DelegatedTask$DelegatedAction.run(SSLEngineImpl.java:1247) ~[?:?]
        at java.security.AccessController.doPrivileged(AccessController.java:691) ~[?:?]
        at sun.security.ssl.SSLEngineImpl$DelegatedTask.run(SSLEngineImpl.java:1192) ~[?:?]
        at io.netty.handler.ssl.SslHandler.runAllDelegatedTasks(SslHandler.java:1502) ~[netty-handler-4.1.43.Final.jar:4.1.43.Final]
        at io.netty.handler.ssl.SslHandler.runDelegatedTasks(SslHandler.java:1516) ~[netty-handler-4.1.43.Final.jar:4.1.43.Final]
        at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1400) ~[netty-handler-4.1.43.Final.jar:4.1.43.Final]
        at io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1227) ~[netty-handler-4.1.43.Final.jar:4.1.43.Final]
        at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1274) ~[netty-handler-4.1.43.Final.jar:4.1.43.Final]
        at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:503) ~[netty-codec-4.1.43.Final.jar:4.1.43.Final]
        at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:442) ~[netty-codec-4.1.43.Final.jar:4.1.43.Final]
        ... 16 more

```

I am using apache beam and I have set _ca cert_ in a [keystore](https://beam.apache.org/releases/javadoc/2.19.0/org/apache/beam/sdk/io/elasticsearch/ElasticsearchIO.ConnectionConfiguration.html#withKeystorePath-java.lang.String-) on my cilent side .

```auto
[ywatanabe@fedora-desktop elasticsearch-7.6.2]$ keytool -list -keystore /home/ywatanabe/Devel/github/public-issues/etc/certs/keystore.jks -storepass 8IK994hP4nw=
Keystore type: jks
Keystore provider: SUN

Your keystore contains 1 entry

ca, Apr 11, 2020, trustedCertEntry, 
Certificate fingerprint (SHA1): 85:81:10:42:27:FE:CD:28:FD:D5:09:B2:C9:E7:06:A3:DF:61:A3:F1

```

Questions I would like to ask are ,

Q1. Is my understanding correct for which cretificates I need to prepare ?

- CA certificate
- Private key
- SSL certificate

Q2. Are self signed certificate allowed in this context ?

Thanks,  
Yu Watanabe

---

<div class="post-metadata">

**Author:** ![ikakavas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ikakavas/32/34430_2.png) [@ikakavas](https://discuss.elastic.co/u/ikakavas)\
**Post date:** [April 11, 2020, 2:31pm UTC](https://discuss.elastic.co/t/which-certificate-should-i-prepare-when-enabling-mutual-tls-authentication/227593/2 "2020-04-11T14:31:11Z")

</div>

Please share your entire elasticsearch configuration, at least the part related to http ssl.

Also take a look in our docs : [https://www.elastic.co/guide/en/elasticsearch/reference/current/configuring-tls.html#tls-http](https://www.elastic.co/guide/en/elasticsearch/reference/current/configuring-tls.html#tls-http)

Once we have more information from your current config ,we can suggest what might be missing or needs changing. We cant do that with what you have shared so far.

---

<div class="post-metadata">

**Author:** ![YuWatanabe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuwatanabe/32/13259_2.png) [@YuWatanabe](https://discuss.elastic.co/u/YuWatanabe)\
**Post date:** [April 12, 2020, 1:49am UTC](https://discuss.elastic.co/t/which-certificate-should-i-prepare-when-enabling-mutual-tls-authentication/227593/3 "2020-04-12T01:49:23Z")

</div>

Thank you for the reply. Below is the whole configuration.  
In the meantime I will also review the [doc](https://www.elastic.co/guide/en/elasticsearch/reference/current/configuring-tls.html#tls-http) again.

```auto
[ywatanabe@fedora-desktop elasticsearch-7.6.2]$ cat config/elasticsearch.yml 
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
#

#
# Enable security
#
xpack.security.enabled: true

#
# For Transport Layer
#
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate 
xpack.security.transport.ssl.key: certs/tls/instance.key
xpack.security.transport.ssl.certificate: certs/tls/instance.crt
xpack.security.transport.ssl.certificate_authorities: ["certs/tls/ca.crt"] 

#
# For HTTP Layer 
#
xpack.security.http.ssl.enabled: true
xpack.security.http.ssl.client_authentication: none
xpack.security.http.ssl.certificate: "certs/http/http-localhost.crt"
xpack.security.http.ssl.key: "certs/http/http-localhost.key"
xpack.security.http.ssl.certificate_authorities: ["certs/tls/ca.crt"]

```

I have used below commands to create each certifiacte and key.

**ca.crt**

`bin/elasticsearch-certutil ca --pem`

**instance.crt**  
`bin/elasticsearch-certutil cert --pem --ca-cert ca/ca.crt -ca-key ca/ca.key`

**http-localhost.crt and http-localhost.key**

`bin/elasticsearch-certutil http -pem`

\*\*client side keystore (ca.crt is above one) \*\*

`keytool -import -alias ca -file ca/ca.crt -keystore /home/ywatanabe/Devel/github/public-issues/etc/certs/keystore.jks -storepass 8IK994hP4nw=`

---

<div class="post-metadata">

**Author:** ![ikakavas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ikakavas/32/34430_2.png) [@ikakavas](https://discuss.elastic.co/u/ikakavas)\
**Post date:** [April 13, 2020, 7:29am UTC](https://discuss.elastic.co/t/which-certificate-should-i-prepare-when-enabling-mutual-tls-authentication/227593/4 "2020-04-13T07:29:28Z")

</div>

As you will see in our docs, you need to

1. Change `xpack.security.http.ssl.client_authentication: none` to `optional` or `required`.

2. Set up your client for mutal TLS:  
Your client needs to have its own client key and certificate if you want to do mutual TLS. What you have done so far is to import the CA cert of the server in your client keystore. This means that your client is able to validate and verify the server certificate, but this is only 50% of the "mutual" TLS.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 11, 2020, 7:29am UTC](https://discuss.elastic.co/t/which-certificate-should-i-prepare-when-enabling-mutual-tls-authentication/227593/5 "2020-05-11T07:29:33Z")

</div>

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