Fix panic in gRPC launcher API handler (#39409)

- [X] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.

## Testing

- [X] QA'd all new/changed functionality manually
This commit is contained in:
Lucas Manuel Rodriguez
2026-02-06 09:31:14 -03:00
committed by GitHub
parent f099db37e7
commit 7c9713d08f
6 changed files with 20 additions and 6 deletions
+1
View File
@@ -0,0 +1 @@
* Fixed panic in gRPC launcher API handler.
+9 -1
View File
@@ -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)))
+1
View File
@@ -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
+2
View File
@@ -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=
+5 -3
View File
@@ -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",
)
}
}
+2 -2
View File
@@ -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)
}