elasticsearch在暴露了一個node的ip和端口后就可以對整個集群進行各種操作,刪索引,改數據等。在重要的項目應用中,需要防范這一點。
目前常見的安全防范方式有,
- X-Pack Elasticsearch Security,收費License
- Search Guard,免費開源
一、安裝:
請打開Search Guard后,根據你的elasticsearch選擇不同的版本下載
輸入以下命令進行 安裝,請注意替換你的下載文件路徑
bin/elasticsearch-plugin install -b file:///home/vagrant/Code/search-guard-7-7.6.1-40.0.0.zip
二、配置
在安裝好的插件目錄tools中對對install_demo_configuration.sh
賦權
chmod +x tools/install_demo_configuration.sh
運行該插件:
./tools/install_demo_configuration.sh
安裝成功后會在elasticsearch 中的config/elasticsearch.yml中寫入search-guard的內容
再次在瀏覽器中輸入瀏覽地址,會提示你登陸
用戶及密碼信息設置:
1)生成hash密碼:
./tools/hash.sh -p abc321
-p 后面的參數據即abc321就為密碼,生成后留下密碼備用
2)新建用戶:打開 sgconfig/sg_internal_users.yml 文件
該配置文件默認用戶相關信息請點擊:https://docs.search-guard.com/latest/demo-users-roles
vim ../sgconfig/sg_internal_users.yml
3)增加用戶myself
編輯 sg_internal_users.yml
vim ../sgconfig/sg_internal_users.yml
在文件中加入以下內容
myself: /*用戶名*/ hash: "$2y$12$GfJVId7fgMFkCZDtIA/boe5iL.AIsGK50SHvgEZ5fV1Oa38KrKwhu" /*上一步生成的hash密碼*/ reserved: true /**/ backend_roles: /*由授權后端(如LDAP,JWT或內部用戶數據庫)獲取的角色*/ - "admin"
4) 分發到集群,使配置生效
cd ./plugins/search-guard-6/tools ./sgadmin.sh -cd ../sgconfig/ -icl -nhnv \ -cacert ../../../config/root-ca.pem \ -cert ../../../config/kirk.pem \ -key ../../../config/kirk-key.pem