Skip to content

Commit

Permalink
fix: add authorization from cookie to metadata
Browse files Browse the repository at this point in the history
Signed-off-by: mikutas <[email protected]>
  • Loading branch information
mikutas committed Sep 23, 2022
1 parent e6eb02f commit 0da92df
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions server/apiserver/argoserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,13 @@ func (as *argoServer) newHTTPServer(ctx context.Context, port int, artifactServe
mux.Handle("/oauth2/callback", handlers.ProxyHeaders(http.HandlerFunc(as.oAuth2Service.HandleCallback)))
mux.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) {
if os.Getenv("ARGO_SERVER_METRICS_AUTH") != "false" {
header := metadata.New(map[string]string{"authorization": r.Header.Get("Authorization")})
ctx := metadata.NewIncomingContext(context.Background(), header)
md := metadata.New(map[string]string{"authorization": r.Header.Get("Authorization")})
for _, c := range r.Cookies() {
if c.Name == "authorization" {
md.Append("cookie", c.Value)
}
}
ctx := metadata.NewIncomingContext(context.Background(), md)
if _, err := as.gatekeeper.Context(ctx); err != nil {
log.WithError(err).Error("failed to authenticate /metrics endpoint")
w.WriteHeader(403)
Expand Down

0 comments on commit 0da92df

Please sign in to comment.