Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KIALI-2505 Fix error when fetching Grafana info with oauth #902

Merged
merged 1 commit into from Mar 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 13 additions & 6 deletions handlers/grafana.go
Expand Up @@ -20,18 +20,25 @@ import (
type serviceSupplier func(string, string, string) (*v1.ServiceSpec, error)
type dashboardSupplier func(string, string, string) ([]byte, int, error)

// The Kiali ServiceAccount token.
var saToken string

// GetGrafanaInfo provides the Grafana URL and other info, first by checking if a config exists
// then (if not) by inspecting the Kubernetes Grafana service in namespace istio-system
func GetGrafanaInfo(w http.ResponseWriter, r *http.Request) {

token, err := getToken(r)
if err != nil {
log.Error(err)
RespondWithError(w, http.StatusInternalServerError, err.Error())
return
// Be careful with how you use this token. This is the Kiali Service Account token, not the user token.
// We need the Service Account token to get the Grafana service in order to generate the Grafana dashboard links.
if saToken == "" {
token, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/token")
if err != nil {
RespondWithError(w, http.StatusInternalServerError, err.Error())
return
}
saToken = string(token)
}

info, code, err := getGrafanaInfo(token, getService, findDashboard)
info, code, err := getGrafanaInfo(saToken, getService, findDashboard)
if err != nil {
log.Error(err)
RespondWithError(w, code, err.Error())
Expand Down