Skip to content

[EDR Workflows] Fix osquery pack results display when agent clock is skewed#251417

Merged
szwarckonrad merged 4 commits intoelastic:mainfrom
szwarckonrad:osquery-fix-future-timestamp-pack-results
Feb 10, 2026
Merged

[EDR Workflows] Fix osquery pack results display when agent clock is skewed#251417
szwarckonrad merged 4 commits intoelastic:mainfrom
szwarckonrad:osquery-fix-future-timestamp-pack-results

Conversation

@szwarckonrad
Copy link
Copy Markdown
Contributor

Summary

When an agent's system clock is set to a future date, the osquery Pack status table would show incorrect data - only displaying results from the clock-skewed agent while hiding results from all other agents with correct timestamps.

Root cause: The "Last Results" queries sorted by @timestamp (set by the agent) instead of event.ingested (set by Elasticsearch at indexing time). A future timestamp would become the "latest" globally, and time range filters would exclude all results from properly-clocked agents.

Fix:

  • Changed pack results queries to use event.ingested for sorting and time range filtering
  • Changed the osquery data view to use event.ingested as its time field
  • Renamed return key from @timestamp to lastResultTime for semantic clarity

Closes https://github.com/elastic/security-team/issues/15072

Testing

Manually tested with two Linux agents:

  1. One agent with correct system time
  2. One agent with clock set 1 day in the future
  3. Verified Pack status table shows results from both agents
  4. Verified "View in Discover" shows results from both agents

@szwarckonrad szwarckonrad added release_note:skip Skip the PR/issue when compiling release notes backport:skip This PR does not require backporting Team:Defend Workflows “EDR Workflows” sub-team of Security Solution labels Feb 3, 2026
@szwarckonrad szwarckonrad self-assigned this Feb 3, 2026
@szwarckonrad szwarckonrad requested a review from tomsonpl February 3, 2026 12:36
@szwarckonrad szwarckonrad marked this pull request as ready for review February 3, 2026 12:38
@szwarckonrad szwarckonrad requested a review from a team as a code owner February 3, 2026 12:38
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/security-defend-workflows (Team:Defend Workflows)

startDate={startDate}
endDate={endDate}
mode={lastResultsData?.['@timestamp'][0] ? 'absolute' : 'relative'}
mode={lastResultsData?.lastResultTime?.[0] ? 'absolute' : 'relative'}
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.

is it possible that we have no lastResultTime (asking about the optional chaining)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah why is this line of code is lastResultTime?.[0] and the ones for start and end date are lastResultTime[0]? I suspect lastResultTime is of any type?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, removed the unnecessary optional chaining and simplified the mode check in f05c152.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in f05c152 - simplified the mode check to match startDate/endDate guards.

Copy link
Copy Markdown
Member

@ashokaditya ashokaditya left a comment

Choose a reason for hiding this comment

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

Did code review only and I have a few questions.

const startDate = lastResultsData?.['@timestamp']
? moment(lastResultsData?.['@timestamp'][0]).subtract(interval, 'seconds').toISOString()
const startDate = lastResultsData?.lastResultTime
? moment(lastResultsData?.lastResultTime[0]).subtract(interval, 'seconds').toISOString()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Since lastResultsData?.lastResultTime is true here the code here should be:

Suggested change
? moment(lastResultsData?.lastResultTime[0]).subtract(interval, 'seconds').toISOString()
? moment(lastResultsData.lastResultTime[0]).subtract(interval, 'seconds').toISOString()

Same applies to all ternary checks throughout changes in the PR.

Also I suspect lastResultsData doesn't have a specific type? Is that something that should also be fixed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in f05c152 - removed the redundant ?. in all ternary truthy branches; the type is inferred from useQuery so it's not any, but adding an explicit interface could be a follow-up.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah I think adding a return type to when we call await lastValueFrom(...) should help.

startDate={startDate}
endDate={endDate}
mode={lastResultsData?.['@timestamp'][0] ? 'absolute' : 'relative'}
mode={lastResultsData?.lastResultTime?.[0] ? 'absolute' : 'relative'}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah why is this line of code is lastResultTime?.[0] and the ones for start and end date are lastResultTime[0]? I suspect lastResultTime is of any type?

Copy link
Copy Markdown
Member

@ashokaditya ashokaditya left a comment

Choose a reason for hiding this comment

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

Thanks for cleaning up the ternary checks.

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

Failed CI Steps

History

cc @szwarckonrad

@szwarckonrad szwarckonrad merged commit ec03b6d into elastic:main Feb 10, 2026
16 checks passed
mbondyra added a commit to mbondyra/kibana that referenced this pull request Feb 10, 2026
* commit '7dcc1fe3c205d2de0c3ca3f65804f21de09013c3': (285 commits)
  Enrich kbn-check-saved-objects-cli README with CI and manual usage docs (elastic#252557)
  [Discover] Add feature flag to make ESQL the default query mode (elastic#252268)
  Add maskProps.headerZindexLocation above to inspect component flyout (elastic#252543)
  [Security Solution][Atack/Alerts] Flyout header: Assignees  (elastic#252190)
  Upgrade EUI to v112.3.0 (elastic#252315)
  [Fleet] Make save_knowledge_base async in streaming state machine (elastic#252328)
  Upgrade @smithy/config-resolver 4.3.0 → 4.4.6 (elastic#252457)
  [Lens as API] Add colorMapping support for XY charts (ES|QL data layers) (elastic#252051)
  [WorkplaceAI] Add Google Drive data source and connector (elastic#250677)
  [Scout] Move GlobalSearch FTR tests to Scout (elastic#252201)
  [EDR Workflows] Fix osquery pack results display when agent clock is skewed (elastic#251417)
  [Observability Onboarding] Apply integrations limit after dedup in parseIntegrationsTSV (elastic#252486)
  [Entity Analytics] Update `host.ip` aggregation to remove painless script (elastic#252426)
  Address `@elastic/eui/require-table-caption` lint violations across `@elastic/obs-presentation-team` files (elastic#251050)
  Consolidate JSON stringify dependencies (elastic#251890)
  [index mgmt] Use esql instead of query dsl to get the index count (elastic#252422)
  Add Usage API Plugin (elastic#252434)
  Cases All Templates page (elastic#250372)
  [Agent Builder] Default value for optional params in ESQL tools (elastic#238472)
  [Fleet] Add upgrade_details.metadata.reason to AgentResponseSchema (elastic#252485)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:Defend Workflows “EDR Workflows” sub-team of Security Solution v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants