I guess that you got this post a thousand times but I could not find my exact issue on the forum. I apologize if it is a duplicate.
Trying to set up Xpack on ES 6.2.1, I did the following
1) On master node
cd /usr/software/elasticsearch
bin/elasticsearch-plugin install x-pack
mkdir config/cert
bin/x-pack/certutil ca
mv elastic-stack-ca.p12 config/cert/
bin/x-pack/certutil cert --ca conf/cert/elastic-stack-ca.p12
mv elastic-certificates.p12 config/cert/
restartelasticsearch.sh
2) On all other nodes
cd /usr/software/elasticsearch
bin/elasticsearch-plugin install x-pack
mkdir config/cert
scp master:/usr/software/elasticsearch/config/cert/elastic-stack-ca.p12 config/cert/.
bin/x-pack/certutil cert --ca conf/cert/elastic-stack-ca.p12
mv elastic-certificates.p12 config/cert/
restartelasticsearch.sh
3) On master node
bin/x-pack/setup-passwords interactive
4) On kibana
cd /usr/software/kibana
bin/kibana-plugin install x-pack
vi config/kibana.yml
added:
elasticsearch.username: "kibana"
elasticsearch.password: "XXXXXX"
restartkibana.sh
5) On master node
cd /usr/software/elasticsearch
bin/x-pack/users useradd mysuperuser -p XXXXXXX -r superuser
As you can see, it is pretty straightforward with the documentation examples.
At this stage, everything is working fine. All nodes are connected, Kibana can connect.
Trying to add the java client in the dance:
6) On kibana, connected as super user
Created user myjavauser with transport_client role
7) On Java
Modified the client to be the Xpack client
Performed the maven dependencies fetch.
Configured login, password and paths to certificates
Here is my code
ses.log(null, "DEBUG", "QESHost_elastic", "connect()", 3, "Connection avec Xpack");
ses.log(null, "DEBUG", "QESHost_elastic", "connect()", 3, "Login", login);
ses.log(null, "DEBUG", "QESHost_elastic", "connect()", 3, "Path certificat", pathCertificate);
ses.log(null, "DEBUG", "QESHost_elastic", "connect()", 3, "Path authorities", pathAuthorities);
Settings settings = null;
if (!pathCertificate.isEmpty()) {
ses.log(null, "DEBUG", "QESHost_elastic", "connect()", 3, "Avec certificats");
settings = Settings.builder()
.put("cluster.name", cluster)
.put("xpack.security.user", login + ":" + password)
.put("xpack.ssl.certificate", pathCertificate)
.put("xpack.ssl.certificate_authorities", pathAuthorities)
.put("xpack.security.transport.ssl.enabled", "true")
.put("xpack.security.transport.ssl.verification_mode", "certificate")
.build();
client = new PreBuiltXPackTransportClient(settings).addTransportAddress(new
TransportAddress(InetAddress.getByName(host), port));
}
Here is the run:
2018/02/28 10:35:48 568-myapp-null-TRACE-QESHost_elastic-sessionClient() : Nouvelle connexion ...:localhost:9300|
2018/02/28 10:35:48 568-myapp-null-DEBUG-QESHost_elastic-connect() : cluster:elasticsearch|
2018/02/28 10:35:48 568-myapp-null-DEBUG-QESHost_elastic-connect() : host:localhost|
2018/02/28 10:35:48 568-myapp-null-DEBUG-QESHost_elastic-connect() : port:9300|
2018/02/28 10:35:48 568-myapp-null-DEBUG-QESHost_elastic-connect() : Connection avec Xpack|
2018/02/28 10:35:48 568-myapp-null-DEBUG-QESHost_elastic-connect() : Login:myjavauser|
2018/02/28 10:35:48 568-myapp-null-DEBUG-QESHost_elastic-connect() : Path certificat:/usr/software/elasticsearch/config/cert/elastic-certificates.p12|
2018/02/28 10:35:48 568-myapp-null-DEBUG-QESHost_elastic-connect() : Path authorities:/usr/software/elasticsearch/config/cert/elastic-certificates.p12|
2018/02/28 10:35:48 568-myapp-null-DEBUG-QESHost_elastic-connect() : Avec certificats|
2018/02/28 10:35:49 686-myapp-null-ERROR-QESHost_elastic-connect() : Erreur de connexion:ElasticsearchException[failed to initialize a TrustManagerFactory]; nested: MalformedInputException[Input length = 1];|
java.lang.RuntimeException: ElasticsearchException[failed to initialize a TrustManagerFactory]; nested: MalformedInputException[Input length = 1];
at org.elasticsearch.xpack.core.XPackClientPlugin.getTransports(XPackClientPlugin.java:385)
at org.elasticsearch.common.network.NetworkModule.<init>(NetworkModule.java:126)
at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:177)
at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:273)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:128)
at org.elasticsearch.xpack.client.PreBuiltXPackTransportClient.<init>(PreBuiltXPackTransportClient.java:59)
...
at com.qwam.qesutil.qeselasticindex.main(qeselasticindex.java:610)
Caused by: ElasticsearchException[failed to initialize a TrustManagerFactory]; nested: MalformedInputException[Input length = 1];
at org.elasticsearch.xpack.core.ssl.PEMTrustConfig.createTrustManager(PEMTrustConfig.java:60)
at org.elasticsearch.xpack.core.ssl.SSLService.createSslContext(SSLService.java:412)
at org.elasticsearch.xpack.core.ssl.SSLService.loadSSLConfigurations(SSLService.java:448)
at org.elasticsearch.xpack.core.ssl.SSLService.<init>(SSLService.java:91)
at org.elasticsearch.xpack.core.XPackClientPlugin.getTransports(XPackClientPlugin.java:383)
... 12 more
Caused by: java.nio.charset.MalformedInputException: Input length = 1
at java.nio.charset.CoderResult.throwException(CoderResult.java:281)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:339)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.read1(BufferedReader.java:210)
at java.io.BufferedReader.read(BufferedReader.java:286)
at java.io.BufferedReader.fill(BufferedReader.java:161)
at java.io.BufferedReader.readLine(BufferedReader.java:324)
at java.io.BufferedReader.readLine(BufferedReader.java:389)
at org.bouncycastle.util.io.pem.PemReader.readPemObject(Unknown Source)
at org.bouncycastle.openssl.PEMParser.readObject(Unknown Source)
at org.elasticsearch.xpack.core.ssl.CertUtils.readCertificates(CertUtils.java:328)
at org.elasticsearch.xpack.core.ssl.CertUtils.readCertificates(CertUtils.java:315)
at org.elasticsearch.xpack.core.ssl.CertUtils.readCertificates(CertUtils.java:307)
at org.elasticsearch.xpack.core.ssl.PEMTrustConfig.createTrustManager(PEMTrustConfig.java:57)
... 16 more
I cannot find the reason of this exception:
Caused by: java.nio.charset.MalformedInputException: Input length = 1
I am missing something there for sure.
Can You help me ?