fleetdm / fleet

Open-source platform for IT, security, and infrastructure teams. (Linux, macOS, Chrome, Windows, cloud, data center)
https://fleetdm.com
Other
2.66k stars 379 forks source link

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

Open lucasmrod opened 1 week ago

lucasmrod commented 1 week ago

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)
JoStableford commented 1 week ago

Related to a Slack conversation

noahtalerman commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

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

sharon-fdm commented 1 week ago

Hey team! Please add your planning poker estimate with Zenhub @getvictor @jacobshandling @lucasmrod @mostlikelee @RachelElysia

zayhanlon commented 6 days ago

@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 commented 5 days ago

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

sharon-fdm commented 5 days ago

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

zayhanlon commented 5 days ago

Thank you all!

lucasmrod commented 4 days ago

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 commented 4 days ago

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

lucasmrod commented 3 days ago

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).

lucasmrod commented 3 days ago

@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 commented 3 days ago

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