Skip to content

Match query reports from hosts in /api/v1/osquery/log endpoint - #50239

Draft
lucasmrod wants to merge 1 commit into
mainfrom
16776-forged-query-report-rows
Draft

Match query reports from hosts in /api/v1/osquery/log endpoint#50239
lucasmrod wants to merge 1 commit into
mainfrom
16776-forged-query-report-rows

Conversation

@lucasmrod

Copy link
Copy Markdown
Member
  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.

Testing

  • Added/updated automated tests
  • QA'd all new/changed functionality manually

Copilot AI review requested due to automatic review settings July 30, 2026 17:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 queriesScheduledForHost filtering 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 saveResultLogsToQueryReports before 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.

Comment thread server/service/osquery.go
Comment on lines +3351 to +3353
// 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.
Comment on lines +1153 to +1167
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

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.11%. Comparing base (5983f9d) to head (07770e9).
⚠️ Report is 56 commits behind head on main.

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     
Flag Coverage Δ
backend 69.45% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants