diff --git a/changes/14115-fix-panic-in-grpc-launcher b/changes/14115-fix-panic-in-grpc-launcher new file mode 100644 index 0000000000..5c15d58d87 --- /dev/null +++ b/changes/14115-fix-panic-in-grpc-launcher @@ -0,0 +1 @@ +* Fixed panic in gRPC launcher API handler. diff --git a/cmd/fleet/serve.go b/cmd/fleet/serve.go index 76a7f3a1e5..046cde30a8 100644 --- a/cmd/fleet/serve.go +++ b/cmd/fleet/serve.go @@ -86,6 +86,7 @@ import ( kitlog "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/google/uuid" + grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/recovery" "github.com/ngrok/sqlmw" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" @@ -1375,7 +1376,14 @@ the way that the Fleet server works. } // Instantiate a gRPC service to handle launcher requests. - launcher := launcher.New(svc, logger, grpc.NewServer(), healthCheckers) + launcher := launcher.New(svc, logger, grpc.NewServer( + grpc.ChainUnaryInterceptor( + grpc_recovery.UnaryServerInterceptor(), + ), + grpc.ChainStreamInterceptor( + grpc_recovery.StreamServerInterceptor(), + ), + ), healthCheckers) rootMux := http.NewServeMux() rootMux.Handle("/healthz", service.PrometheusMetricsHandler("healthz", otelmw.WrapHandler(health.Handler(httpLogger, healthCheckers), "/healthz", config))) diff --git a/go.mod b/go.mod index 54ebe5b5d8..9c6a53ce96 100644 --- a/go.mod +++ b/go.mod @@ -83,6 +83,7 @@ require ( github.com/gosuri/uilive v0.0.4 github.com/groob/finalizer v0.0.0-20170707115354-4c2ed49aabda github.com/groob/plist v0.0.0-20220217120414-63fa881b19a5 + github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.3 github.com/hashicorp/go-multierror v1.1.1 github.com/hectane/go-acl v0.0.0-20190604041725-da78bae5fc95 github.com/hillu/go-ntdll v0.0.0-20220801201350-0d23f057ef1f diff --git a/go.sum b/go.sum index 0c33c6c7bd..0ca6a05c50 100644 --- a/go.sum +++ b/go.sum @@ -507,6 +507,8 @@ github.com/groob/finalizer v0.0.0-20170707115354-4c2ed49aabda h1:5ikpG9mYCMFiZX0 github.com/groob/finalizer v0.0.0-20170707115354-4c2ed49aabda/go.mod h1:MyndkAZd5rUMdNogn35MWXBX1UiBigrU8eTj8DoAC2c= github.com/groob/plist v0.0.0-20220217120414-63fa881b19a5 h1:saaSiB25B1wgaxrshQhurfPKUGJ4It3OxNJUy0rdOjU= github.com/groob/plist v0.0.0-20220217120414-63fa881b19a5/go.mod h1:itkABA+w2cw7x5nYUS/pLRef6ludkZKOigbROmCTaFw= +github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.3 h1:B+8ClL/kCQkRiU82d9xajRPKYMrB7E0MbtzWVi1K4ns= +github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.3/go.mod h1:NbCUVmiS4foBGBHOYlCT25+YmGpJ32dZPi75pGEUpj4= github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 h1:NmZ1PKzSTQbuGHw9DGPFomqkkLWMC+vZCkfs+FHv1Vg= github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3/go.mod h1:zQrxl1YP88HQlA6i9c63DSVPFklWpGX4OWAc9bFuaH4= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= diff --git a/server/launcher/launcher.go b/server/launcher/launcher.go index a8f0afecff..13a8a11859 100644 --- a/server/launcher/launcher.go +++ b/server/launcher/launcher.go @@ -110,9 +110,11 @@ func (svc *launcherWrapper) PublishLogs(ctx context.Context, nodeKey string, log err = svc.tls.SubmitResultLogs(newCtx, results) return "", "", false, ctxerr.Wrap(ctx, err, "submit result logs from launcher") default: - // We have a logTypeAgent which is not there in the osquery-go enum. - // See https://github.com/kolide/launcher/issues/183 - panic(fmt.Sprintf("%s log type not implemented", logType)) + return "", "", false, ctxerr.Wrap(ctx, + &fleet.BadRequestError{Message: fmt.Sprintf("log type %q not implemented", logType)}, + "unsupported log type", + ) + } } diff --git a/server/launcher/server.go b/server/launcher/server.go index fb54360dcf..80c86f5c15 100644 --- a/server/launcher/server.go +++ b/server/launcher/server.go @@ -44,12 +44,12 @@ func New( // Handler will route gRPC traffic to the gRPC server, other http traffic // will be routed to normal http handler functions. -func (hgprc *Handler) Handler(next http.Handler) http.Handler { +func (hgrpc *Handler) Handler(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.ProtoMajor == 2 && strings.Contains(r.Header.Get("Content-Type"), "application/grpc") { ctx := r.Context() ctx = kithttp.PopulateRequestContext(ctx, r) - hgprc.ServeHTTP(w, r.WithContext(ctx)) + hgrpc.ServeHTTP(w, r.WithContext(ctx)) } else { next.ServeHTTP(w, r) }