Hi
I was able to install search guard and run elastic search succesfully by following the steps mentioned in https://github.com/floragunncom/search-guard
I am running the below versions
Elastic Search 5.5.0
Spring-data-elasticsearch 3.0.0.RC2
Search Guard 5.5.0-15
Using the below code I was able to successfully connect to Elastic Search and insert records into elastic search
`Settings esSettings = Settings.builder()
.put("path.home", ".")
.put("[cluster.name](http://cluster.name/)", "searchguard_demo")
.put("searchguard.ssl.transport.enabled", true)
.put("searchguard.ssl.transport.keystore_filepath", "/Users/temp/Desktop/applications/mycert/kirk.jks")
.put("searchguard.ssl.transport.truststore_filepath", "/Users/temp/Desktop/applications/mycert/truststore.jks")
.put("searchguard.ssl.transport.enforce_hostname_verification", false)
.put("searchguard.ssl.transport.resolve_hostname", false)
.put(SSLConfigConstants.SEARCHGUARD_SSL_TRANSPORT_KEYSTORE_PASSWORD, "changeit")
.put(SSLConfigConstants.SEARCHGUARD_SSL_TRANSPORT_TRUSTSTORE_PASSWORD, "changeit")
.putArray("searchguard.authcz.admin_dn", "CN=kirk,OU=client,O=client,l=Est,C=De")
.build();
TransportClient client = new PreBuiltTransportClient(esSettings,SearchGuardPlugin.class);
try {
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(“127.0.0.1”), Integer.valueOf(“9300”)));
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
`
Now , I am trying to create certificates using the TLS generator provided by Search Guard.
https://floragunn.com/tls-certificate-generator/
I got two client certificates : sgadmin and demouser apart from the node cerificate CN=127.0.0.1-keystore.jks
After generating the certificates , the copied the below files to searchgaurd/config/generate-certificates folder
CN=demouser-keystore.jks
CN=sgadmin-keystore.jks
truststore.jks
I am trying to use the CN=demouser-keystore.jks to connect to Elastic Search
Below is my configuration in elasticsearch.yml
`
######## Start Search Guard Demo Configuration ########
searchguard.ssl.transport.keystore_filepath: generated-certificates/CN=demouser-keystore.jks
searchguard.ssl.transport.keystore_password: afd02cecb11578f80c78
searchguard.ssl.transport.truststore_filepath: generated-certificates/truststore.jks
searchguard.ssl.transport.truststore_password: 8533bf07a673a9af95b9
searchguard.ssl.transport.enforce_hostname_verification: false
searchguard.ssl.http.enabled: true
searchguard.ssl.http.keystore_filepath: generated-certificates/CN=demouser-keystore.jks
searchguard.ssl.http.keystore_password: afd02cecb11578f80c78
searchguard.ssl.http.truststore_filepath: generated-certificates/truststore.jks
searchguard.ssl.http.truststore_password: 8533bf07a673a9af95b9
searchguard.authcz.admin_dn:
- CN=sgadmin
- CN=demouser
cluster.name: searchguard_demo
network.host: 0.0.0.0
######## End Search Guard Demo Configuration ########
`
When I start elastic search , I get the following error. I have only one node in my cluster .
I have still not run sgadmin.sh . Am I doing any mistake here ? Should I add the node certificate also to elasticsearch.yml file ?
Caused by: org.elasticsearch.transport.RemoteTransportException: [TR6U48o][127.0.0.1:9300][internal:transport/handshake]
Caused by: org.elasticsearch.ElasticsearchException: bad header found. This means typically that one node try to connect to another with a non-node certificate (no OID or searchguard.nodes_dn incorrect configured) or that someoneis spoofing requests. See https://github.com/floragunncom/search-guard-docs/blob/master/tls_node_certificates.md
at com.floragunn.searchguard.ssl.util.ExceptionUtils.createBadHeaderException(ExceptionUtils.java:56) ~[?:?]
at com.floragunn.searchguard.transport.SearchGuardRequestHandler.messageReceivedDecorate(SearchGuardRequestHandler.java:159) ~[?:?]
at com.floragunn.searchguard.ssl.transport.SearchGuardSSLRequestHandler.messageReceived(SearchGuardSSLRequestHandler.java:140) ~[?:?]
at com.floragunn.searchguard.SearchGuardPlugin$3$1.messageReceived(SearchGuardPlugin.java:376) ~[?:?]
at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.transport.TcpTransport$RequestHandler.doRun(TcpTransport.java:1544) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.common.util.concurrent.EsExecutors$1.execute(EsExecutors.java:110) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.transport.TcpTransport.handleRequest(TcpTransport.java:1501) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.transport.TcpTransport.messageReceived(TcpTransport.java:1385) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.transport.netty4.Netty4MessageChannelHandler.channelRead(Netty4MessageChannelHandler.java:74) ~[?:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[?:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[?:?]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) ~[?:?]
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310) ~[?:?]
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:297) ~[?:?]
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:413) ~[?:?]
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:265) ~[?:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[?:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[?:?]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) ~[?:?]
at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) ~[?:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[?:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[?:?]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) ~[?:?]
at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1267) ~[?:?]
at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1078) ~[?:?]
at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:489) ~[?:?]
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:428) ~[?:?]
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:265) ~[?:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[?:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[?:?]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) ~[?:?]
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334) ~[?:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[?:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[?:?]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926) ~[?:?]
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:134) ~[?:?]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:644) ~[?:?]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:544) ~[?:?]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:498) ~[?:?]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458) ~[?:?]
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) ~[?:?]
… 1 more
I was able to run the below command successfully
./sgadmin.sh -ks /Users/myname/Desktop/applications/elasticsearch-5.5.0-demouser/config/generated-certificates/CN=demouser-keystore.jks -kspass afd02cecb11578f80c78 -ts /Users/myname/Desktop/applications/elasticsearch-5.5.0-demouser/config/generated-certificates/truststore.jks -tspass 8533bf07a673a9af95b9 -cd …/sgconfig -icl -nhnv
I was also able to insert records into elastic search finally …
`
Settings esSettings = Settings.builder()
.put("path.home", ".")
.put("[cluster.name](http://cluster.name/)", "searchguard_demo")
.put("searchguard.ssl.transport.enabled", true)
.put("searchguard.ssl.transport.keystore_filepath", "/Users/myname/Desktop/applications/elasticsearch-5.5.0-demouser/config/generated-certificates/CN=demouser-keystore.jks")
.put("searchguard.ssl.transport.truststore_filepath", "/Users/myname/Desktop/applications/elasticsearch-5.5.0-demouser/config/generated-certificates/truststore.jks")
.put("searchguard.ssl.transport.enforce_hostname_verification", false)
.put("searchguard.ssl.transport.resolve_hostname", false)
//.put("[request.headers.sg.impersonate.as](http://request.headers.sg.impersonate.as/)", "admin")
.put(SSLConfigConstants.SEARCHGUARD_SSL_TRANSPORT_KEYSTORE_PASSWORD, "afd02cecb11578f80c78")
.put(SSLConfigConstants.SEARCHGUARD_SSL_TRANSPORT_TRUSTSTORE_PASSWORD, "8533bf07a673a9af95b9")
.putArray("searchguard.authcz.admin_dn", "CN=demouser")
.build();
TransportClient client = new PreBuiltTransportClient(esSettings,SearchGuardPlugin.class);
try {
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(“127.0.0.1”), Integer.valueOf(“9300”)));
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
`
I still get this error in elastic search server logs though I was able to insert and select data from elastic search .
I could not find out what I had missed. Kindly revert if you find any issue in my configurations
Caused by: org.elasticsearch.transport.RemoteTransportException: [TR6U48o][[::1]:9300][internal:transport/handshake]
Caused by: org.elasticsearch.ElasticsearchException: bad header found. This means typically that one node try to connect to another with a non-node certificate (no OID or searchguard.nodes_dn incorrect configured) or that someoneis spoofing requests. See https://github.com/floragunncom/search-guard-docs/blob/master/tls_node_certificates.md
at com.floragunn.searchguard.ssl.util.ExceptionUtils.createBadHeaderException(ExceptionUtils.java:56) ~[?:?]
at com.floragunn.searchguard.transport.SearchGuardRequestHandler.messageReceivedDecorate(SearchGuardRequestHandler.java:159) ~[?:?]
at com.floragunn.searchguard.ssl.transport.SearchGuardSSLRequestHandler.messageReceived(SearchGuardSSLRequestHandler.java:140) ~[?:?]
at com.floragunn.searchguard.SearchGuardPlugin$3$1.messageReceived(SearchGuardPlugin.java:376) ~[?:?]
at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.transport.TcpTransport$RequestHandler.doRun(TcpTransport.java:1544) ~[elasticsearch-5.5.0.jar:5.5.0]
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-5.5.0.jar:5.5.0]
``