Skip to content

Commit

Permalink
Add CustomHeaderMatcher to pass additional headers
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Dye <[email protected]>
  • Loading branch information
andrewwdye committed Jul 16, 2024
1 parent c1563d7 commit 7dd2229
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

Check warning on line 544 in flyteadmin/auth/handlers.go

View check run for this annotation

Codecov / codecov/patch

flyteadmin/auth/handlers.go#L542-L544

Added lines #L542 - L544 were not covered by tests
}
return func(key string) (string, bool) {
canonicalKey := textproto.CanonicalMIMEHeaderKey(key)
switch canonicalKey {
case XRequestID:
return canonicalKey, true
default:
return runtime.DefaultHeaderMatcher(key)

Check warning on line 552 in flyteadmin/auth/handlers.go

View check run for this annotation

Codecov / codecov/patch

flyteadmin/auth/handlers.go#L546-L552

Added lines #L546 - L552 were not covered by tests
}
}
}
3 changes: 3 additions & 0 deletions flyteadmin/pkg/server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,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 7dd2229

Please sign in to comment.