add default fleet for BYOD Apple migration - #47161
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements the database/schema changes for BYOD Apple enrollment work by extending abm_tokens with a BYOD default team pointer and a required enrollment URL token, plus introducing a new mdm_adue_enrollment_challenges table. It also adds a Fleet helper for generating the URL-safe random token and includes a migration test.
Changes:
- Add
byod_default_team_idand requiredenrollment_url_token(unique + length check) toabm_tokens, with a backfill for existing rows. - Add
mdm_adue_enrollment_challengestable with FK relationships toabm_tokensandmdm_idp_accounts. - Add a shared helper to generate a 32-byte-entropy base64url token and add migration tests.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
server/fleet/mdm.go |
Adds helper for generating 32-byte random base64url token. |
server/datastore/mysql/schema.sql |
Updates canonical schema for new ABM token fields + new ADUE challenges table. |
server/datastore/mysql/migrations/tables/20260609104220_AddBYODFleetAndADUEEnrollment.go |
Adds migration that alters abm_tokens, backfills enrollment_url_token, and creates ADUE challenges table. |
server/datastore/mysql/migrations/tables/20260609104220_AddBYODFleetAndADUEEnrollment_test.go |
Adds migration test coverage for backfill + constraints/FK behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
WalkthroughThis PR introduces foundational schema and infrastructure for BYOD default fleet enrollment and ADUE enrollment challenge tracking. It adds a cryptographic token generation utility, extends the Possibly related issues
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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.
Inline comments:
In
`@server/datastore/mysql/migrations/tables/20260609104220_AddBYODFleetAndADUEEnrollment_test.go`:
- Around line 80-83: The negative tests for abm_tokens FK constraints are not
isolating the intended foreign-key failures because required non-null columns
are omitted, so the DB may reject the row for the wrong reason; update the
failing insert statements that target byod_default_team_id, idp_account_uuid,
and abm_token_id to include all other required non-null columns (e.g.,
enrollment_url_token, challenge, idp_account_uuid, abm_token_id as appropriate)
with valid placeholder values so the only failing condition is the specific FK
being tested (refer to the abm_tokens table columns byod_default_team_id,
enrollment_url_token, challenge, idp_account_uuid, abm_token_id to locate and
fix the three blocks around the current failing checks).
In
`@server/datastore/mysql/migrations/tables/20260609104220_AddBYODFleetAndADUEEnrollment.go`:
- Around line 32-44: The rows.Err() check is currently executed before iterating
and therefore won't catch iteration-time errors; move the check to run after the
for rows.Next() loop that scans into the temporary token struct and appends to
abmTokens so any errors from rows.Next() or rows.Scan() are captured (i.e.,
perform rows.Err() after the loop that processes abm_tokens using rows.Next()
and rows.Scan()).
- Around line 71-87: The idp_account_uuid column in table
mdm_adue_enrollment_challenges is declared as VARCHAR(36) but it references
mdm_idp_accounts.uuid which is VARCHAR(255); update the idp_account_uuid
definition in the CREATE TABLE for mdm_adue_enrollment_challenges to match the
referenced type and collation (change VARCHAR(36) to VARCHAR(255) COLLATE
utf8mb4_unicode_ci NOT NULL) so the foreign key constraint (CONSTRAINT
mdm_adue_idp_account_fk FOREIGN KEY (idp_account_uuid) REFERENCES
mdm_idp_accounts(uuid) ON DELETE CASCADE) remains valid and consistent.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: aa3bff7e-f708-409b-8954-9d3bba20be07
📒 Files selected for processing (4)
server/datastore/mysql/migrations/tables/20260609104220_AddBYODFleetAndADUEEnrollment.goserver/datastore/mysql/migrations/tables/20260609104220_AddBYODFleetAndADUEEnrollment_test.goserver/datastore/mysql/schema.sqlserver/fleet/mdm.go
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #47161 +/- ##
=======================================
Coverage 67.19% 67.19%
=======================================
Files 3273 3274 +1
Lines 227905 227975 +70
Branches 11746 11746
=======================================
+ Hits 153137 153188 +51
- Misses 60956 60967 +11
- Partials 13812 13820 +8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
7e9ee38 to
65ec360
Compare
00283c2 to
394aba1
Compare
Related issue: Resolves #45595
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/oree/fleetd-chrome/changes.See Changes files for more information. (Will add in a follow up story)
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
Release Notes