Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore(grpc-gateway): use incoming header matcher (#18632)
p0ny3021ca2f3a1f
diff --git a/backend/api/auth/auth.go b/backend/api/auth/auth.goindex 27f726a30a..1c534c3c17 100644--- a/backend/api/auth/auth.go+++ b/backend/api/auth/auth.go@@ -277,7 +277,7 @@ func GetTokenFromHeaders(headers http.Header) (string, error) {// Check HTTP cookiesvar accessToken string- for _, cookieHeader := range append(headers.Values("cookie"), headers.Values("grpcgateway-cookie")...) {+ for _, cookieHeader := range headers.Values("cookie") {header := http.Header{}header.Add("Cookie", cookieHeader)request := http.Request{Header: header}diff --git a/backend/api/v1/auth_service.go b/backend/api/v1/auth_service.goindex c2fe04a431..e5ab434c9b 100644--- a/backend/api/v1/auth_service.go+++ b/backend/api/v1/auth_service.go@@ -204,10 +204,6 @@ func (s *AuthService) Login(ctx context.Context, req *connect.Request[v1pb.Login}origin := req.Header().Get("Origin")- if origin == "" {- origin = req.Header().Get("grpcgateway-origin")- }-cookie := auth.GetTokenCookie(ctx, s.store, s.licenseService, origin, response.Token)resp.Header().Add("Set-Cookie", cookie.String())}@@ -279,9 +275,6 @@ func (s *AuthService) Logout(ctx context.Context, req *connect.Request[v1pb.Logoresp := connect.NewResponse(&emptypb.Empty{})origin := req.Header().Get("Origin")- if origin == "" {- origin = req.Header().Get("grpcgateway-origin")- }cookie := auth.GetTokenCookie(ctx, s.store, s.licenseService, origin, "")resp.Header().Add("Set-Cookie", cookie.String())return resp, nildiff --git a/backend/server/grpc_routes.go b/backend/server/grpc_routes.goindex 66cec62186..7de5fa3a90 100644--- a/backend/server/grpc_routes.go+++ b/backend/server/grpc_routes.go@@ -5,6 +5,7 @@ import ("fmt""log/slog""net/http"+ "strings""google.golang.org/grpc""google.golang.org/grpc/credentials/insecure"@@ -59,12 +60,23 @@ func configureGrpcRouters(//nolint:forbidigoUnmarshalOptions: protojson.UnmarshalOptions{},}),+ // pass through request headers that need to be used by connect rpc handlers.+ grpcruntime.WithIncomingHeaderMatcher(func(key string) (string, bool) {+ switch strings.ToLower(key) {+ // grpc-gateway hard codes authorization pass-through already, we do it again anyways.+ // https://github.com/grpc-ecosystem/grpc-gateway/blob/2cca0efe61de30f05068b9e3b4eb4801b1b2c1aa/runtime/context.go#L160+ case "authorization", "cookie", "origin":+ return key, true+ default:+ return "", false+ }+ }),grpcruntime.WithOutgoingHeaderMatcher(func(key string) (string, bool) {- switch key {+ switch strings.ToLower(key) {case "set-cookie":return key, truedefault:- return grpcruntime.DefaultHeaderMatcher(key)+ return "", false}}),grpcruntime.WithRoutingErrorHandler(func(ctx context.Context, sm *grpcruntime.ServeMux, m grpcruntime.Marshaler, w http.ResponseWriter, r *http.Request, httpStatus int) {