ropensci / elastic

R client for the Elasticsearch HTTP API
https://docs.ropensci.org/elastic
Other
245 stars 58 forks source link

elastic appears to be using http even when https is specified #274

Closed binkleym closed 3 years ago

binkleym commented 3 years ago

I'm using Elastic 1.1.0 on Windows using R 3.6.3 to try to connect to an ES server. Here is the script I'm using:


library(elastic)

es <- connect(host = "elk1.vampire",
              port = "9200",
              errors = "complete",
              transport_scheme = "https",
              user = "elastic",
              pwd  = "not_the_real_password",
              cainfo = "ACCRE/ca.crt")

Search(es, "depot")

On the client side, I see the error:

Error in curl::curl_fetch_memory(x$url$url, handle = x$url$handle) : 
  Empty reply from server

On the server side, I see the error:

[2020-08-05T10:23:22,245][WARN ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [elk1.vampire] received plaintext http traffic on an https channel, closing connection Netty4HttpChannel{localAddress=/10.0.11.151:9200, remoteAddress=/10.0.11.40:32911}

So even though I'm specifiying "https" as the transport_scheme and giving it a valid CA crt, it seems to be trying http to connect to the ES server.

Any suggstions? Thanks.

sckott commented 3 years ago

I don't see any reason why that would occur looking at the elastic package code.

Can you turn on verbose curl output crul::set_verbose() then run it again and see if the curl output gives any useful information

binkleym commented 3 years ago

I got a little closer to figuring it out. I enabled debugging and caught the following message:

It appears that it's insufficient to specify the ca file using elastic's "connect(cainfo = "this_ca.crt"). It appears I have to add it to the OS's CA list by:

1) cd /usr/local/share/ca-certificates 2) mkdir my_folder && cd my_folder 3) cp /tmp/ca.crt . 4) sudo update-ca-certificates

Now it's going farther before erroring out. I'm still seeing "http" instead of "https" on the server side so I'm curious if it's falling back to http if it can't negotiate a successful https connection.

sckott commented 3 years ago

Yes, makes sense that curl would fall back to http if https does not work.

How does your elasticsearch instance expect the API key? As a header? Maybe the API key isn't being set right? If relevant, this package doesn't support any of the paid Elasticsearch security features as I wasn't able to get access to those to test

sckott commented 3 years ago

closing inactivity