Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated python_packages osquery query #26434

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

ksykulev
Copy link
Contributor

@ksykulev ksykulev commented Feb 18, 2025

A new feature in osquery 5.16 was created to allow for scanning of user directories for python packages. If the new version of osquery is detected use the new query, otherwise use the old query.

#26423

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.
  • Added/updated automated tests
  • A detailed QA plan exists on the associated ticket (if it isn't there, work with the product group's QA engineer to add it)
  • Manual QA for all new/changed functionality

@ksykulev ksykulev requested a review from a team as a code owner February 18, 2025 22:04
@ksykulev
Copy link
Contributor Author

I tried to add some tests in server/service/osquery_utils/queries_test.go. However, because this method is called during var initialization, it is very hard to stub either fleet.OsqueryVersion or semver.NewVersion.

Copy link

codecov bot commented Feb 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.84%. Comparing base (6e3d6dd) to head (72c5159).
Report is 51 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #26434      +/-   ##
==========================================
+ Coverage   63.72%   63.84%   +0.12%     
==========================================
  Files        1655     1659       +4     
  Lines      158995   159162     +167     
  Branches     4144     4144              
==========================================
+ Hits       101321   101619     +298     
+ Misses      49737    49602     -135     
- Partials     7937     7941       +4     
Flag Coverage Δ
backend 64.67% <100.00%> (+0.13%) ⬆️

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

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

@@ -850,7 +851,7 @@ SELECT
'' AS vendor,
0 AS last_opened_at,
path AS installed_path
FROM python_packages
FROM ` + osqueryVersionGreaterThanEqual("5.16.0", "cached_users CROSS JOIN python_packages USING (uid)", "python_packages") + `
Copy link
Member

Choose a reason for hiding this comment

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

How does this work when a fleet of hosts have mixed osquery versions? This feels like we're hard-coding the query for the entirety of the Fleet server, which means this will either skip the new functionality or break old clients depending on when Fleet was built, rather than based on what the host actually has installed.

Feels like the right place to put this is in GetDetailQueries, potentially as another type of override. Splitting this query up might allow for more code reuse with that override.

Likely need to update gen_queries_doc.go as well to either split results based on osquery version, or at least link to GitHub history for how vitals queries change while mentioning which osquery version those queries correspond to.

The catch with this is that we'll have one query in detail queries relying on the result of ingesting another detail query, which is particularly tricky when setting things up on enrollment, but this looks fixable by splitting the detail queries onto a group that relies on host into and a group that doesn't, running the "doesn't" group first, then passing host info into the generator for the rest. Then if we don't get osquery info back we assume an old version of osquery, which will return less info but won't break.

Nice thing about all of the above is it makes this a lot more testable, since calling an endpoint with differing query results for osquery_info will kick back the relevant software query.

A new feature in osquery 5.16 was created to allow for scanning of user directories for python packages.
If the new version of osquery is detected use the new query, otherwise use the old query.
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