Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send DeviceConfigured MDM command after DEP enrollment #17737

Merged

Conversation

mna
Copy link
Member

@mna mna commented Mar 20, 2024

#17401

Checklist for submitter

  • Changes file added for user-visible changes in changes/ or orbit/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)
  • Added/updated tests

Copy link

codecov bot commented Mar 20, 2024

Codecov Report

Attention: Patch coverage is 75.60000% with 61 lines in your changes are missing coverage. Please review.

❗ No coverage uploaded for pull request base (feat-prefill-account-name@8d2deb3). Click here to learn what that means.

❗ Current head 770c9d4 differs from pull request most recent head c4da092. Consider uploading reports for the commit c4da092 to get more accurate results

Files Patch % Lines
server/worker/apple_mdm.go 67.96% 29 Missing and 12 partials ⚠️
...145650_UpdateDEPProfilesToAwaitDeviceConfigured.go 83.33% 6 Missing and 2 partials ⚠️
ee/server/service/mdm.go 45.45% 4 Missing and 2 partials ⚠️
ee/server/service/teams.go 40.00% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@                     Coverage Diff                      @@
##             feat-prefill-account-name   #17737   +/-   ##
============================================================
  Coverage                             ?   65.64%           
============================================================
  Files                                ?     1194           
  Lines                                ?   108292           
  Branches                             ?     2574           
============================================================
  Hits                                 ?    71093           
  Misses                               ?    31802           
  Partials                             ?     5397           
Flag Coverage Δ
backend 66.65% <75.60%> (?)

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.

}
}

func (s *integrationMDMTestSuite) TestDEPProfileAssignment() {
Copy link
Member Author

Choose a reason for hiding this comment

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

This test was not modified, just moved here from the integration_mdm_test.go as it is DEP-specific.

@@ -1981,745 +1999,6 @@ func createWindowsHostThenEnrollMDM(ds fleet.Datastore, fleetServerURL string, t
return host, mdmDevice
}

func (s *integrationMDMTestSuite) TestDEPProfileAssignment() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Since this file is already huuuuuge, I created a new integration_mdm_dep_test.go file for the DEP-specific MDM integration tests, and moved this one over there.

// On the next try, new commands will be enqueued for the same task (e.g. if
// it failed at the bootstrap package, install fleetd will be enqeueued
// again), will Apple MDM process both commands successfully or would the
// second one fail? Relevant for the device release.
Copy link
Member Author

Choose a reason for hiding this comment

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

@roperzh maybe you know this? My hunch is that those are idempotent so if e.g. fleetd is already installed and the command is sent again, it would succeed again.

Copy link
Member

Choose a reason for hiding this comment

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

it would! they're not idempotent, but I believe the commands we send won't produce errors either.

  • All InstallProfile commands won't have any effect (because it'll be considered an 'edit' by the OS and nothing changed)
  • All InstallEnterpriseApplication will trigger a second install. This might be problematic for the bootstrap package, but I believe Noah's plan is to document that the bootstrap package must be "idempotent" (as much as an application can be)

I don't know if I'm missing other commands.

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe the commands we send won't produce errors either.
This might be problematic for the bootstrap package, but I believe Noah's plan is to document that the bootstrap package must be "idempotent" (as much as an application can be)

Awesome, thanks for the clarifications!

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know if I'm missing other commands.

The other potential one is AccountConfiguration, which I assume would be like an edit to the previous settings and would not result in an error.

Copy link
Member

Choose a reason for hiding this comment

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

agreed, IIRC that's fine as well.

// the release device task is always added with a delay
var delay time.Duration
if task == AppleMDMPostDEPReleaseDeviceTask {
delay = 30 * time.Second
Copy link
Member Author

Choose a reason for hiding this comment

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

This task is always delayed, so that the device has the time to process the initial enrollment commands and a Reconcile profiles job has a chance to run.

@@ -191,6 +209,7 @@ func (w *Worker) processJob(ctx context.Context, job *fleet.Job) error {
args = *job.Args
}

ctx = context.WithValue(ctx, retryNumberCtxKey, job.Retries)
Copy link
Member Author

Choose a reason for hiding this comment

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

A bit hacky, but that was a quick and easy way to make that info available to the job processor.

//
// but without calling that function, in case the code changes in the future,
// breaking this migration. Instead we insert directly the job in the
// database, and the worker will process it shortly after Fleet restarts.
Copy link
Member Author

Choose a reason for hiding this comment

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

@roperzh do you know if that means that existing DEP-enrolled devices will now need to be explicitly released? The Apple docs mention it blocks in Setup Assistant so presumably devices that are already past this assistant will be ok, but worth double-checking in tests? Because re-generating the profiles also re-assigns them to existing hosts here: https://github.com/fleetdm/fleet/blob/main/server/worker/macos_setup_assistant.go#L113-L137

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I believe we're fine here! those settings only affect the next time the device goes through the setup assistant 👍

@mna mna marked this pull request as ready for review March 20, 2024 20:31
@mna mna requested a review from a team as a code owner March 20, 2024 20:31
Copy link
Member

@roperzh roperzh left a comment

Choose a reason for hiding this comment

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

very elegant solution for a hard problem ✨ . LGTM

server/worker/apple_mdm.go Show resolved Hide resolved
@mna
Copy link
Member Author

mna commented Mar 25, 2024

@roperzh I'll merge as it's only going to the feature branch and Gabe is waiting on this to implement some fixes on top of it, but I did merge a fix and some minor changes after your approval, if you want to take another look (if there's anything to address, I'll do so in a subsequent PR). The Go mysql8 tests are also failing, but looks like that might be something we inherited from merging main into our branch, I'll take a look for a fix in the next PR too.

@mna mna merged commit 994040b into feat-prefill-account-name Mar 25, 2024
11 of 12 checks passed
@mna mna deleted the mna-17401-post-dep-enroll-device-release branch March 25, 2024 17:25
@mna
Copy link
Member Author

mna commented Mar 25, 2024

It's a test time-out on mysql 8:

2024-03-25T17:22:15.7627631Z panic: test timed out after 15m0s
2024-03-25T17:22:15.7627722Z running tests:
2024-03-25T17:22:15.7627848Z 	TestIntegrationsMDM (11m11s)
2024-03-25T17:22:15.7628055Z 	TestIntegrationsMDM/TestDEPProfileAssignment (10m42s)

I'll increase the test timeout limit for now, in a future PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants