diff --git a/changes/8161-fix-kubequery-rows-check b/changes/8161-fix-kubequery-rows-check new file mode 100644 index 000000000..a613f6bb9 --- /dev/null +++ b/changes/8161-fix-kubequery-rows-check @@ -0,0 +1 @@ +- Fixed panic in `ingestKubequeryInfo` query ingestion. diff --git a/server/service/osquery_utils/queries.go b/server/service/osquery_utils/queries.go index 166bec7e1..155fae598 100644 --- a/server/service/osquery_utils/queries.go +++ b/server/service/osquery_utils/queries.go @@ -1201,8 +1201,7 @@ func directIngestMunkiInfo(ctx context.Context, logger log.Logger, host *fleet.H func ingestKubequeryInfo(ctx context.Context, logger log.Logger, host *fleet.Host, rows []map[string]string) error { if len(rows) != 1 { - logger.Log("component", "service", "method", "ingestKubequeryInfo", "warn", - fmt.Sprintf("kubernetes_info expected single result got %d", len(rows))) + return fmt.Errorf("kubernetes_info expected single result got: %d", len(rows)) } host.Hostname = fmt.Sprintf("kubequery %s", rows[0]["cluster_name"]) diff --git a/server/service/osquery_utils/queries_test.go b/server/service/osquery_utils/queries_test.go index 990548224..eb18d70bd 100644 --- a/server/service/osquery_utils/queries_test.go +++ b/server/service/osquery_utils/queries_test.go @@ -813,3 +813,16 @@ func TestDirectIngestWindowsUpdateHistory(t *testing.T) { require.NoError(t, err) require.True(t, ds.InsertWindowsUpdatesFuncInvoked) } + +func TestIngestKubequeryInfo(t *testing.T) { + err := ingestKubequeryInfo(context.Background(), log.NewNopLogger(), &fleet.Host{}, nil) + require.Error(t, err) + err = ingestKubequeryInfo(context.Background(), log.NewNopLogger(), &fleet.Host{}, []map[string]string{}) + require.Error(t, err) + err = ingestKubequeryInfo(context.Background(), log.NewNopLogger(), &fleet.Host{}, []map[string]string{ + { + "cluster_name": "foo", + }, + }) + require.NoError(t, err) +}