Skip to content

update apple query for profile verification with include all/any + exclude#47079

Merged
MagnusHJensen merged 2 commits into
mainfrom
apple-verification-label-update
Jun 8, 2026
Merged

update apple query for profile verification with include all/any + exclude#47079
MagnusHJensen merged 2 commits into
mainfrom
apple-verification-label-update

Conversation

@MagnusHJensen

@MagnusHJensen MagnusHJensen commented Jun 8, 2026

Copy link
Copy Markdown
Member

Related issue: Follow up PR for the Include Any/All + Exclude label story, since this was missed.

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), JS inline code is prevented especially for url redirects, and untrusted data interpolated into shell scripts/commands is validated against shell metacharacters.

  • Timeouts are implemented and retries are limited to avoid infinite loops

  • If paths of existing endpoints are modified without backwards compatibility, checked the frontend/CLI for any necessary changes

Testing

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

Summary by CodeRabbit

  • Bug Fixes

    • Improved Apple MDM profile verification to more accurately determine expected configuration profiles, including correct handling of mixed include/exclude label combinations and exclusion edge cases.
  • Tests

    • Updated unit and integration tests to reflect the expanded Apple include+exclude scenarios and to run Apple-only profile reconciliation flows.

Copilot AI review requested due to automatic review settings June 8, 2026 13:19
@MagnusHJensen MagnusHJensen requested a review from a team as a code owner June 8, 2026 13:19

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

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.

Pull request overview

This PR updates the MySQL query used to compute expected Apple MDM profiles for verification, expanding label-scope handling to support combinations of include any/all with exclude-any.

Changes:

  • Updated getHostMDMAppleProfilesExpectedForVerification SQL to separate “include-only”, “exclude-only”, and new “include + exclude” cases via additional UNION branches.
  • Removed Windows handling from GetHostMDMProfilesExpectedForVerification (and removed corresponding Windows test coverage).
  • Extended the macOS labeled-profile verification test setup to include include+exclude scenarios.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
server/datastore/mysql/mdm.go Expands Apple expected-profiles verification query with include/exclude combinations; removes Windows platform support from expected-profiles verification.
server/datastore/mysql/mdm_test.go Adds macOS include+exclude test cases and removes Windows expected-profiles verification tests.
Comments suppressed due to low confidence (1)

server/datastore/mysql/mdm.go:1397

  • The "exclude-any only" branch doesn't implement the same dynamic-label freshness gate used elsewhere (e.g. Android/Windows desired-state queries): a dynamic exclude label created after hosts.label_updated_at should disqualify the profile, but this query will currently include it as long as the host isn't in label_membership. This can cause profiles to be incorrectly expected/verified before the host has reported label results. Consider joining hosts/labels and adding a HAVING condition equivalent to count_profile_labels = count_host_updated_after_labels (see server/datastore/mysql/android.go exclude-only HAVING).
	macp.team_id = ? AND
	NOT EXISTS (
		SELECT 1 FROM mdm_configuration_profile_labels
		WHERE apple_profile_uuid = macp.profile_uuid AND exclude = 0
	)
GROUP BY
	profile_uuid, identifier
HAVING
	-- considers only the profiles with labels, without any broken label, and with the host not in any label
	count_profile_labels > 0 AND
	count_profile_labels = count_non_broken_labels AND
	count_host_labels = 0

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/datastore/mysql/mdm.go
Comment thread server/datastore/mysql/mdm.go
Comment thread server/datastore/mysql/mdm_test.go
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The PR refines Apple MDM expected-profile verification by restructuring the SQL query to handle label combinations more precisely. The platform switch now explicitly rejects unsupported platforms. Single-label-type profiles (include-all-only, exclude-any-only) are refined with NOT EXISTS predicates to enforce mutual exclusivity with conflicting label types. New UNION branches handle mixed configurations (include-all + exclude-any, include-any + exclude-any) using conditional aggregation to enforce include requirements while rejecting profiles with disqualifying exclude labels. Test coverage is extended with 4 new profiles combining include and exclude rules, increasing expected profile count to 15.

