Skip to content

Tweak MDM detection query to return the proper enrollment when there are multiple entries#29360

Merged
JordanMontgomery merged 6 commits intomainfrom
JM-29042
May 22, 2025
Merged

Tweak MDM detection query to return the proper enrollment when there are multiple entries#29360
JordanMontgomery merged 6 commits intomainfrom
JM-29042

Conversation

@JordanMontgomery
Copy link
Copy Markdown
Member

@JordanMontgomery JordanMontgomery commented May 21, 2025

This change is deceptively simple but helps us choose the right one in cases like #29042 where there are multiple enrollments in the registry. In this case the customer seems to have been using something like co-management(though even using their MDM we have not repro'd internally) which leads to 2 registry keys in the registry with a UPN node. I believe the way some MDM services handle unenroll can also leave the registry keys in this state. Either way, because of this, and the fact that we have a LIMIT 1 in the query, we were, in 50% of the cases where we had multiple keys, returning the less useful of the nodes from the query and because no Server URL was coming back we were treating it as if the host was not MDM enrolled and thus, not unenrolling it, and leading to enrollment failing.

With this change we'll return the proper registry key which should allow us to, in the case of migration, properly unenroll the host and even in the case where a customer isn't using Fleet MDM will allow us to display the correct information from the registry.

Checklist for submitter

If some of the following don't apply, delete the relevant line.

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.
  • Input data is properly validated, SELECT * is avoided, SQL injection is prevented (using placeholders for values in statements)
  • Manual QA for all new/changed functionality

@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 64.26%. Comparing base (8b7a9a1) to head (c0841d0).
Report is 18 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #29360      +/-   ##
==========================================
- Coverage   64.27%   64.26%   -0.01%     
==========================================
  Files        1840     1840              
  Lines      179020   179020              
  Branches     5174     5174              
==========================================
- Hits       115059   115047      -12     
- Misses      54921    54929       +8     
- Partials     9040     9044       +4     
Flag Coverage Δ
backend 65.25% <ø> (-0.01%) ⬇️

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.

🚀 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.

@JordanMontgomery JordanMontgomery marked this pull request as ready for review May 21, 2025 20:57
@JordanMontgomery JordanMontgomery requested review from a team, lukeheath and sharon-fdm as code owners May 21, 2025 20:57
@JordanMontgomery JordanMontgomery changed the title Tweak MDM detection query to return the proper enrollment in co-management scenarios Tweak MDM detection query to return the proper enrollment when there are multiple entries May 22, 2025
Copy link
Copy Markdown
Contributor

@gillespi314 gillespi314 left a comment

Choose a reason for hiding this comment

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

LGTM!

@JordanMontgomery JordanMontgomery merged commit 149cd9d into main May 22, 2025
43 of 44 checks passed
@JordanMontgomery JordanMontgomery deleted the JM-29042 branch May 22, 2025 18:08
eashaw added a commit that referenced this pull request May 27, 2025
Changes:
- Updated the host vital queries in queries.yml to have the changes from
#29360 and
#29280
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.

3 participants