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

Added to Fleet set to Never when enrolling manually on MDM after installing fleetd first #20059

Closed
lucasmrod opened this issue Jun 27, 2024 · 26 comments
Assignees
Labels
:ai Request AI PR review bug Something isn't working as documented customer-preston #g-endpoint-ops Endpoint ops product group P2 Prioritize as urgent :release Ready to write code. Scheduled in a release. See "Making changes" in handbook. ~released bug This bug was found in a stable release.
Milestone

Comments

@lucasmrod
Copy link
Member

lucasmrod commented Jun 27, 2024

Fleet version: latest (bug introduced in fleet-v4.51.0)


💥  Actual behavior

Installing fleetd on macOS and then enrolling to MDM manually causes the host's Added to Fleet in the host details to be Never.

Screenshot 2024-06-27 at 2 07 48 PM

Expected behavior

The Added to Fleet should not be reset (set to Never) when enrolling the host to Fleet MDM manually.

🧑‍💻  Steps to reproduce

  1. Install fleetd on macOS
  2. Install MDM profile via My Device (aka manual MDM enroll)

QA notes

  1. Before applying 4.54.0 reproduce issue as described above for a macOS device, let's call it device X.
  2. Before applying 4.54.0 add a good macOS device (without the issue described here), let's call this one device Y.
  3. Apply 4.54.0, which will run a migration that will fix the issue for the macOS device X and will leave device Y untouched.
  4. Test enrolling DEP device works (macOS, iOS, iPadOS)
  • check the Added to Fleet date is accurate.
  1. Test enrolling macOS manually works (first install fleetd, then enroll via MDM via My device)
  • check the Added to Fleet date is accurate.
@lucasmrod lucasmrod added bug Something isn't working as documented #g-mdm MDM product group :incoming New issue in triage process. :product Product Design department (shows up on 🦢 Drafting board) #g-endpoint-ops Endpoint ops product group and removed #g-mdm MDM product group labels Jun 27, 2024
@JoStableford
Copy link
Contributor

@noahtalerman
Copy link
Member

Hey @lucasmrod and @sharon-fdm!

I'm not sure why this ended up on the drafting board...is the expected behavior unclear? Something else?

The "Added to Fleet" timestamp is when the host enrolls to Fleet. When a host shows up in Fleet for the first time. More context here: https://fleetdm.com/handbook/company/why-this-way#why-does-fleet-use-mdm-on-off-instead-of-mdm-enrolled-unenrolled

@lucasmrod lucasmrod added :release Ready to write code. Scheduled in a release. See "Making changes" in handbook. and removed :product Product Design department (shows up on 🦢 Drafting board) labels Jun 28, 2024
@lucasmrod
Copy link
Member Author

Sorry, I incorrectly added the :product label. This is a bug. Let us know how big of a priority is fixing this (vs other bugs/features).

@sharon-fdm
Copy link
Collaborator

Thanks @lucasmrod.
As always, let's keep on our board and estimate soon.

@sharon-fdm
Copy link
Collaborator

@lukeheath lukeheath added the ~released bug This bug was found in a stable release. label Jun 28, 2024
@zayhanlon zayhanlon added the P2 Prioritize as urgent label Jul 1, 2024
@zayhanlon
Copy link
Contributor

zayhanlon commented Jul 1, 2024

@sharon-fdm adding a p2 label here because the 'workaround' option of deleting the host to get this updated with the correct date does not work for customer-preston. they're unable to delete the hosts. their entire enrollment status and workflow is based on this 'enrolled date' field

@jacobshandling jacobshandling removed the :incoming New issue in triage process. label Jul 1, 2024
@jacobshandling
Copy link
Contributor

@zayhanlon got it. Sharon is out today, but we saw the P2 label and have prioritized accordingly.

@sharon-fdm
Copy link
Collaborator

Thanks @zayhanlon.
I bumped it the top of our bug list and will get this looked at asap.

@zayhanlon
Copy link
Contributor

