ElasticSearch本身没有权限管理模块,只要获取服务器的地址和端口,任何人都可以随意读写ElasticSearch的API并获取数据,这样非常不安全。如果获取了ES的访问IP和端口,一条命令就可以删除整个索引库。好在Elastic公司开发了安全插件shield来解决权限管理问题. https://www.elastic.co/products/shield
一、shield安装
- 1
- 2
- 1
- 2
第二步:重启Elasticsearch
- 1
- 1
第三步:添加管理员
- 1
- 1
adminName是可以自定义的,执行该命令以后会提示输入密码,再次输入密码进行确认,之后管理员用户就添加成功了。
再访问ES服务器中的数据就需要密码验证了.在终端中执行之前的命令试一下:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
报安全异常,这时候需要把-u 管理员名称加到命令中,截图方便理解:
加入权限以后,在终端中每次执行操作都需要加参数并输入正确的密码。
在浏览器中访问ES同样需要验证:
二、Java Api中使用shield
加入权限管理以后在Java Api中需要做修改:
第一步:加入jar包
直接导入
到elasticsearch-2.3.3/plugins/shield目录下拷贝shield-2.3.3.jar,加到CLASSPATH中.
或者maven导入
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
第二步:修改setting:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
第三步:修改client
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
三、shield 用户管理
3.1 新增用户
- 1
- 1
回车后输入两次密码确认
Enter new password:
Retype new password:
3.2 查看用户
- 1
- 1
会列出当前所有的user和角色:
- 1
- 2
- 1
- 2
3.3 修改密码
给用户名为bropen的管理员修改密码:
- 1
- 1
回车后输入两次密码确认
- 1
- 2
- 3
- 1
- 2
- 3
3.4 删除用户
./elasticsearch-2.3.3/bin/shield/esusers userdel bropen
查看所有可用命令:
- 1
- 1
如果在head中出现cluster health: not connected的情况,如下图:
可以查看当前用户是不是管理员角色:
- 1
- 1
给名为bropen的管理员添加角色:
- 1
- 1
官网关于Shield的Java api说明:
https://www.elastic.co/guide/en/shield/current/_using_elasticsearch_java_clients_with_shield.html
Shield参考手册
https://www.elastic.co/guide/en/shield/current/index.html
2016年9月23日更新:
在stackoverflow上问的大神说Shield插件是收费软件,免费试用1一个月,需要购买license才能继续使用。后来发现shield插件简单的接口可以一直使用,高级功能需要付费后使用。
转载地址:
http://blog.csdn.net/napoay/article/details/52201558