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

Add CustomHeaderMatcher to pass additional headers #5563

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
"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 @@
"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 @@
FromHTTPVal = "true"
)

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

type PreRedirectHookError struct {
Message string
Code int
Expand Down Expand Up @@ -533,3 +538,18 @@
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
Loading