Skip to content

BMAA: Add personal enrollment type including aggregate counts#31091

Merged
JordanMontgomery merged 24 commits intomainfrom
JM-bmaa-personal-enrollment
Jul 22, 2025
Merged

BMAA: Add personal enrollment type including aggregate counts#31091
JordanMontgomery merged 24 commits intomainfrom
JM-bmaa-personal-enrollment

Conversation

@JordanMontgomery
Copy link
Copy Markdown
Member

@JordanMontgomery JordanMontgomery commented Jul 21, 2025

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)
  • If database migrations are included, checked table schema to confirm autoupdate
  • For database migrations:
    • Checked schema for all modified table for columns that will auto-update timestamps during migration.
    • Confirmed that updating the timestamps is acceptable, and will not cause unwanted side effects.
    • Ensured the correct collation is explicitly set for character columns (COLLATE utf8mb4_unicode_ci).
  • Added/updated automated tests
    • Where appropriate, automated tests simulate multiple hosts and test for host isolation (updates to one hosts's records do not affect another.)
  • Manual QA for all new/changed functionality

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 21, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch JM-bmaa-personal-enrollment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 21, 2025

Codecov Report

Attention: Patch coverage is 73.91304% with 18 lines in your changes missing coverage. Please review.

Project coverage is 64.03%. Comparing base (a87ec09) to head (4d18cde).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
...bles/20250718091828_AddPersonalEnrollmentStatus.go 69.23% 6 Missing and 2 partials ⚠️
server/service/microsoft_mdm.go 0.00% 4 Missing ⚠️
server/datastore/mysql/apple_mdm.go 75.00% 0 Missing and 3 partials ⚠️
server/datastore/mysql/hosts.go 77.77% 2 Missing ⚠️
server/mdm/lifecycle/lifecycle.go 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #31091   +/-   ##
=======================================
  Coverage   64.03%   64.03%           
=======================================
  Files        1905     1906    +1     
  Lines      187623   187655   +32     
  Branches     5415     5448   +33     
=======================================
+ Hits       120136   120169   +33     
+ Misses      58047    58042    -5     
- Partials     9440     9444    +4     
Flag Coverage Δ
backend 64.89% <73.91%> (+<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.

gillespi314
gillespi314 previously approved these changes Jul 21, 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.

Looks good! Feel free to address comments in a follow up PR as you see fit :)

Does this also cover filtering hosts by the new status? I didn't see any changes to transport so I'm assuming that's still on our list as something that @ghernandez345 can work on adding that and supplementing related tests?

- "host_serial": Serial number of the host (Apple enrollments only, always empty for Microsoft). Only for company-owned hosts.
- "enrollment_id": Enrollment identifier of the personal (BYOD) host (iPhone, iPad and Android enrollments only, null for other platforms).
- "host_display_name": Display name of the host.
- "personal_host": Whether the host is personal or company-owned.
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.

Do we need this personal_host boolean? It seems like we can infer that this is a personal device based on the presence or absence of enrollment_id. Also, we may want to disambiguate enrollment_id (to avoid collisions with other activity types). Maybe byod_identifier is more distinctive?

Copy link
Copy Markdown
Contributor

@ghernandez345 ghernandez345 Jul 22, 2025

Choose a reason for hiding this comment

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

if we do switch this lets remember to upate the global activities UI as it currently relies on personal_host to render correctly

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.

This is what Marko specified so I can ask in design review. Enrollment ID is technically the term Apple uses here though

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree with @gillespi314 about inferring this from the presence of an enrollment_id rather than adding an extra boolean, but am not super opposed to personal_host if it's too late to change. (Would prefer we called it byod_host since that's more in line with our usual terminology.)

Sorry to ask for changes this late in the game! I was never requested for review on #30186 so this is my first time seeing this

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.

No worries. What I am gonna do is split these activity/doc changes out so someone else can tighten up the spec and get them merged in later this week

assert.True(t, entry.IsPersonalEnrollment, "is_personal_enrollment should be true for host_id 7")
assert.Equal(t, "On (personal)", *entry.EnrollmentStatus)
case 8:
assert.True(t, entry.IsPersonalEnrollment, "is_personal_enrollment should be true for host_id 6")
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.

Nit: Seems like the host_id is wrong in the message. Consider using a format string based on entry.HostID?

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.

You're right. I came back and updated this test after wanting to add more cases and messed it up. Will fix

Comment on lines +13933 to +13935
// Fetch the hosts we enrolled and check their details. Specifically we want to verify that MDM
// shows a personal enrollment via all 3 endpoints(list hosts, host details and host MDM
// details) since they query for the information slightly differently
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.

Quick double-check: There are a few other endpoints that also return similar data that you may want to spot check. For example:

https://fleetdm.com/docs/rest-api/rest-api#get-host-by-identifier
https://fleetdm.com/docs/rest-api/rest-api#list-hosts-in-a-label
https://fleetdm.com/docs/rest-api/rest-api#targets

Potentially others too that I don't remember off the top of my head (but I think they are documented in the code comments on the other host endpoints).

Comment on lines +937 to +938
// Note I am explicitly not re-enrolling the iPhone here as I don't believe that particular
// device and enrollment type actually supports re-enrollment like this
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.

Did this comment come back as a result of merge conflicts?

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.

Good catch. It must have. The actual command to re-enroll was there even though this comment said otherwise. Thanks for catching that

gillespi314
gillespi314 previously approved these changes Jul 22, 2025
Comment thread server/fleet/activities.go Outdated
Comment thread server/service/integration_mdm_dep_test.go Outdated
gillespi314
gillespi314 previously approved these changes Jul 22, 2025
@JordanMontgomery JordanMontgomery merged commit fea2b40 into main Jul 22, 2025
42 checks passed
@JordanMontgomery JordanMontgomery deleted the JM-bmaa-personal-enrollment branch July 22, 2025 21:24
@MagnusHJensen MagnusHJensen mentioned this pull request Jul 23, 2025
7 tasks
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.

5 participants