fleet/server/mdm
Jordan Montgomery 572536d466
Skip setup experience during AxM based migrations (#32822)
Fixes #32096

The gist of the fix is that when syncing devices from DEP we save the
migration deadline to our host_dep_assignments table. The next
enrollment, which we assume should be the migration, looks at
host_dep_assignments, sees that mdm_migration_deadline is non-Null and
mdm_migration_completed is NULL, and uses that as the signal that a
migration is in progress and skips enqueuing setup experience items. It
then marks the migration as complete which sets mdm_migration_completed
= mdm_migration_deadline. Once this is set setup experience will run as
normal unless mdm_migration_completed gets set to NULL and/or
mdm_migration_deadline gets set to a value in the future(which e.g.
would happen if the customer assigned to another MDM server then
assigned to migrate to fleet again)

DB test failure is expected here because it won't like the migration
timestamp but that is a necessary failure because this fix is going to
be backported into 4.73

# Checklist for submitter

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

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.

- [x] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [x] If paths of existing endpoints are modified without backwards
compatibility, checked the frontend/CLI for any necessary changes

## Testing

- [x] Added/updated automated tests
- [x] Where appropriate, [automated tests simulate multiple hosts and
test for host
isolation](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/reference/patterns-backend.md#unit-testing)
(updates to one hosts's records do not affect another)

- [x] QA'd all new/changed functionality manually

For unreleased bug fixes in a release candidate, one of:

- [x] Confirmed that the fix is not expected to adversely impact load
test results
- [x] Alerted the release DRI if additional load testing is needed

## Database migrations

- [x] Checked table schema to confirm autoupdate
- [x] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [x] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [x] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* New Features
  * Tracks and stores Apple DEP MDM migration deadlines per device/host.
  * Detects “migration in progress” during DEP sync and check-in.
* Automatically marks migration complete and skips Setup Assistant items
while migration is in progress to prevent conflicts.

* Bug Fixes
* Improved DEP compatibility by updating the protocol version and
User-Agent used for Apple’s APIs, reducing the chance of blocked or
rejected requests.

* Migrations
* Adds fields to support migration deadlines and completion status (no
action required).

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Magnus Jensen <magnus@fleetdm.com>
2025-09-11 09:40:40 -04:00
..
android Handle deleted Android Enterprise (#32267) 2025-09-04 08:17:37 -04:00
apple Skip setup experience during AxM based migrations (#32822) 2025-09-11 09:40:40 -04:00
assets Updated SQL modes in tests to match production. (#31445) 2025-08-03 08:18:13 +02:00
crypto Update nanomdm dependency with latest bug fixes and improvements. (#23906) 2024-11-20 11:47:11 -06:00
cryptoutil Refactoring crypto code for future reuse. (#25148) 2025-01-07 16:14:12 -06:00
internal/commonmdm friday tidy up party (#18106) 2024-04-08 08:42:42 -03:00
lifecycle BMAA: Add personal enrollment type including aggregate counts (#31091) 2025-07-22 17:24:19 -04:00
linux Linux Encryption Docs (#23622) 2024-12-10 08:26:46 -07:00
maintainedapps Add custom software icons (#32652) 2025-09-05 17:31:03 -05:00
microsoft Fixed issue due to UUID mistmatch on BitLocker CSP cmd. (#32210) 2025-08-22 14:32:23 -04:00
nanodep Skip setup experience during AxM based migrations (#32822) 2025-09-11 09:40:40 -04:00
nanomdm Fix flaky test async last seen by using channel sync instead of time sleep (#31128) 2025-07-22 18:19:44 +02:00
scep fleetd generate TPM key and issue SCEP certificate (#30932) 2025-07-18 11:31:52 -03:00
testing_utils Add datastore methods for host certificates feature (#26416) 2025-02-18 17:49:02 -06:00
mdm.go Added verification support for $FLEET_VAR_HOST_UUID (#31777) 2025-08-11 14:47:55 +02:00
mdm_test.go fix: Detect file starting with comment in mdm.go as well (#27673) 2025-03-31 19:16:13 -05:00