fleetdm / fleet

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

Deleting a host doesn't delete the MDM table references #10673

Closed roperzh closed 1 year ago

roperzh commented 1 year ago

Fleet version: 4.28.1

🧑‍💻  Expected behavior

When a host is deleted, all references are removed from other tables (we don't enforce foreign key constraints to the hosts table.)

💥  Actual behavior

host_mdm_apple_profiles, and all nano_ tables still keep the host reference.

This is probably not a big deal for the nano tables, but I don't think the cron is smart enough to deal with host_mdm_apple_profiles.

More info

We have an slice of hosts references:

https://github.com/fleetdm/fleet/blob/f5c8daacf01b0765324a7f627aaeffa96c37b699/server/datastore/mysql/hosts.go#L309-L312

But those are DELETEd by id, however all MDM tables reference hosts by host_uuid

https://github.com/fleetdm/fleet/blob/f5c8daacf01b0765324a7f627aaeffa96c37b699/server/datastore/mysql/hosts.go#L336-L338

mna commented 1 year ago

Oooh great catch!

lukeheath commented 1 year ago

@georgekarrv I thought this would be a good bug to start on.

mna commented 1 year ago

@georgekarrv Just a heads-up that I started work on this one, I might be able to have something ready by EOD but if not I'll make sure to keep you posted on whatever remains to be done!

EDIT: PR is up and ready for review: https://github.com/fleetdm/fleet/pull/11017

fleet-release commented 1 year ago

Hosts deleted, cleaned, MDM tables refreshed too, Fleet harmonizes.