為ElasticSearch添加HTTP基本認證

284681032 8年前發布 | 31K 次閱讀 ElasticSearch 搜索引擎

來自: http://blog.csdn.net//jiao_fuyou/article/details/48337997


ES的HTTP連接沒有提供任何的權限控制措施,一旦部署在公共網絡就容易有數據泄露的風險,尤其是加上類似elasticsearch-head這樣友好的前端界面,簡直讓你的數據瞬間裸奔在黑客的眼皮底下。項目上線前做十萬伏特的防護當然不現實,但至少,我們不要裸奔,穿一套比基尼吧。而做一個簡單的HTTP認證并不需要從頭造輪子,elasticsearch-http-basic就提供了針對ES HTTP連接的IP白名單、密碼權限和信任代理功能。

安裝

elasticsearch-http-basic還不支持ES標準的bin/plugin install [github-name]/[repo-name]的安裝方式,但作者有提供編譯好的jar包,不需要下載源碼重新編譯。GitHub上目前的最新版本是對應ES的1.4.0版本,但驗證過1.5.2也是同樣可用的。

插件的安裝步驟如下:

  • elasticsearch-http-basic的發布版下載對應版本的jar包
  • mkdir -p plugins/http-basic; mv elasticsearch-http-basic-x.x.x.jar plugins/http-basic注意文件夾的名稱
  • 重啟ES進程
  • 驗證插件是否生效:curl localhost:9200/_nodes/[your-node-name]/plugins?pretty=true(如果看到plugins列表包含有http-basic-server-plugin就說明插件生效了)

配置

elasticsearch-http-basic和其他ES插件一樣,在config/elasticsearch.yml中統一配置:

http.basic.enabled: true
http.basic.log: false                  
http.basic.user: "loguser"          
http.basic.password: "logpwd"  
http.basic.ipwhitelist: ["172.16.18.171","172.16.18.114"]   
http.basic.xforward: "X-Forwarded-For"
http.basic.trusted_proxy_chains: ["172.16.18.114"]

<th style="padding:5px 8px;border:1px solid #e6e6e6;word-break:normal;background:#f3f3f3;"> 默認值</th>

<th style="padding:5px 8px;border:1px solid #e6e6e6;word-break:normal;background:#f3f3f3;"> 說明</th>

</tr>

</thead>

<td style="padding:5px 8px;border:1px solid #e6e6e6;word-break:normal;"> true</td>

<td style="padding:5px 8px;border:1px solid #e6e6e6;word-break:normal;"> 開關,開啟會接管全部HTTP連接</td>

</tr>

</tbody>

</table> </div>

測試

配置名
http.basic.enabled
http.basic.user "loguser" 賬號
http.basic.password "logpwd" 密碼
http.basic.ipwhitelist ["172.16.18.171","172.16.18.114"] 白名單內的ip訪問不需要通過賬號和密碼,支持ip和主機名,不支持ip區間或正則
http.basic.trusted_proxy_chains ["172.16.18.114"] 信任代理列表
http.basic.log false 把無授權的訪問事件添加到ES的日志
http.basic.xforward "X-Forwarded-For" 記載代理路徑的header字段名
  • sesese色