mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 03:12:38 +08:00
Plugins: Forward user header (X-Grafana-User) in backend plugin requests (#58646)
Grafana would forward the X-Grafana-User header to backend plugin request when dataproxy.send_user_header is enabled. In addition, X-Grafana-User will be automatically forwarded in outgoing HTTP requests for core/builtin HTTP datasources. Use grafana-plugin-sdk-go v0.147.0. Fixes #47734 Co-authored-by: Will Browne <wbrowne@users.noreply.github.com>
This commit is contained in:

committed by
GitHub

parent
ecf83a6df9
commit
6478d0a5ef
@ -4,8 +4,13 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"sort"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
)
|
||||
|
||||
// UserHeaderName name of the header used when forwarding the Grafana user login.
|
||||
const UserHeaderName = "X-Grafana-User"
|
||||
|
||||
// PrepareProxyRequest prepares a request for being proxied.
|
||||
// Removes X-Forwarded-Host, X-Forwarded-Port, X-Forwarded-Proto, Origin, Referer headers.
|
||||
// Set X-Grafana-Referer based on contents of Referer.
|
||||
@ -69,3 +74,11 @@ func ClearCookieHeader(req *http.Request, keepCookiesNames []string, skipCookies
|
||||
func SetProxyResponseHeaders(header http.Header) {
|
||||
header.Set("Content-Security-Policy", "sandbox")
|
||||
}
|
||||
|
||||
// ApplyUserHeader Set the X-Grafana-User header if needed (and remove if not).
|
||||
func ApplyUserHeader(sendUserHeader bool, req *http.Request, user *user.SignedInUser) {
|
||||
req.Header.Del(UserHeaderName)
|
||||
if sendUserHeader && user != nil && !user.IsAnonymous {
|
||||
req.Header.Set(UserHeaderName, user.Login)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user