1

Currently, I am running elasticsearch 5.2.0 in my digital ocean server.To remotely access the rest apis of elasticsearch, I made following change in config/elasticsearch.yml file:

network.host: 0.0.0.0

With this change, I am able to access the elasticsearch apis from anywhere using request:

http://server_url:9200/......

But, I want to access the elasticsearch apis only from local and selected devices/computers.

for eg: to access only from localhost(within server) and computerA, I have tried configuring as:

network.host: [_computerAIp_,_local_]

But its not working. How do I configure to achieve this requirement?

oblivion
  • 5,928
  • 3
  • 34
  • 55

2 Answers2

2

elasticsearch network.host settings in elasticsearch.yml is to set bind address for incoming http traffic and node to node communication.

From the look of your bit of code it seems you are misinterpreting it with ip address of the clients for ip filtering.

Here in elasticsearch.yml configuration you can do the following -

1) change http traffic port (default is 9200) for incoming http traffic using http.port: 9200.

2) change tcp port for transport clients for node to node communication using transport.tcp.port: 9300.

3) you can change elasticsearch bind address for elasticsearch server where to listen for traffic using network.bind_host: 192.168.0.1. You can change this to 'network.bind_host: localhost' to restrict public access.

More more detailed info on configuration please refer this and official documentation.

Now to achieve what you are trying i suggest you to use shield plugin which now comes free with X-Pack. Shield offers IP filtering support where you can define IP address who can access your elasticsearch.

Shield plugin will allow you to block, allow ip addresses for accessing your elasticsearch server by extending the same elasticsearch.yml file. After successfully installing shield plugin you will be able to use shield module in elasticsearch.yml file.

shield.transport.filter.enabled: false
shield.http.filter.enabled: true
shield.transport.filter.allow: [ "192.168.0.1", "192.168.0.2", "192.168.0.3", "192.168.0.4" ]
shield.transport.filter.deny: _all

Now these settings in elasticsearch.yml will be hard settings and after every change you may have to restart your server. Since you mentioned selected devices and computers and if the IP address for those devices changes dynamically. Then elastic also expose setting/configuring/changing IP address for IP filtering over their REST api as follows where you can change IP addresses on the fly without any restart

curl -XPUT localhost:9200/_cluster/settings -d '{
    "persistent" : {
        "shield.transport.filter.allow" : "172.16.0.0/24"
    }
}'

curl -XPUT localhost:9200/_cluster/settings -d '{
    "persistent" : {
        "shield.transport.filter.enabled" : false
    }
}'

This nice REST api for dynamically changing IP address for elastic along with other features of shield like authentication, authorization, document level roles can help you build a really fancy console interface/application for managing your elasticsearch cluster.

Please also refer the elasticsearch shield ip filtering documentation for more configuration info.

Hope this helps.

user3775217
  • 4,675
  • 1
  • 22
  • 33
  • So, for configuration `network.bind_host: 192.168.0.1`, it means that then any computers on the same subnet (anything that starts with 192.168.0) will be able to connect. That means if `computerA` is in the same subnet, it will be able to connect right ? And will shield help me(computerA) to connect to the elastic server if it is in `completely different network` ?(outside 192.168.0.1) I am still confused about the right usage of `network.bind_host: 192.168.0.1` – oblivion Feb 03 '17 at 10:37
  • well i doubt that. here is a good post explaining the difference between bind_host and publish_host for elasticsearch. http://stackoverflow.com/questions/24063644/whats-the-difference-between-bind-host-and-publish-host-in-elasticsearch. Beside that i don't have much knowledge on networking domain. – user3775217 Feb 03 '17 at 11:29
  • publish_host means: "Call me on this number", bind_host means: "I'll answer on this number" – user3775217 Feb 03 '17 at 11:32
1

No, you couldn't do that from the Elasticsearch configuration. One possible way is to use some HTTP server, which will provide firewall functionality, e.g. Apache HTTPD or Nginx.

Why you coudln't user network.bind_host

This specifies which network interface(s) a node should bind to in order to listen for incoming requests. A node can bind to multiple interfaces, e.g. two network cards, or a site-local address and a local address.

It means, that if you deploy your ES on some server, you could, for example, bind it to the localhost, or to 89.2.34.3 (just an example). In first case, it will be reachable only from localmachine, second one could allow to reach it from the internet. But it will not help you to create set of rules which machines/devices could reach it and which couldn't.

Mysterion
  • 9,050
  • 3
  • 30
  • 52
  • In the elastic search documentation for` network.bind_host` here: https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html#advanced-network-settings . It explains : `This specifies which network interface(s) a node should bind to in order to listen for incoming requests` . So, why can't I configure that the elastic search listens/binds to selected devices only ?In my question, the device would be `computerA`. Please help me understand this. – oblivion Feb 03 '17 at 10:53
  • 1
    @oblivion, i updated the answer with answer to your question in comments as well – Mysterion Feb 03 '17 at 10:58
  • thank you for the updated answer. So, `network.bind_host` basically defines the address `where` the ES is listening and not `whom` it listens to right ? And lets say the `Ip address` of server (where ES is deployed) is `101.104.154.163`. In this scenario, what are the addresses that I can use for `network.bind_host` to make ES accessible to the internet? I know `0.0.0.0` and `101.104.154.163` works. Can I use some other addresses here ? – oblivion Feb 03 '17 at 11:14