Skip to content

Commit

Permalink
Add CustomHeaderMatcher to pass additional headers (flyteorg#5563)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Dye <[email protected]>
Signed-off-by: Vladyslav Libov <[email protected]>
  • Loading branch information
andrewwdye authored and VladyslavLibov committed Aug 16, 2024
1 parent 2bdbcd0 commit a3ca782
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
20 changes: 20 additions & 0 deletions flyteadmin/auth/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (
"encoding/json"
"fmt"
"net/http"
"net/textproto"
"net/url"
"strings"
"time"

"github.com/grpc-ecosystem/go-grpc-middleware/util/metautils"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"golang.org/x/oauth2"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand All @@ -22,6 +24,7 @@ import (
"github.com/flyteorg/flyte/flyteadmin/pkg/common"
"github.com/flyteorg/flyte/flyteadmin/plugins"
"github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/service"
"github.com/flyteorg/flyte/flytestdlib/contextutils"
"github.com/flyteorg/flyte/flytestdlib/errors"
"github.com/flyteorg/flyte/flytestdlib/logger"
)
Expand All @@ -32,6 +35,8 @@ const (
FromHTTPVal = "true"
)

var XRequestID = textproto.CanonicalMIMEHeaderKey(contextutils.RequestIDKey.String())

type PreRedirectHookError struct {
Message string
Code int
Expand Down Expand Up @@ -533,3 +538,18 @@ func GetUserInfoForwardResponseHandler() UserInfoForwardResponseHandler {
return nil
}
}

func GetCustomHeaderMatcher(pluginRegistry *plugins.Registry) runtime.HeaderMatcherFunc {
if fn := plugins.Get[runtime.HeaderMatcherFunc](pluginRegistry, plugins.PluginIDCustomerHeaderMatcher); fn != nil {
return fn
}
return func(key string) (string, bool) {
canonicalKey := textproto.CanonicalMIMEHeaderKey(key)
switch canonicalKey {
case XRequestID:
return canonicalKey, true
default:
return runtime.DefaultHeaderMatcher(key)
}
}
}
3 changes: 3 additions & 0 deletions flyteadmin/pkg/server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ func newHTTPServer(ctx context.Context, pluginRegistry *plugins.Registry, cfg *c
// This option sets subject in the user info response
gwmuxOptions = append(gwmuxOptions, runtime.WithForwardResponseOption(auth.GetUserInfoForwardResponseHandler()))

// Use custom header matcher to allow additional headers to be passed through
gwmuxOptions = append(gwmuxOptions, runtime.WithIncomingHeaderMatcher(auth.GetCustomHeaderMatcher(pluginRegistry)))

if cfg.Security.UseAuth {
// Add HTTP handlers for OIDC endpoints
auth.RegisterHandlers(ctx, mux, authCtx, pluginRegistry)
Expand Down
9 changes: 5 additions & 4 deletions flyteadmin/plugins/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import (
type PluginID = string

const (
PluginIDWorkflowExecutor PluginID = "WorkflowExecutor"
PluginIDAdditionalGRPCService PluginID = "AdditionalGRPCService"
PluginIDCustomerHeaderMatcher PluginID = "CustomerHeaderMatcher"
PluginIDDataProxy PluginID = "DataProxy"
PluginIDUnaryServiceMiddleware PluginID = "UnaryServiceMiddleware"
PluginIDPreRedirectHook PluginID = "PreRedirectHook"
PluginIDLogoutHook PluginID = "LogoutHook"
PluginIDAdditionalGRPCService PluginID = "AdditionalGRPCService"
PluginIDPreRedirectHook PluginID = "PreRedirectHook"
PluginIDUnaryServiceMiddleware PluginID = "UnaryServiceMiddleware"
PluginIDWorkflowExecutor PluginID = "WorkflowExecutor"
)

type AtomicRegistry struct {
Expand Down

0 comments on commit a3ca782

Please sign in to comment.