瀏覽代碼

Secure Elasticsearch datasources a bit (#6031)

Instead of allowing users to access the
entire cluster, apply some sane restrictions.

Change-Id: Ib2e93722bf2e39d700d4afa713ff49ec556f2fdf
wvl 9 年之前
父節點
當前提交
a73424d6af
共有 1 個文件被更改,包括 16 次插入0 次删除
  1. 16 0
      pkg/api/dataproxy.go

+ 16 - 0
pkg/api/dataproxy.go

@@ -104,6 +104,22 @@ func ProxyDataSourceRequest(c *middleware.Context) {
 	}
 
 	proxyPath := c.Params("*")
+
+	if ds.Type == m.DS_ES {
+		if c.Req.Request.Method == "DELETE" {
+			c.JsonApiErr(403, "Deletes not allowed on proxied Elasticsearch datasource", nil)
+			return
+		}
+		if c.Req.Request.Method == "PUT" {
+			c.JsonApiErr(403, "Puts not allowed on proxied Elasticsearch datasource", nil)
+			return
+		}
+		if c.Req.Request.Method == "POST" && proxyPath != "_msearch" {
+			c.JsonApiErr(403, "Posts not allowed on proxied Elasticsearch datasource except on /_msearch", nil)
+			return
+		}
+	}
+
 	proxy := NewReverseProxy(ds, proxyPath, targetUrl)
 	proxy.Transport = dataProxyTransport
 	proxy.ServeHTTP(c.Resp, c.Req.Request)