Skip to content

Fix enrollment endpoint errors - #52611

Draft
JordanMontgomery wants to merge 2 commits into
mainfrom
JM-enrollment-restructure
Draft

Fix enrollment endpoint errors#52611
JordanMontgomery wants to merge 2 commits into
mainfrom
JM-enrollment-restructure

Conversation

@JordanMontgomery

@JordanMontgomery JordanMontgomery commented Sep 4, 2026

Copy link
Copy Markdown
Member

Related issue: Resolves #

Centralizes error handling around invalid token/invalid serial/missing machineinfo cases. Prior, depending on whether or not OS updates were enabled or the host was assigned in DEP or not these would return any number of 4xx/5xx statuses. Moved the check logic up so that those consistent checks happen first, return a 4xx if necessary, then move on to the config-specific ones

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

Summary by CodeRabbit

  • Security & Enrollment

    • Automatic Apple device enrollment now verifies the enrollment token and confirms the device is assigned for enrollment before processing.
    • Failed enrollment requests provide clearer error messages and stop before further processing.
  • Bug Fixes

    • Unsupported Apple host platforms now return a not-found response when OS update settings are unavailable.

@JordanMontgomery

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

🟡 Changes recommended

Authentication accepts manual-profile tokens and relies on potentially stale replica data for current DEP assignment state.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Warning

  • Copilot's review of this pull request may be incomplete because some of the changed files are excluded by your Copilot content exclusion settings. See Excluding content from Copilot for details.
Pull request overview

Centralizes authentication for Apple automatic enrollment and standardizes enrollment failures.

Changes:

  • Validates enrollment tokens, machine info, and DEP assignments earlier.
  • Treats unsupported Apple update platforms as not found.
  • Updates mocks and enrollment tests.
File summaries
File Description
changes/apple-automatic-enrollment-restructure Excluded change note; contents unavailable.
server/service/apple_mdm.go Adds centralized DEP enrollment authentication.
server/fleet/service.go Extends the service interface.
server/mock/service/service_mock.go Adds generated authentication mocks.
server/datastore/mysql/apple_mdm.go Returns not-found for unsupported platforms.
server/datastore/mysql/apple_mdm_test.go Tests unsupported-platform behavior.
server/service/apple_mdm_test.go Tests authentication ordering and outcomes.
server/service/integration_mdm_test.go Adds DEP assignments to test fixtures.
server/service/integration_mdm_dep_test.go Synchronizes DEP before enrollment tests.
server/service/integration_mdm_commands_test.go Uses manual enrollment for command restrictions.
Review details

Files excluded by content exclusion policy (1)

  • changes/apple-automatic-enrollment-restructure
  • Files reviewed: 9/10 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread server/service/apple_mdm.go Outdated
Comment on lines +2947 to +2951
if _, err := svc.ds.GetMDMAppleEnrollmentProfileByToken(ctx, token); err != nil {
if fleet.IsNotFound(err) {
return fleet.NewAuthFailedError("enrollment profile not found")
}
return ctxerr.Wrap(ctx, err, "get enrollment profile")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

there is nowhere in the current code that creates or would allow someone to create such a manual profile, but removed the possibility anyways

}

// Only devices currently assigned to Fleet in ABM may enroll through this path.
assignments, err := svc.ds.GetHostDEPAssignmentsBySerial(ctx, machineInfo.Serial)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed

@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 879a3c54-eeba-45af-a8dd-11a2f0bd855f

📥 Commits

Reviewing files that changed from the base of the PR and between 86fb514 and 6cff036.

📒 Files selected for processing (10)
  • changes/apple-automatic-enrollment-restructure
  • server/datastore/mysql/apple_mdm.go
  • server/datastore/mysql/apple_mdm_test.go
  • server/fleet/service.go
  • server/mock/service/service_mock.go
  • server/service/apple_mdm.go
  • server/service/apple_mdm_test.go
  • server/service/integration_mdm_commands_test.go
  • server/service/integration_mdm_dep_test.go
  • server/service/integration_mdm_test.go

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


Walkthrough

The Apple MDM enrollment endpoint now authenticates the enrollment token and verifies the device’s DEP assignment before OS checks and profile generation. The service interface and mock include the new authentication method. Unit and integration tests cover authentication errors, processing order, DEP assignment setup, and ABM scheduling. Apple OS update settings lookups now return not-found errors for unsupported host platforms.

Merge Risk: ⚪ Minimal · up to 6cff0

Apple DEP enrollment now rejects invalid tokens, missing machine details, and unassigned serials before downstream processing, while valid devices continue through enrollment. The supplied coverage supports the intended 4xx behavior and enrollment flow.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 7 files. (3 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change: fixing inconsistent enrollment endpoint errors.
Description check ✅ Passed The description explains the problem, intended behavior, and testing. It includes the required checklist sections that apply, although the related issue placeholder remains unresolved and the changes-…
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 7 files. (3 skipped: 1 unsupported, 2 too large.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch JM-enrollment-restructure

Warning

Some tools did not complete. Review the errors below.

🔧 ast-grep (0.45.2)
server/service/integration_mdm_test.go

ast-grep timed out on this file


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.

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