ES用戶權限控制


  1、創建索引:
創建兩個索引 “a”和“b”(使用super用戶):
索引A:curl -XPUT -u userName:password http://localhost:9200/indexa
索引B:curl -XPUT -u userName:password http://localhost:9200/indexb

2、創建角色:

創建兩個角色testRoleA和testRoleB,並將索引 indexa 的權限給testRoleA,indexb的權限給testRoleB
備注:
備注:如果是只讀角色"privileges":["all"]改成"privileges":["read"]

testRoleA:

curl -XPOST -u userName:password 'localhost:9200/_xpack/security/role/testRoleA' -H "Content-Type: application/json" -d '{"cluster":["monitor"],"indices":[{"names":["indexa"],"privileges":["all"]}]}'

testUserB:

curl -XPOST -u userName:password 'localhost:9200/_xpack/security/role/testRoleB' -H "Content-Type: application/json" -d '{"cluster":["monitor"],"indices":[{"names":["indexb"],"privileges":["all"]}]}'

3、創建用戶:

創建兩個用戶testUserA,並指定testRoleA(其中password和roles是必填字段):
testUserA:
curl -XPOST -u userName:password 'localhost:9200/_xpack/security/user/testUserA' -H "Content-Type: application/json" -d '{
  "password" : "123123",
  "full_name" : "testUserA",
  "email" : "test@test.com",
  "roles" : [ "testRoleA" ],
  "metadata" : {
    "intelligence" : 7
  }
}'
 
testUserB:
curl -XPOST -u userName:password 'localhost:9200/_xpack/security/user/testUserB' -H "Content-Type: application/json" -d '{
  "password" : "123123",
  "full_name" : "testUserB",
  "email" : "test@test.com",
  "roles" : [ "testRoleB" ],
  "metadata" : {
    "intelligence" : 7
  }
}'

4、測試:

嘗試使用testUserA去刪除索引indexb,嘗試使用testUserB去刪除索引indexa:
curl -XDELETE -u testUserA:123123 http://localhost:9200/indexb
curl -XDELETE -u testUserB:123123 http://localhost:9200/indexa

 

如果刪除失敗,出現這樣的提示:“xxx is unauthorized for user xxx” ,那么恭喜你,你的es集群權限控制成功啦~~

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM