将一堆json数据上传到elasticsearch服务器以获得基本查询api非常容易,有很多选项
我只是想知道是否有简单的方法将其发布,以防止人们修改它
从默认设置,服务器打开或接收将修改数据的DELETE或PUT http消息.
是否有某种设置将其配置为只读?或者我应该配置某种http代理来实现它?
(我是一个有弹性的新手)
kar*_*rmi 20
如果您想将Elasticsearch API公开为只读,我认为最好的方法是将Nginx放在它前面,并拒绝除GET之外的所有请求.示例配置如下所示:
# Run me with:
#
# $ nginx -c path/to/this/file
#
# All requests except GET are denied.
worker_processes 1;
pid nginx.pid;
events {
worker_connections 1024;
}
http {
server {
listen 8080;
server_name search.example.com;
error_log elasticsearch-errors.log;
access_log elasticsearch.log;
location / {
if ($request_method !~ "GET") {
return 403;
break;
}
proxy_pass http://localhost:9200;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后:
curl -i -X GET http://localhost:8080/_search -d '{"query":{"match_all":{}}}'
HTTP/1.1 200 OK
curl -i -X POST http://localhost:8080/test/test/1 -d '{"foo":"bar"}'
HTTP/1.1 403 Forbidden
curl -i -X DELETE http://localhost:8080/test/
HTTP/1.1 403 Forbidden
Run Code Online (Sandbox Code Playgroud)
请注意,恶意用户仍然可能弄乱您的服务器,例如发送不正确的脚本有效负载,这会使Elasticsearch卡住,但在大多数情况下,这种方法会没问题.
如果您需要更多关于代理的控制,您可以使用更复杂的Nginx配置,或者编写专用代理,例如.在Ruby或Node.js.
有关更复杂的基于Ruby的代理,请参阅此示例.
您可以在索引上设置只读标志,但这确实限制了某些操作,因此您需要查看是否可接受.
curl -XPUT http://<ip-address>:9200/<index name>/_settings -d'
{
"index":{
"blocks":{
"read_only":true
}
}
}'
Run Code Online (Sandbox Code Playgroud)
正如其他一个答案中所提到的,实际上你应该让ES在受信任的环境中运行,在那里你可以控制对它的访问.
在这里索引设置更多信息:http://www.elasticsearch.org/guide/reference/api/admin-indices-update-settings/
我知道这是一个古老的话题.我遇到了同样的问题,把ES放在Nginx后面,以使它只读,但允许kibana访问它.
在我的案例中,Kibana唯一需要ES的请求是"url_public/_all/_search".
所以我允许它进入我的Nginx conf.
这是我的conf文件:
server {
listen port_es;
server_name ip_es;
rewrite ^/(.*) /$1 break;
proxy_ignore_client_abort on;
proxy_redirect url_es url_public;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
location ~ ^/(_all/_search) {
limit_except GET POST OPTIONS {
deny all;
}
proxy_pass url_es;
}
location / {
limit_except GET {
deny all;
}
proxy_pass url_es;
}
}
Run Code Online (Sandbox Code Playgroud)
因此,除非请求是_all/_search,否则只允许GET请求.如果需要,添加其他请求很简单.
我使用这个elasticsearch插件:
https://github.com/sscarduzio/elasticsearch-readonlyrest-plugin
它非常简单,易于安装和配置.GitHub项目页面有一个配置示例,显示如何仅限制对HTTP GET方法的请求; 这不会改变elasticsearch中的任何数据.如果您只需要列入白名单的IP#(或无)使用可以更改数据的其他方法(PUT/DELETE/etc),那么它也可以覆盖您.
这样的东西会进入你的elasticsearch配置文件(/etc/elasticsearch/elasticsearch.yml或等价物),改编自GitHub页面:
readonlyrest:
enable: true
response_if_req_forbidden: Sorry, your request is forbidden
# Default policy is to forbid everything, let's define a whitelist
access_control_rules:
# from these IP addresses, accept any method, any URI, any HTTP body
#- name: full access to internal servers
# type: allow
# hosts: [127.0.0.1, 10.0.0.10]
# From external hosts, accept only GET and OPTION methods only if the HTTP request body is empty
- name: restricted access to all other hosts
type: allow
methods: [OPTIONS,GET]
maxBodyLength: 0
Run Code Online (Sandbox Code Playgroud)
Elasticsearch旨在用于受信任的环境,并且本身没有任何访问控制机制.因此,部署elasticsearch的最佳方法是在其前面安装一个Web服务器,负责控制可以访问elasticsearch的查询的访问和类型.这样说,可以通过使用elasticsearch-jetty插件限制对elasticsearch的访问.
无论是 Elastic 还是 Solr,依靠搜索引擎来保证安全都不是一个好主意。您应该在容器中使用安全性,或者甚至将容器置于真正防弹的东西(例如 Apache HTTPD)后面,然后设置安全性以禁止您想要禁止的事情。
归档时间: |
|
查看次数: |
14507 次 |
最近记录: |