Thank you all!

@lucasmrod
Copy link
Member Author

adding a p2 label here because the 'workaround' option of deleting the host to get this updated with the correct date does not work for customer-preston. they're unable to delete the hosts. their entire enrollment status and workflow is based on this 'enrolled date' field

@zayhanlon @noahtalerman
I have a PR in review that solves the issue moving forward (for new devices added to Fleet).
Let's discuss what we should do with hosts that already are in this state (Added to Fleet = Never). What enroll date do we set on them?

@zayhanlon
Copy link
Contributor

@lucasmrod guessing that there's no way for us to figure out the actual enroll date?

@lucasmrod
Copy link
Member Author

I'll be taking a look at where we can get the enrolled date from. AFAICS it won't be exact, most likely an approximation (deduced from other MySQL table row timestamps).

@lukeheath lukeheath added this to the 4.54.0-tentative milestone Jul 3, 2024
@lucasmrod
Copy link
Member Author

@zayhanlon @noahtalerman

Added to Fleet is the date the osquery agent enrolled (different than the MDM enroll time or the time that the host was ingested via DEP).

I did some digging and we can use the host_disks.created_at which most of the cases is close to the hosts.last_enrolled_at. In some cases it's many days apart (e.g. if you uninstall+install fleetd again on a device, then last_enrolled_at will be updated and will be different than host_disks.created_at)

Here's a dump from dogdood (46 hosts have 0 day difference, and 14 have a non-0 difference):

select datediff(hd.created_at, h.last_enrolled_at) as days_between_last_enrolled_at_and_host_disks from host_disks hd join hosts h on hd.host_id=h.id join host_mdm hmdm on hmdm.host_id=h.id where h.platform = 'darwin' and h.last_enrolled_at !;
+----------------------------------------------+
| days_between_last_enrolled_at_and_host_disks |
+----------------------------------------------+
|                                           -8 |
|                                            0 |
|                                            0 |
|                                          -92 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                           -2 |
|                                         -231 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                         -147 |
|                                         -130 |
|                                          -91 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                           -6 |
|                                            0 |
|                                            0 |
|                                          -70 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                          -52 |
|                                          -96 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                          -12 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                           -9 |
|                                          -10 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                            0 |
|                                            0 |
+----------------------------------------------+
60 rows in set (0.20 sec)

Let me know if we are a-ok going this route. (Via a migration in 4.54.0 to fix these "Never" hosts using host_disks.created_at)

@zayhanlon
Copy link
Contributor

Seems like it makes sense but I'll wait for @noahtalerman

@zayhanlon
Copy link
Contributor

@lucasmrod @noahtalerman is there NO other way for us to capture the actual enrollment date vs this option^ ? The diff on some of these is really high

@lucasmrod
Copy link
Member Author

is there NO other way for us to capture the actual enrollment date vs this option^ ? The diff on some of these is really high

I ran out of ideas. Let me check with the team.

@valentinpezon-primo
Copy link

@lucasmrod - thanks for looking into this !

Do we know why the date is "Never" even tho the agent is installed ? 🤔

We have some internal flow that triggers if the enrollment date change, in our minde this date should never changed, and if it is, it means the device was re-enrolled

if the host_disks.created_at fix is going to apply only for device that has "Never" date, I think it's acceptable

@sharon-fdm sharon-fdm added the :ai Request AI PR review label Jul 9, 2024
@noahtalerman
Copy link
Member

Hey @lucasmrod thanks for digging into this!

Installing fleetd on macOS and then enrolling to MDM manually causes the host's Added to Fleet in the host details to be Never.

Looking at the bug description, my understanding is that customer-preston is doing the opposite. Their workflow:

  1. Turn on MDM manually (installed enrollment profile)
  2. Install fleetd

@valentinpezon-primo please correct me if I'm wrong.

Do we know why the date is "Never" even tho the agent is installed ?

I had the same question...

