Commit 839eb970 by bergquist

Merge branch 'feature/dataProxyAuditLog' of https://github.com/Ricky-N/grafana…

Merge branch 'feature/dataProxyAuditLog' of https://github.com/Ricky-N/grafana into Ricky-N-feature/dataProxyAuditLog
parents ee1c15b9 0b48e48e
...@@ -47,6 +47,9 @@ root_url = %(protocol)s://%(domain)s:%(http_port)s/ ...@@ -47,6 +47,9 @@ root_url = %(protocol)s://%(domain)s:%(http_port)s/
# Log web requests # Log web requests
router_logging = false router_logging = false
# This enables data proxy logging, default is false
data_proxy_logging = false
# the path relative working path # the path relative working path
static_root_path = public static_root_path = public
......
...@@ -49,6 +49,9 @@ ...@@ -49,6 +49,9 @@
# Log web requests # Log web requests
;router_logging = false ;router_logging = false
# This enables query request audit logging, output at warn level, default is false
;data_proxy_logging = false
# the path relative working path # the path relative working path
;static_root_path = public ;static_root_path = public
......
...@@ -143,6 +143,7 @@ with Grafana admin permission. ...@@ -143,6 +143,7 @@ with Grafana admin permission.
"protocol":"http", "protocol":"http",
"root_url":"%(protocol)s://%(domain)s:%(http_port)s/", "root_url":"%(protocol)s://%(domain)s:%(http_port)s/",
"router_logging":"true", "router_logging":"true",
"data_proxy_logging":"true",
"static_root_path":"public" "static_root_path":"public"
}, },
"session":{ "session":{
......
package api package api
import ( import (
"bytes"
"io/ioutil"
"net/http" "net/http"
"net/http/httputil" "net/http/httputil"
"net/url" "net/url"
...@@ -8,6 +10,7 @@ import ( ...@@ -8,6 +10,7 @@ import (
"github.com/grafana/grafana/pkg/api/cloudwatch" "github.com/grafana/grafana/pkg/api/cloudwatch"
"github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/metrics" "github.com/grafana/grafana/pkg/metrics"
"github.com/grafana/grafana/pkg/middleware" "github.com/grafana/grafana/pkg/middleware"
m "github.com/grafana/grafana/pkg/models" m "github.com/grafana/grafana/pkg/models"
...@@ -121,6 +124,24 @@ func ProxyDataSourceRequest(c *middleware.Context) { ...@@ -121,6 +124,24 @@ func ProxyDataSourceRequest(c *middleware.Context) {
c.JsonApiErr(400, "Unable to load TLS certificate", err) c.JsonApiErr(400, "Unable to load TLS certificate", err)
return return
} }
proxyLog(ds.Type, c)
proxy.ServeHTTP(c.Resp, c.Req.Request) proxy.ServeHTTP(c.Resp, c.Req.Request)
c.Resp.Header().Del("Set-Cookie") c.Resp.Header().Del("Set-Cookie")
} }
func proxyLog(dataSourceType string, c *middleware.Context) {
if setting.DataProxyLogging {
auditLogger := log.New("data-proxy-log", "userid", c.UserId, "orgid", c.OrgId, "username", c.Login)
var body string
if c.Req.Request.Body != nil {
buffer, _ := ioutil.ReadAll(c.Req.Request.Body)
c.Req.Request.Body = ioutil.NopCloser(bytes.NewBuffer(buffer))
body = string(buffer)
}
auditLogger.Info("Proxying incoming request", "datasource", dataSourceType, "uri", c.Req.RequestURI, "method", c.Req.Request.Method, "body", body)
}
}
...@@ -66,6 +66,7 @@ var ( ...@@ -66,6 +66,7 @@ var (
SshPort int SshPort int
CertFile, KeyFile string CertFile, KeyFile string
RouterLogging bool RouterLogging bool
DataProxyLogging bool
StaticRootPath string StaticRootPath string
EnableGzip bool EnableGzip bool
EnforceDomain bool EnforceDomain bool
...@@ -491,6 +492,7 @@ func NewConfigContext(args *CommandLineArgs) error { ...@@ -491,6 +492,7 @@ func NewConfigContext(args *CommandLineArgs) error {
HttpAddr = server.Key("http_addr").MustString(DEFAULT_HTTP_ADDR) HttpAddr = server.Key("http_addr").MustString(DEFAULT_HTTP_ADDR)
HttpPort = server.Key("http_port").MustString("3000") HttpPort = server.Key("http_port").MustString("3000")
RouterLogging = server.Key("router_logging").MustBool(false) RouterLogging = server.Key("router_logging").MustBool(false)
DataProxyLogging = server.Key("data_proxy_logging").MustBool(false)
EnableGzip = server.Key("enable_gzip").MustBool(false) EnableGzip = server.Key("enable_gzip").MustBool(false)
EnforceDomain = server.Key("enforce_domain").MustBool(false) EnforceDomain = server.Key("enforce_domain").MustBool(false)
StaticRootPath = makeAbsolute(server.Key("static_root_path").String(), HomePath) StaticRootPath = makeAbsolute(server.Key("static_root_path").String(), HomePath)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment