From 5f8a680ce4c64cb949847ef6189dbe85a3c5471c Mon Sep 17 00:00:00 2001 From: Khurram Baig Date: Mon, 9 Dec 2024 18:41:32 +0530 Subject: [PATCH] Fix the Unauthorized for the Rest API This correctly sets the auth header to the incoming context. --- pkg/api/server/v1alpha2/plugin/plugin_logs.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/api/server/v1alpha2/plugin/plugin_logs.go b/pkg/api/server/v1alpha2/plugin/plugin_logs.go index fe7db0f4f..88f8342c4 100644 --- a/pkg/api/server/v1alpha2/plugin/plugin_logs.go +++ b/pkg/api/server/v1alpha2/plugin/plugin_logs.go @@ -331,7 +331,7 @@ func getBlobLogs(s *LogServer, writer io.Writer, parent string, rec *db.Record) iter := bucket.List(&blob.ListOptions{ Prefix: strings.TrimPrefix(s.config.LOGS_PATH+fmt.Sprintf(defaultBlobPathParams, parent, rec.ResultName, rec.Name), "/"), }) - s.logger.Debugf("prefix: %s", strings.TrimPrefix(s.config.LOGS_PATH+"/"+fmt.Sprintf(defaultBlobPathParams, parent, rec.ResultName, rec.Name)+"/", "/")) + s.logger.Debugf("prefix: %s", strings.TrimPrefix(s.config.LOGS_PATH+fmt.Sprintf(defaultBlobPathParams, parent, rec.ResultName, rec.Name), "/")) for { obj, err := iter.Next(ctx) if err == io.EOF { @@ -407,7 +407,8 @@ func (s *LogServer) LogMux() http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // TODO: Create a new log handler ctx := r.Context() - ctx = metadata.AppendToOutgoingContext(ctx, "authorization", r.Header.Get("Authorization")) + md := metadata.New(map[string]string{"authorization": r.Header.Get("Authorization")}) + ctx = metadata.NewIncomingContext(ctx, md) parent := r.PathValue("parent") if err := s.auth.Check(ctx, parent, auth.ResourceLogs, auth.PermissionGet); err != nil { s.logger.Error(err)