Match query reports from hosts in /api/v1/osquery/log endpoint - #50239
Match query reports from hosts in /api/v1/osquery/log endpoint#50239lucasmrod wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Warning
- Copilot's review of this pull request may be incomplete because some of the changed files are excluded by your Copilot content exclusion settings. See Excluding content from Copilot for details.
Pull request overview
This PR tightens query report ingestion from the /api/v1/osquery/log (result logs) endpoint by correlating incoming scheduled query results to the reporting host’s actual schedule, preventing hosts from persisting forged/stale results into admin-visible query reports.
Changes:
- Add
queriesScheduledForHostfiltering to only accept results for saved, scheduled queries that belong to the host’s applicable scope (global or the host’s team) and are actually delivered to agents (per scheduling rules). - Enforce the new schedule correlation inside
saveResultLogsToQueryReportsbefore persisting rows. - Add/adjust unit and integration tests to cover rejected forged submissions and accepted scheduled submissions.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| server/service/osquery.go | Adds schedule-correlation logic and applies it when saving query report rows from result logs. |
| server/service/osquery_test.go | Updates mocks to reflect scheduled queries and adds a unit test for rejecting non-scheduled/forged report submissions. |
| server/service/integration_core_test.go | Adds an integration test ensuring forged results for unscheduled/other-team reports are rejected, and scheduled ones are accepted. |
| changes/16776-forged-query-report-rows | User-visible changelog entry (content excluded from review). |
Files excluded by content exclusion policy (1)
- changes/16776-forged-query-report-rows
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Ignore results for queries that are not part of this host's schedule | ||
| // (e.g. queries of another team, out of the host's label scope, or not | ||
| // scheduled at all), otherwise a host could forge rows in any report. |
| ds.QueryByNameFunc = func(ctx context.Context, teamID *uint, name string) (*fleet.Query, error) { | ||
| query, ok := queries[name] | ||
| if !ok || teamID != nil { | ||
| return nil, newNotFoundError() | ||
| } | ||
| return query, nil | ||
| } | ||
| ds.OverwriteQueryResultRowsFunc = func(ctx context.Context, rows []*fleet.ScheduledQueryResultRow, maxQueryReportRows int) (int, error) { | ||
| return len(rows), nil | ||
| } | ||
|
|
||
| log := fmt.Sprintf( | ||
| `{"action":"snapshot","name":"pack/Global/%s","hostIdentifier":"1379f59d98f4","calendarTime":"Tue Jan 10 20:08:51 2017 UTC","unixTime":1484078931,"snapshot":[{"forged":"true"}]}`, | ||
| tc.queryName, | ||
| ) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #50239 +/- ##
==========================================
+ Coverage 68.07% 68.11% +0.04%
==========================================
Files 3936 3936
Lines 250572 250946 +374
Branches 13433 13433
==========================================
+ Hits 170565 170927 +362
+ Misses 64696 64690 -6
- Partials 15311 15329 +18
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
changes/,orbit/changes/oree/fleetd-chrome/changes.Testing