Repository navigation
feat(mdm): require BitLocker per Windows host on Fleet Free CU-17tkuw6a8db #293
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
Merged
+1,272
−19
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
48fb5ce
feat(mdm): CU-17tkuw6a8db require BitLocker per Windows host on Fleet…
andrii-flamingo fc8cbd0
fix(mdm): CU-17tkuw6avb8 require the server URL on a tenant config up…
andrii-flamingo 928a8fc
fix(mdm): CU-17tkuw6a8db clear the key time with the BitLocker key row
andrii-flamingo 48ba46d
fix(mdm): CU-17tkuw6a8db count a repeated host id once in the BitLock…
andrii-flamingo f0a0ef4
fix(mdm): CU-17tkuw6a8db take the BitLocker key of a host that left MDM
andrii-flamingo 8302101
fix(mdm): CU-17tkuw6a8db move the BitLocker requirement to the Window…
andrii-flamingo 3d24a1c
fix(mdm): CU-17tkuw6a8db lift the old tenant's BitLocker requirement …
andrii-flamingo 16a45a4
Merge branch 'main' into feat/windows-disk-encryption
andrii-flamingo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # BitLocker required per host on Fleet Free (OpenFrame) | ||
|
|
||
| Upstream requires disk encryption per team and only on Premium. In the fork a team is a tenant, and a tenant | ||
| requires encryption for some of its customers only, so each Windows host has its own requirement. | ||
|
|
||
| Only in OpenFrame mode (`FLEET_OPENFRAME_MODE`) or shared mode; otherwise everything below is upstream's. macOS | ||
| and Linux keep the team's setting, except the archived keys (below). | ||
|
|
||
| ## Requirement | ||
|
|
||
| - `POST /api/_version_/fleet/disk_encryption/hosts` with `{"host_ids": [1, 2]}` requires the hosts to encrypt; | ||
| `DELETE` on the same path with the same body lifts that. Both answer `{"hosts": <n>}`, the number of hosts they | ||
| applied to, and can be repeated. Permission is the one for upstream's `POST /disk_encryption`, on the pinned team. | ||
| - Hosts of another tenant, hosts that don't exist and hosts that don't run Windows are dropped. In shared mode a | ||
| call without a tenant is refused. | ||
| - `openframe_host_disk_encryption` (`migrations/openframe/20261201000001_AddHostDiskEncryptionTable.go`) keeps a row | ||
| per host that was ever required, with the tenant it was required in. Lifting keeps the row with `required = 0`. | ||
| A host moved to another tenant is not required there, and starts there without the old tenant's error and key | ||
| time; deleting the host deletes the row. | ||
|
|
||
| ## Result | ||
|
|
||
| The same row keeps what fleetd reported, without the key, so that the table can be captured by the CDC connector and | ||
| `host_disk_encryption_keys`, which holds the keys, never has to be: | ||
|
|
||
| - `client_error`: fleetd's last error, empty when there is none. A failing fleetd reports it again every config cycle; | ||
| a repeated error changes nothing in the row. | ||
| - `key_stored_at`: when the host's last key was stored, NULL before the first. An error keeps it. | ||
|
|
||
| Both are cleared where upstream deletes the key row, MDM re-enrollment and team change: after a wipe or a reinstall the | ||
| disk is another one. A required host's fleetd then sends a new key. Lifting the requirement keeps both. The archived key | ||
| stays readable after a re-enrollment, so NULL in `key_stored_at` does not mean that Fleet has no key. | ||
|
|
||
| ## What follows it | ||
|
|
||
| - **fleetd** (`setDiskEncryptionNotifications`): a required host that is in MDM gets `EnforceBitLockerEncryption` | ||
| under upstream's conditions; any other host does not, whatever the team's setting is. Lifting never turns | ||
| BitLocker off. | ||
| - **The key** (`SetOrUpdateDiskEncryptionKey`): stored for a host that was ever required, also after the requirement | ||
| was lifted. On a drive that was already encrypted fleetd removes the other recovery keys before it sends the new | ||
| one, so a dropped key would leave none that opens the drive. | ||
| - **The status** (`GetMDMWindowsBitLockerStatus`, `os_settings.disk_encryption` in host details): shown on Free for a | ||
| required host, empty for any other. No startup PIN is ever required. | ||
|
|
||
| `GET /hosts/{id}/encryption_key` is upstream's. The host is fenced (`HostLite`), and in shared mode the key is | ||
| decrypted with the pair of the host's tenant. | ||
|
|
||
| ## Archived keys | ||
|
|
||
| Without an archived key of the host itself, upstream returns one by hardware serial. In OpenFrame mode it does not, | ||
| on any platform: the serial can be another machine's, of the tenant or of another one. | ||
|
|
||
| ## Known limits | ||
|
|
||
| - fleetd sends again a key that Fleet did not take only while the host is told to encrypt. A key that failed to | ||
| reach Fleet is lost if the requirement is lifted before the next try. | ||
| - The result is written after the key, not with it. Its write is retried on a deadlock or a lock timeout; if it | ||
| fails, `key_stored_at` stays as it was until the next key. | ||
| - Reading a key needs Windows MDM to be on for the tenant (`VerifyMDMWindowsConfigured`), as upstream. | ||
|
|
||
| ## Tests | ||
|
|
||
| - `server/service/openframe_windows_disk_encryption_test.go` | ||
| - `server/datastore/mysql/openframe_windows_disk_encryption_test.go` (`MYSQL_TEST=1`) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4333,167 +4333,172 @@ | |
| return nil | ||
| } | ||
|
|
||
| func (ds *Datastore) MDMResetEnrollment(ctx context.Context, hostUUID string, scepRenewalInProgress bool) error { | ||
| return ds.withRetryTxx(ctx, func(tx sqlx.ExtContext) error { | ||
| var hosts []fleet.Host | ||
| // >>> OPENFRAME(windows-mdm-tenant): in shared mode a pinned reset touches only its tenant's host — openframe/docs/mysql-multitenancy-feature.md | ||
| hostsStmt, hostsArgs := `SELECT id, platform, team_id FROM hosts WHERE uuid = ?`, []any{hostUUID} | ||
| if teamID, ok := fleet.OpenframeTeamID(ctx); ok && openframeSharedMode(ctx) { | ||
| hostsStmt, hostsArgs = hostsStmt+` AND team_id = ?`, append(hostsArgs, teamID) | ||
| } | ||
| err := sqlx.SelectContext( | ||
| ctx, tx, &hosts, | ||
| hostsStmt, hostsArgs..., | ||
| ) | ||
| // <<< OPENFRAME(windows-mdm-tenant) | ||
| switch { | ||
| case err != nil: | ||
| return ctxerr.Wrap(ctx, err, "resetting mdm enrollment: getting host info from UUID") | ||
| case len(hosts) == 0: | ||
| return ctxerr.Wrap(ctx, notFound("Host").WithName(hostUUID), "resetting mdm enrollment: getting host info from UUID") | ||
| case len(hosts) > 1: | ||
| // >>> OPENFRAME(enroll-machine-identity): machines of one team sharing a hardware UUID get no MDM enrollment rather than each other's host — openframe/docs/enroll-machine-identity.md | ||
| if err := ds.openframeRefuseSharedHardwareUUIDOfOneTeam(ctx, hostUUID, hosts); err != nil { | ||
| return err | ||
| } | ||
| // <<< OPENFRAME(enroll-machine-identity) | ||
| // This shouldn't happen, but if it does, we log the IDs of the hosts | ||
| // with the same UUID for debugging purposes. | ||
| ids := make([]uint, len(hosts)) | ||
| for _, host := range hosts { | ||
| ids = append(ids, host.ID) | ||
| } | ||
| ds.logger.InfoContext(ctx, "multiple hosts found with the same uuid", "host_ids", fmt.Sprintf("%v", ids)) | ||
| } | ||
| host := hosts[0] | ||
|
|
||
| if !fleet.MDMSupported(host.Platform) { | ||
| return ctxerr.Errorf(ctx, "unsupported host platform: %q", host.Platform) | ||
| } | ||
|
|
||
| // Reconcile host_emails and host_scim_users sourced from mdm_idp_accounts. | ||
| // | ||
| // Note that we aren't deleting the mdm_idp_accounts themselves, just prior associations | ||
| // for the host. This ensures that hosts that reenroll their emails up-to-date. | ||
| switch host.Platform { | ||
| case "darwin", "ios", "ipados": | ||
| idp, err := reconcileHostEmailsFromMdmIdpAccountsDB(ctx, tx, ds.logger, host.ID) | ||
| if err != nil { | ||
| return ctxerr.Wrap(ctx, err, "resetting host_emails sourced from mdm_idp_accounts") | ||
| } | ||
| // TODO: confirm approach with Victor | ||
| if _, err := tx.ExecContext(ctx, `DELETE FROM host_scim_user WHERE host_id = ?`, host.ID); err != nil { | ||
| return ctxerr.Wrap(ctx, err, "resetting host_scim_users") | ||
| } | ||
| if err := maybeAssociateHostMDMIdPWithScimUser(ctx, tx, ds.logger, host.ID, idp); err != nil { | ||
| return ctxerr.Wrap(ctx, err, "resetting host_emails sourced from mdm_idp_accounts") | ||
| } | ||
| } | ||
|
|
||
| // TODO: Add test coverage for scepRenewalInProgress branching logic. | ||
| // FIXME: When revisiting scep renewal paths, think about no clear indicator for new enrollment vs only SCEP renewal coming from Authenticate | ||
| // which is why we call this method, with a distinct false value in TokenUpdate, as that is only where we have a clear indicator | ||
| // on if it is an old device that was expected to renew but was wiped. | ||
| if scepRenewalInProgress { | ||
| // FIXME: We need to revisit this flow. Short-circuiting in random places means it is | ||
| // much more difficult to reason about the state of the host. We should try instead | ||
| // to centralize the flow control in the lifecycle methods. | ||
| ds.logger.InfoContext(ctx, "host lifecycle action received for a SCEP renewal in process, skipping additional reset actions", "host_uuid", hostUUID) | ||
| return nil | ||
| } | ||
|
|
||
| // Deleting profiles from this table will cause all profiles to | ||
| // be re-delivered on the next cron run. | ||
| if err := ds.deleteMDMOSCustomSettingsForHost(ctx, tx, hostUUID, host.Platform); err != nil { | ||
| return ctxerr.Wrap(ctx, err, "resetting profiles status") | ||
| } | ||
|
|
||
| // Delete any stored disk encryption keys. This covers cases | ||
| // where hosts re-enroll without sending a CheckOut message | ||
| // first, for example: | ||
| // | ||
| // - IT admin wiping the host locally | ||
| // - Host restoring from a back-up | ||
| // | ||
| // This also means that somebody running `sudo profiles renew | ||
| // --type enrollment` will report disk encryption as "pending" | ||
| // for a short period of time. | ||
| _, err = tx.ExecContext(ctx, ` | ||
| DELETE FROM host_disk_encryption_keys | ||
| WHERE host_id = ?`, host.ID) | ||
| if err != nil { | ||
| return ctxerr.Wrap(ctx, err, "resetting disk encryption key information for host") | ||
| } | ||
| // >>> OPENFRAME(windows-disk-encryption): the result goes with the key — openframe/docs/windows-disk-encryption.md | ||
| if err := openframeClearDiskEncryptionResults(ctx, tx, []uint{host.ID}); err != nil { | ||
| return err | ||
| } | ||
| // <<< OPENFRAME(windows-disk-encryption) | ||
|
|
||
| // Clear MDM-delivered certs for the same re-enroll-without-CheckOut | ||
| // cases (local wipe, restore from backup, manual MDM profile removal). | ||
| if err := softDeleteMDMHostCertsDB(ctx, tx, host.ID); err != nil { | ||
| return ctxerr.Wrap(ctx, err, "resetting mdm host certificates for host") | ||
| } | ||
|
|
||
| // Do platform-specific cleanup. | ||
| switch host.Platform { | ||
| case "ios", "ipados": | ||
| // Clear refetch commands for iOS and iPadOS hosts. | ||
| // FIXME: Do we care about wipe/lock commands? How can we consolidate this with host deletion? See https://github.com/fleetdm/fleet/pull/29283/files#r2098735905 | ||
| _, err = tx.ExecContext(ctx, ` | ||
| DELETE FROM host_mdm_commands | ||
| WHERE host_id = ? AND instr(command_type, ?)`, host.ID, fleet.RefetchBaseCommandUUIDPrefix) | ||
| if err != nil { | ||
| return ctxerr.Wrap(ctx, err, "resetting host_mdm_commands for host") | ||
| } | ||
|
|
||
| case "darwin": | ||
| // Deleting the matching entry on this table will cause | ||
| // the aggregate report to show this host as 'pending' to | ||
| // install the bootstrap package. | ||
| _, err = tx.ExecContext(ctx, `DELETE FROM host_mdm_apple_bootstrap_packages WHERE host_uuid = ?`, hostUUID) | ||
| if err != nil { | ||
| return ctxerr.Wrap(ctx, err, "resetting host_mdm_apple_bootstrap_packages") | ||
| } | ||
|
|
||
| _, err = tx.ExecContext( | ||
| ctx, | ||
| "UPDATE nano_enrollments SET hardware_attested = false WHERE id = ? AND enabled = 1", | ||
| hostUUID, | ||
| ) | ||
| if err != nil { | ||
| return ctxerr.Wrap(ctx, err, "resetting hardware_attested") | ||
| } | ||
|
|
||
| // Soft-delete the recovery lock password: Apple wipes the device-side recovery lock | ||
| // whenever the MDM profile is removed, and any subsequent Authenticate means the | ||
| // device went through an unenroll/re-enroll (or wipe/restore). Also unsticks rows | ||
| // whose SetRecoveryLock command was abandoned by nanomdm's ClearQueue (same | ||
| // Authenticate fires both cleanups). Table is keyed by host_uuid. | ||
| if err := softDeleteHostRecoveryLockPassword(ctx, tx, hostUUID); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| // reset the enrolled_from_migration value. We only get to this | ||
| // stage if the host is enrolling with Fleet, SCEP renewals are | ||
| // short-circuited before this. | ||
| _, err = tx.ExecContext( | ||
| ctx, | ||
| "UPDATE nano_enrollments SET enrolled_from_migration = 0 WHERE id = ? AND enabled = 1", | ||
| hostUUID, | ||
| ) | ||
| if err != nil { | ||
| return ctxerr.Wrap(ctx, err, "setting enrolled_from_migration") | ||
| } | ||
| _, err = tx.ExecContext( | ||
| ctx, | ||
| `UPDATE nano_devices SET platform = ?, enroll_team_id = ? WHERE id = ?`, | ||
| host.Platform, host.TeamID, hostUUID, | ||
| ) | ||
| if err != nil { | ||
| return ctxerr.Wrap(ctx, err, "setting platform and enroll_team_id") | ||
| } | ||
|
|
||
| return nil | ||
| }) | ||
| } | ||
|
Check warning on line 4501 in server/datastore/mysql/apple_mdm.go
|
||
|
|
||
| func (ds *Datastore) ClearHostEnrolledFromMigration(ctx context.Context, hostUUID string) error { | ||
| const stmt = ` | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
server/datastore/mysql/migrations/openframe/20261201000001_AddHostDiskEncryptionTable.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package openframe | ||
|
|
||
| import ( | ||
| "database/sql" | ||
| "fmt" | ||
| ) | ||
|
|
||
| func init() { | ||
| MigrationClient.AddMigration(Up_20261201000001, Down_20261201000001) | ||
| } | ||
|
|
||
| // Up_20261201000001 adds `openframe_host_disk_encryption`: the Windows hosts OpenFrame has ever required to encrypt, and | ||
| // whether it still does. A row stays when the requirement is lifted, so that a key on its way is accepted. `team_id` is | ||
| // the host's tenant when the row was written: a row does not follow the host to another tenant. `client_error` and | ||
| // `key_stored_at` repeat what host_disk_encryption_keys knows without the key, so that this table can be captured by the | ||
| // CDC connector and that one never has to be. See openframe/docs/windows-disk-encryption.md. | ||
| // | ||
| // Idempotent. | ||
| func Up_20261201000001(tx *sql.Tx) error { | ||
| if _, err := tx.Exec(` | ||
| CREATE TABLE IF NOT EXISTS openframe_host_disk_encryption ( | ||
| host_id INT UNSIGNED NOT NULL, | ||
| team_id INT UNSIGNED DEFAULT NULL, | ||
| required TINYINT(1) NOT NULL, | ||
| client_error VARCHAR(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', | ||
| key_stored_at TIMESTAMP(6) NULL DEFAULT NULL, | ||
| updated_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), | ||
| PRIMARY KEY (host_id) | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`); err != nil { | ||
| return fmt.Errorf("creating openframe_host_disk_encryption: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
|
andrii-flamingo marked this conversation as resolved.
Resolved
andrii-flamingo marked this conversation as resolved.
Resolved
|
||
|
|
||
| func Down_20261201000001(tx *sql.Tx) error { | ||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.