ES 7.4.1 - Authentication [Rest API]
I got an answer from ES forum (didn't thought to ask there first..)
Because, as developer, I always looking for answer here, in stackoverflow, I decide to not delete this question and copy TimV answer:
The documentation you are looking for is here: https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.4/_encrypted_communication.html
SSL is automatically enabled (or not) based on the scheme (protocol) in the HttpHost
objects you pass to the builder.
RestClient.builder(hosts)
If you are using SSL, you want to pass "https"
as the scheme (3rd argument) when you construct the HttpHost
objects (hosts
).
Unfortunately there is no simple means to pass certificate_authorities
to the Rest client, you need to turn those certificates into a standard Java truststore.You can probably find some sample code on the web ("convert PEM certificates to Java truststore"), but the gist of it is:
- Open the certificate authority files as an
InputStream
- Create a X.509 certificate factory:
java.security.cert.CertificateFactory.getInstance("X.509")
- Call
generateCertificates
on the certificate factory to read those certificate files into javaCertificate
objects - Construct an empty
KeyStore
object - Add the loaded certificates as trusted entries
- Pass that to
SSLContextBuilder.loadTrustMaterial
Link: https://discuss.elastic.co/t/es-7-4-1-authentication-rest-api/211969