How disable remote access in elasticsearch - elasticsearch

When running a elasticsearch server.
We can access www.example.com:9200
But i want block remote access only allow local access.
How to setting?

Instead of disabling whole HTTP protocol by changing http.enabled in /etc/elasticsearch/elasticsearch.yml settings (because some of your APIs can use the HTTP endpoint which was my case), you can just set network.host: localhost in the same file.
This will make your :9200 HTTP access to be available only from your local machine/server.

Elasticsearch allows you to disable the http endpoint just setting http.enabled to false in the settings. It also allows to have a local node which will only be reachable in the same jvm. On the other hand you are asking how to allow only local access to the rest endpoint, which is different and require the use of additional tools.
In fact, it's not a good idea to expose elasticsearch to the internet. I would use a proxy like apache or Nginx to limit the access to it and open for instance only some of the available endpoints, but that's needed only if you have external users that want to send messages directly to elasticsearch. Usually that's not the case. Or if you just want to deny access to it for all external users, because it's for instance only your website or application that needs access to it, just use a firewall and setup a proper rule to close the 9200 port.

You should set http.host to "127.0.0.1". This way you can access http on port 9200 from host itself, however not from outside. This also allows you to put a proxy which listens on some other port and filters and passes the requests selectively to elasticsearch node on localhost:9200.
For example, you may want to reject the request for shutdown, do a basic authentication using nginx and then pass all query requests to elasticsearch cluster url at http://localhost:9200.
This doesn't involve firewall.

Related

Elasticsearch - Collecting logs from devices not on server LAN

I am trying to build familiarity with SIEM systems in general and decided to set up an Elastic Stack via Digital Ocean. Everything was successful and my server as localhost is producing logs. It's been interesting to tinker with visualizations and that good stuff.
Obviously my interest isn't in logs from this remote server, though. I would like to configure some devices on my home network to send logs.
Current setup on server: filebeat > logstash > elasticsearch > kibana.
When I install filebeat onto, say, my laptop and configure the .yml file in a similar way to the server (comment out elastic output, uncomment logstash output) it is not able to connect. Basically I just set the hosts to serverip:logstash port and enabled filebeat on the system. Running the setup commands leads to a "couldn't connect to any configured elasticsearch hosts".
Instead of a direct answer, can someone explain for me generally what I need to be considering for this process? What is happening when connecting outside of the server LAN? and how do I handle authentication to the server, if needed?
Thank you, really. I know that the information is out there but I am deep in a rabbit hole and having a hard time finding what I need.
By default, the HTTP API is bound to only the host's local loopback interface,
ensuring that it is not accessible to the rest of the network. Because the API
includes neither authentication nor authorization and has not been hardened or
tested for use as a publicly-reachable API, binding to publicly accessible IPs
should be avoided where possible.
Even you set "http.host: 0.0.0.0" - you need to open port for your laptop (better if you already have public IP and open it only for your laptop)
For authentication - you have to investigate xpack - security features .
BR Alexey.

How to expose my Elastic Search server to the internet?

I've done installed my ElasticSearch (ES) Server on a VPS Centos. I did test the ES inside the Server and it response correctly.
My next step, is to allow my website which is host on a different web host to access and index its data content into my ES server.
My question is, what is the recommended way of exposed the ES to the internet, so my website can access to it to perform index and search? Is there's authentication method that I need to install ?
You need to include network.host:0.0.0.0 in your elasticsearch.yml file so that it listens on the non-loopback address and after that, if your app-server and ES are both in the same VPC, app-server will be able to connect to ES(provided if you exposed 9200 port in security group(in case of AWS).
And hopefully, your app-server port is exposed to the internet which internally connects to ES, you should not expose 9200 port of ES or Elasticsearch to the internet.
If you want an extra layer of security, you can enable x-pack basic which is included in the free tier and can be enabled using xpack.security.enabled: true in elasticsearch.config.
Refer x-pack features and configuration for more info.

Cannot access data source of elasticsearch using grafana cloud

I'm using grafana cloud for creating visualization but when i'm trying to load the data source with elasticsearch i'm getting 502 error.
502 usually means bad gateway (there is no connection) and that IP address looks like an internal IP address. GrafanaCloud is a cloud service so it does not have access to internal IP addresses.
Your options are:
Install Grafana locally if you do not want to open up anything over the internet.
Use direct mode instead of proxy mode. This means that requests will go directly from your browser to the elasticsearch server and not go through the Grafana backend server. However, GrafanaCloud is on https so you will get a mixed content warning and you would need to solve that by having a proxy in front of your elasticsearch server (or by setting up https for your server).
Make your server accessible over the internet. Setup a static IP address for your elasticsearch server, setup firewall rules etc. so that GrafanaCloud can query your server.
Add the following configurations in config/elasticsearch.yml:
transport.host: localhost
transport.tcp.port: 9300
http.port: 9200
network.host: 0.0.0.0

Elasticsearch Access Log

I'm trying to track down who is issuing queries to an ElasticSearch Cluster. Elastic doesn't appear to have an access log.
Is there a place where I can find out which IP is hitting the cluster?
Elasticsearch doesn't provide any security out of the box, and that is on purpose and by design.
So you have a couple solutions out there:
Don't let your ES cluster exposed to the open world, but put it behind a firewall (i.e. whitelist the hosts that can access ports 9200/9300 on your nodes)
Look into the Shield plugin for Elasticsearch in order to secure your environment.
Put an nginx server in front of your cluster to act as a reverse proxy.
Add simple basic authentication with either the elasticsearch-jetty plugin or simply the elasticsearch-http-basic plugin, which also allowws you to whitelist the client IPs that are allowed to access your cluster.
If you want to have access logs, you need either 2 or 3, but all solutions above will allow you to secure your ES environment.

How to disable elasticsearch http module?

The default value of "http.enabled" option in elasticsearch's configuration file is true which means that we can search and admin the cluster from http command, for example:DELETE /index_* request can delete all indexes. But this is not safe when deployment the service to the production environment. How can I fix this problem?
You can either implement shield - this is free if you are paying for one of the Elasticsearch support packages.
Or implement a reverse proxy which checks each request and the user running the request, for example nginx.

Resources