1. 程式人生 > >elk模組x-pack簡單替代,按照索引設定不同使用者(nginx許可權控制)

elk模組x-pack簡單替代,按照索引設定不同使用者(nginx許可權控制)

按照url路徑劃分不同業務組的應用

例如nginx日誌顯示:

"POST/elasticsearch/logstash-ceshi-1*/_field_stats?level=indices HTTP/1.1" 401195 "http://192.168.6.3:9999/app/kibana" "Mozilla/5.0 (WindowsNT 6.1; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0"

"POST /elasticsearch/logstash-ceshi-2*/_field_stats?level=indicesHTTP/1.1" 200 266 "http://192.168.6.3:9999/app/kibana""Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0) Gecko/20100101Firefox/51.0"

假如:

允許wangdd,wangzz,wangxx訪問/路徑

允許wangdd訪問logstash-ceshi-1*索引

允許wangzz 訪問logstash-ceshi-2*索引

設定三個檔案分配:/使用site_pass_2認證檔案,記錄三人使用者密碼允許三人全部訪問

                  logstash-ceshi-1*使用site_pass1認證檔案,允許wangzz訪問

                  logstash-ceshi-2*使用site_pass認證檔案,允許wangdd訪問

命令:

建立檔案並新增首個使用者

 htpasswd -c /mapbar/app/nginx-1.2.2/conf/site_pass_2  wangxx

New password:
Re-type new password:
Adding password for user wangxx

追加一個使用者到檔案

htpasswd -b /mapbar/app/nginx-1.2.2/conf/site_pass_2  wangzz  password

Adding password for user wangzz
追加第二個使用者到檔案

htpasswd -b /mapbar/app/nginx-1.2.2/conf/site_pass_2  wangdd password

Adding password for user wangdd

三個檔案建立完後效果

site_pass_2訪問/路徑用的認證檔案


cat /mapbar/app/nginx-1.2.2/conf/site_pass_2

wangdd:uWfSrgP7jE3sM
wangzz:wi6auciO1xX5c
wangxx:cPmyh4wFDQ9xg
site_pass_1訪問logstash-ceshi-1*索引用的認證檔案
cat /mapbar/app/nginx-1.2.2/conf/site_pass_1

wangzz:B61OxHybX4H.A

site_pass訪問logstash-ceshi-2*索引用的認證檔案

cat /mapbar/app/nginx-1.2.2/conf/site_pass

wangdd:YDgPa.WUDLqp.

Nginx location匹配

location /

       {

            proxy_pass http://192.168.6.3:5601;

            auth_basic "userpassword";

            auth_basic_user_file /mapbar/app/nginx-1.2.2/conf/site_pass_2;

       }

       location ^~ /elasticsearch/logstash-ceshi-1*/

       {

            proxy_pass http://192.168.6.3:5601;

            auth_basic "userpassword";

            auth_basic_user_file /mapbar/app/nginx-1.2.2/conf/site_pass_1;

       }

       location ^~ /elasticsearch/logstash-ceshi-2*/

       {

            proxy_pass http://192.168.6.3:5601;

            auth_basic "userpassword";

            auth_basic_user_file /mapbar/app/nginx-1.2.2/conf/site_pass;

       }

配完成後重啟nginx

驗證:

當用wangxx訪問首頁時通過

當進入預設logstash-ceshi-1*索引,由於wangxx許可權不足需要再次認證


輸入wangzz後,許可權滿足


當進入logstash-ceshi-2*時由於wangzz許可權不足再次需要認證。

輸入相應許可權wangdd


進入logstash-ceshi-2*