Don't we have a "created at" timestamp in the hosts table in the Fleet DB that gets created when fleetd is installed and host enrolls? Maybe this the bug?

Meaning, assuming I'm right about customer-preston's workflow, we're not populating that "created at" timestamp for hosts that turn on MDM manually and then have fleetd installed.

I did some digging and we can use the host_disks.created_at which most of the cases is close to the hosts.last_enrolled_at. In some cases it's many days apart (e.g. if you uninstall+install fleetd again on a device, then last_enrolled_at will be updated and will be different than host_disks.created_at)

@lucasmrod, are there other cases that we know of in which the dates are far apart?

If I'm understanding correctly, customer-prestons hosts that have "Never" haven't had fleetd uninstalled and then re-installed yet.

@valentinpezon-primo is that right?

If that's right, and assuming we don't have a "created at" timestamp for hosts that turn on MDM manually and then have fleetd installed, it sounds like host_disks.created_at will be accurate.

@valentinpezon-primo
Copy link

Yes @noahtalerman , we do this (profile then fleetd is installed by fleet)

But this behavior is new (the "never" date), was properly populated before !

@lucasmrod
Copy link
Member Author

Hi folks!

Do we know why the date is "Never" even tho the agent is installed ?

The bug we introduced in v4.51.0 caused MDM enrolls/re-enrolls to set the Added to Fleet field to Never. (We are fixing this in the next release.)

Looking at the bug description, my understanding is that customer-preston is doing the opposite. Their workflow:
Turn on MDM manually (installed enrollment profile)
Install fleetd

Gotcha. AFAICS the Never would happen in these scenarios:
A. fleetd installed first, manual MDM enroll after.
B. MDM re-enroll (e.g. if the user unenrolls from MDM manually by uninstalling the enrollment profile and then re-enrolling to MDM by installing the enrollment profile again)
C. During DEP migration flow (where fleetd is installed first then MDM turned on in Fleet).

I'm guessing for customer-preston these "Never" happen because of either (B) or (C)?

@lucasmrod
Copy link
Member Author

Don't we have a "created at" timestamp in the hosts table in the Fleet DB that gets created when fleetd is installed and host enrolls? Maybe this the bug?

created_at timestamp is set when the host is enrolled through DEP (so it's different than last_enrolled_at, which is set when fleetd enrolls via orbit/osquery)

@lucasmrod
Copy link
Member Author

if the host_disks.created_at fix is going to apply only for device that has "Never" date, I think it's acceptable

Yes, that would be the plan.

@lukeheath lukeheath modified the milestones: 4.54.0, 4.55.0-tentative Jul 9, 2024
@sharon-fdm sharon-fdm modified the milestones: 4.55.0-tentative, 4.54.0 Jul 10, 2024
lucasmrod added a commit that referenced this issue Jul 11, 2024
…0173)

#20059

- [X] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#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 database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [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`).
- [X] Added/updated tests
- [X] Manual QA for all new/changed functionality
@lucasmrod
Copy link
Member Author

@xpkoala @PezHub I've added QA notes to the issue.

@PezHub
Copy link
Contributor

PezHub commented Jul 11, 2024

Thanks @lucasmrod and good timing. I literally encountered this yesterday after enrolling my device via DEP, removing the profile then manually re-enrolling. I'll be sure to test the other scenarios listed above as well.
Screenshot 2024-07-11 at 10 05 47 AM

@PezHub
Copy link
Contributor

PezHub commented Jul 11, 2024

I had to test scenario B for another mdm ticket today and confirm this fixes the issue (screenshot I posted above)

@fleet-release
Copy link
Contributor

Enrolling manually,
Fleet's date now accurate,
Calm as cloud city's view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:ai Request AI PR review bug Something isn't working as documented customer-preston #g-endpoint-ops Endpoint ops product group P2 Prioritize as urgent :release Ready to write code. Scheduled in a release. See "Making changes" in handbook. ~released bug This bug was found in a stable release.
Projects
None yet
Development

No branches or pull requests

10 participants