Possibly related PRs

  • fleetdm/fleet#46889: Implements the main Apple verification expected-profiles SQL computation with combined include-all/include-any + exclude-any applicability and corresponding test coverage across label-rule platforms.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: updating the Apple MDM profile verification query to handle combined include-all/any and exclude label scenarios.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch apple-verification-label-update

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@MagnusHJensen

Copy link
Copy Markdown
Member Author

Main and integration-mdm failures seems unrelated? One failing on TUF and another on an S3 test

@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.05%. Comparing base (836695a) to head (5c8697a).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #47079      +/-   ##
==========================================
- Coverage   67.05%   67.05%   -0.01%     
==========================================
  Files        2887     2891       +4     
  Lines      225171   225197      +26     
  Branches    11636    11636              
==========================================
+ Hits       150996   151012      +16     
- Misses      60504    60511       +7     
- Partials    13671    13674       +3     
Flag Coverage Δ
backend 68.77% <100.00%> (-0.01%) ⬇️

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.

@JordanMontgomery

Copy link
Copy Markdown
Member

@MagnusHJensen I think the integrations-mdm error is legitimate. Looks like maybe the verification Windows code was being used in the test for soemthing

time=2026-06-08T13:24:09.582Z level=INFO msg="Completing manage_windows_profiles job" test=TestIntegrationsMDM/TestHostMDMProfilesExcludeLabels time=2026-06-08T13:24:09Z
integration_mdm_test.go:1098: [awaitTriggerProfileSchedule] All jobs completed successfully at 2026-06-08T13:24:09Z
time=2026-06-08T13:24:09.582Z level=INFO msg=completed schedule=mdm_apple_profile_manager instanceID=TestIntegrationsMDM
integration_mdm_profiles_test.go:6224:
Error Trace: /home/runner/work/fleet/fleet/server/service/integration_mdm_profiles_test.go:6224
Error: Received unexpected error:
unsupported platform: windows
Test: TestIntegrationsMDM/TestHostMDMProfilesExcludeLabels

@MagnusHJensen

Copy link
Copy Markdown
Member Author

@JordanMontgomery Just removed the windows part on that test, which should have been removed with the removal of Windows verification. It's never exercised in production code and hasn't been for a long time, so we are fine to remove the windows branch.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
server/service/integration_mdm_profiles_test.go (1)

6232-6234: ⚡ Quick win

Update stale Windows wording in this Apple-only flow.

Line 6233 still references “the Windows host,” but this test path is now Apple-only. Keeping this comment accurate will prevent confusion when debugging this scenario.

✏️ Suggested comment cleanup
-	// remove membership of [4] for Apple, meaning
-	// that only D3 will be installed on Apple (as the Windows host is still
-	// member of an excluded label)
+	// remove membership of [4] for Apple, meaning
+	// that only D3 will be installed on Apple.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server/service/integration_mdm_profiles_test.go` around lines 6232 - 6234,
Update the stale comment in integration_mdm_profiles_test.go that reads "the
Windows host is still member of an excluded label": this flow is Apple-only, so
change that phrase to accurately reflect the scenario (e.g., "the other host is
still a member of an excluded label" or "a different host is still a member of
an excluded label") near the comment starting "remove membership of [4] for
Apple" so the comment no longer references a Windows host.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@server/service/integration_mdm_profiles_test.go`:
- Around line 6232-6234: Update the stale comment in
integration_mdm_profiles_test.go that reads "the Windows host is still member of
an excluded label": this flow is Apple-only, so change that phrase to accurately
reflect the scenario (e.g., "the other host is still a member of an excluded
label" or "a different host is still a member of an excluded label") near the
comment starting "remove membership of [4] for Apple" so the comment no longer
references a Windows host.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 33ac7504-faf2-4dd3-a5db-7ca6c09b0a31

📥 Commits

Reviewing files that changed from the base of the PR and between 5f0d769 and 5c8697a.

📒 Files selected for processing (1)
  • server/service/integration_mdm_profiles_test.go

@MagnusHJensen MagnusHJensen merged commit 6a84d3a into main Jun 8, 2026
42 checks passed
@MagnusHJensen MagnusHJensen deleted the apple-verification-label-update branch June 8, 2026 15:24
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