Skip to content

Commit

Permalink
Merge branch 'mnacharov:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mnacharov authored May 15, 2024
2 parents ea1cae8 + 353b47c commit 0c5bc11
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Requirements:
- Grafana OSS server
- Google OAuth2 Provider configured
- Grafana Server Administrator credentials
- "Forward OAuth Identity" enabled in datasource settings (.jsonData.oauthPassThru == true)

Environment variables:
- `GRAFANA_BASE_URL` - grafana oss server base url (like https://grafana.example.com or https://infra.example.com/grafana)
Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ type ForbidViewerProxy struct {
func (m ForbidViewerProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
token := r.Header.Get("X-ID-Token")
if token == "" {
log.Println("token not found")
m.proxy.ServeHTTP(w, r)
http.Error(w, "403 - JWT Token not found", http.StatusForbidden)
} else {
email, err := GetEmailFromGoogleJWT(token)
if err != nil {
log.Printf("Error getting email from Google JWT: %s\n", err)
http.Error(w, "500 - Error getting email from Google JWT!", http.StatusInternalServerError)
http.Error(w, "403 - Wrong JWT Token", http.StatusForbidden)
} else {
orgID := r.Header.Get("X-Grafana-Org-ID")
if isViewer(email, orgID) {
Expand All @@ -33,6 +32,7 @@ func (m ForbidViewerProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
}

func NewForbidViewerProxy() ForbidViewerProxy {
target, err := url.Parse(os.Getenv("PROXY_ORIGIN_SERVER"))
if err != nil {
Expand All @@ -50,6 +50,7 @@ func NewForbidViewerProxy() ForbidViewerProxy {
}
return ForbidViewerProxy{*proxy}
}

func main() {
log.Fatal(http.ListenAndServe(":8989", NewForbidViewerProxy()))
}

0 comments on commit 0c5bc11

Please sign in to comment.