Elasticsearch 許可權控制
隨著ES的廣泛使用,其安全問題也備受關注,雖然ES叢集一般部署於公司內網,但多個業務部門使用同一套ES叢集的情況非常多,如何做好資料共享、訪問隔離,防止使用者誤操作、資料洩露等,這需要一套良好的許可權控制機制。
1.方案調研
目前官方的安全模組Shield需要收費,所以普及率並不高,下面調研了以下幾種方案:
1)elasticsearch-http-basic
https://github.com/Asquera/elasticsearch-http-basic
支援版本:目前最高支援elasticsearch.1.7.0
特點:部署簡單,實現了賬號認證和IP白名單認證功能,功能單一。
2)kibana-authentication-proxy
https://github.com/fangli/kibana-authentication-proxy
支援版本:Kibana 3 ,程式碼最後一次更新是2年前。
特點:針對kibana實現的認證,支援Google OAuth2,Basic Authentication, CAS Auth。
3)Shield
https://www.elastic.co/downloads/shield
支援版本:支援到Elaticsearch 2.x
特點:功能豐富,文件齊全,30天試用;
4)search-guard
https://github.com/floragunncom/search-guard
2.編譯打包
mvn package -DskipTests
如果報以下錯誤:
[ERROR][com.floragunn.searchguard.SearchGuardPlugin] Class enhancements for DLS/FLS not successful due to javassist.CannotCompileException: [source error] no such field: context
修改SearchGuardPlugin類原始碼,並重新編譯:
//me.insertAt(559, "if(callback != null) {callback.onCreateContext(context, request);}");
me.insertAt(574, "if(callback != null) {callback.onCreateContext(context, request);}");
pom檔案:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
拷貝jar包到elastic search/plusgin/search-guard,注意目錄target/releases/:
target/releases/search-guard-0.6-SNAPSHOT.jar
否則報錯:
Caused by: java.lang.ClassNotFoundException: javassist.ClassPool
[2015-11-19 18:37:24,287][INFO ][watcher.trigger.schedule ] [idc] using [ticker] schedule trigger engine
{1.7.1}: Initialization Failed ...
- NoClassDefFoundError[waffle/windows/auth/IWindowsAuthProvider]
3.手動安裝
../bin/plugin -u file:./search-guard-0.6-SNAPSHOT.jar -i search-guard
日誌:
-> Installing search-guard...
Trying file:./search-guard-0.6-SNAPSHOT-jar-with-dependencies.jar...
Downloading.........................................................................
DONE
Installed search-guard into /usr/local/webserver/elasticsearch/plugins/search-guard
4.許可權測試
{
"error": "ClassCastException[com.petalmd.armor.http.netty.SessionAwareNettyHttpChannel cannot be cast to org.elasticsearch.http.HttpChannel]",
"status": 500
}
許可權修改
curl -XPUT 'http://***.***.***.***:9200/armor/ac/ac' -d '{
"acl": [
{
"__Comment__": "By default no filters are executed and no filters a by-passed. In such a case an exception is thrown and access will be denied.",
"hosts": ["*"], "indices": ["*"],
"filters_bypass": [],
"filters_execute": ["actionrequestfilter.readonly"]
},
{
"__Comment__": "For role *root* all filters are bypassed (so none will be executed). This means unrestricted access.",
"hosts": ["*"],
"roles": [
"root"
],"indices": ["*"],
"filters_bypass": ["*"],
"filters_execute": []
}
]
}’
armor 索引只允許在部署elasticsearch的機器上訪問,否則會報錯:
[2015-11-30 15:49:39,610][ERROR][com.petalmd.armor.filter.ArmorActionFilter] Forbidden while apply() due to com.petalmd.armor.authorization.ForbiddenException: Only allowed from localhost (loopback) for action indices:data/read/search
com.petalmd.armor.authorization.ForbiddenException: Only allowed from localhost (loopback)
user1使用者只有只讀許可權,在head介面建立索引時,會報如下錯:
[2015-11-30 15:25:21,565][ERROR][com.petalmd.armor.filter.ArmorActionFilter] Forbidden while apply() due to com.petalmd.armor.authorization.ForbiddenException: Action 'indices:admin/create' is forbidden due to DEFAULT for action indices:admin/create
com.petalmd.armor.authorization.ForbiddenException: Action 'indices:admin/create' is forbidden due to DEFAULT
通過admin使用者則成功建立test-log索引。
在新增許可權後,往測試索引中新增資料無響應:
curl -XPOST 'http://***.***.***.***:9200/test-log/order' -d '{"date":"2015-11-20 15:39:00","customerID":"user1”}’,
需要加上具有寫許可權的使用者名稱/密碼:
curl -v --user admin:admin -XPOST 'http://***.***.***.***:9200/test-log/order' -d '{"date":"2015-11-20 15:39:00","customerID":"user1”}’
* Hostname was NOT found in DNS cache
* Trying 10.1.***.***...
* Connected to 10.1.***.*** (10.1.***.***) port 9200 (#0)
* Server auth using Basic with user 'admin'
> POST /test-log/order HTTP/1.1
> Authorization: Basic YWRtaW46YWRtaW4=
> User-Agent: curl/7.37.1
> Host: 10.1.***.***:9200
> Accept: */*
> Content-Length: 51
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 51 out of 51 bytes
< HTTP/1.1 201 Created
< Content-Type: application/json; charset=UTF-8
< Content-Length: 94
<
* Connection #0 to host 10.1.***.*** left intact
返回結果:
{"_index":"test-log","_type":"order","_id":"AVFXVBQXMJgnGjM0BUcq","_version":1,"created":true}
此時在head介面,就能看到剛插入的資料了:
如果user1使用者試圖刪除它沒許可權的索引:
curl -v --user user1:123 -XDELETE http://10.1.***.***:9200/armor
將返回:
{"error":"ForbiddenException[Only allowed from localhost (loopback)]","status":403}
相關文章
- 使用nginx控制ElasticSearch訪問許可權NginxElasticsearch訪問許可權
- elasticsearch7.8許可權控制和規劃Elasticsearch
- 許可權控制
- shiro許可權控制
- 如何用 Vue 實現前端許可權控制(路由許可權 + 檢視許可權 + 請求許可權)Vue前端路由
- Linux的許可權控制Linux
- Laravel實現許可權控制Laravel
- 許可權維持專題:域控制器許可權維持
- Java 訪問許可權控制(6)Java訪問許可權
- vue-router控制路由許可權Vue路由
- 許可權控制及AOP日誌
- springboot-許可權控制shiro(二)Spring Boot
- etcd套路(四)auth許可權控制
- 資料分析的許可權控制
- Spring MVC 整合 Shiro 許可權控制SpringMVC
- k8s結合jumpserver做kubectl許可權控制 使用者在多個namespaces的訪問許可權 rbac許可權控制K8SServernamespace訪問許可權
- MYSQL學習筆記13: DCL許可權控制(使用者許可權操作)MySql筆記
- 一對一原始碼,前端頁面許可權和按鈕許可權控制原始碼前端
- 小知識:軟體開發的許可權控制和許可權驗證
- Spring Boot 之 RESRful API 許可權控制Spring BootAPI
- React基於RBAC的許可權控制React
- SAP Business Application Studio的許可權控制APP
- 打造自己的系統許可權控制
- casbin基於golang的許可權控制Golang
- Atlas 2.1.0 實踐(4)—— 許可權控制
- 許可權之選單許可權
- linux 檔案許可權 s 許可權和 t 許可權解析Linux
- 玩轉 K8s 許可權控制:RBAC + kubeconfig 搞定 kubectl 許可權管理那些事K8S
- Nestjs RBAC 許可權控制管理實踐(一)JS
- Linux 許可權控制的基本原理Linux
- 005.OpenShift訪問控制-許可權-角色
- SpringBoot--- SpringSecurity進行登出,許可權控制Spring BootGse
- Nestjs RBAC 許可權控制管理實踐 (二)JS
- 淺談 Orbeon form builder 的許可權控制ORBORMUI
- 填報表上下載檔案控制元件可寫許可權控制控制元件
- 許可權系統:一文搞懂功能許可權、資料許可權
- 前端如何配合後端完成RBAC許可權控制前端後端
- SpringBoot(一) 如何實現AOP的許可權控制Spring Boot
- 前端真的能做到徹底許可權控制嗎?前端