|
| 1 | +# Windows lock on Fleet Free (OpenFrame) |
| 2 | + |
| 3 | +Upstream locks Windows hosts on Premium only, with a script that disables local accounts. The fork's lock on Free |
| 4 | +is a hard lock with BitLocker: the system drive is forced into recovery and the PC restarts to the BitLocker |
| 5 | +recovery screen. It starts again only with the drive's recovery key, which Fleet holds. There is no unlock command: |
| 6 | +someone types the key at the PC, and Fleet notices when the PC checks in again. |
| 7 | + |
| 8 | +Only in OpenFrame mode (`FLEET_OPENFRAME_MODE`) or shared mode, and only for Windows hosts; otherwise the request goes |
| 9 | +to upstream's `LockHost` (402 on Free). |
| 10 | + |
| 11 | +## Request |
| 12 | + |
| 13 | +`POST /api/_version_/fleet/hosts/{id}/lock`, with an optional body `{"message": "..."}` |
| 14 | +(`server/service/scripts.go`, `server/service/openframe_windows_lock.go`). The message, up to 240 characters with no |
| 15 | +line breaks or other control characters, is set as the custom message of the recovery screen. |
| 16 | + |
| 17 | +Refused: |
| 18 | + |
| 19 | +- without permission to run MDM commands on the host's team (403); another tenant's host is 404; |
| 20 | +- when fleetd doesn't run scripts on the host (`scripts_enabled` not true, or no fleetd) (422); |
| 21 | +- with a pending lock, unlock or wipe, or when the host is locked (422) or wiped (409); |
| 22 | +- when Fleet has no current recovery key for the host that it can decrypt (422, "Lock needs BitLocker"). An archived |
| 23 | + key is not used: it may be of another disk. Windows MDM doesn't have to be on for the host, but the tenant's WSTEP |
| 24 | + pair has to decrypt the key. |
| 25 | + |
| 26 | +The lock is queued by upstream's `LockHostViaScript` as an internal script, so the host's status is upstream's: pending |
| 27 | +lock until fleetd reports the result, locked once it reports exit code 0. `locked_host` is recorded with the request. |
| 28 | + |
| 29 | +## The lock script |
| 30 | + |
| 31 | +It runs on the PC as SYSTEM, in PowerShell, and on `%SystemDrive%`: |
| 32 | + |
| 33 | +1. checks that BitLocker protects the drive (exit 2); |
| 34 | +2. checks that one of the drive's recovery passwords is the key Fleet holds: the script carries its SHA-256, never |
| 35 | + the key (exit 3). A locked PC that Fleet's key doesn't open could not be started again; |
| 36 | +3. refuses a drive with a TPM protector that has a PIN or a startup key, which the lock would delete and the unlock |
| 37 | + couldn't restore (exit 4); |
| 38 | +4. records under `HKLM\SOFTWARE\OpenFrame\BitLockerLock` when it locked, whether the drive had a TPM protector, and |
| 39 | + the recovery message policy it replaces; |
| 40 | +5. sets the message, if any, as the recovery message policy (`HKLM\SOFTWARE\Policies\Microsoft\FVE`, |
| 41 | + `RecoveryKeyMessageSource` = 2 and `RecoveryKeyMessage`). The message reaches the script in base64, so nothing in |
| 42 | + it runs; |
| 43 | +6. runs `manage-bde -forcerecovery`, which also deletes the drive's TPM protectors (exit 5 if it fails, with the |
| 44 | + message and the record undone); |
| 45 | +7. restarts the PC in 30 seconds, closing open apps, and exits 0, so that fleetd reports the result before it. |
| 46 | + |
| 47 | +A failed lock clears the pending lock and records `failed_lock` with the exit code; a lock that succeeded records |
| 48 | +`completed_lock` (`server/fleet/openframe_windows_lock.go`). |
| 49 | + |
| 50 | +## Unlock |
| 51 | + |
| 52 | +When a locked Windows host checks in (orbit config) at least 15 minutes after its lock succeeded, someone has typed |
| 53 | +the recovery key. The fork then queues an internal unlock script with upstream's `unlock_ref` |
| 54 | +(`OpenframeQueueWindowsUnlock`, `server/datastore/mysql/openframe_windows_lock.go`), unless an unlock is pending, a |
| 55 | +wipe is, or an unlock was tried within the last 15 minutes. The host's row is locked while the script is queued, so |
| 56 | +concurrent check-ins queue one. |
| 57 | + |
| 58 | +The script: |
| 59 | + |
| 60 | +1. exits 0 if no lock is recorded on the PC; |
| 61 | +2. exits 10 if the PC hasn't restarted since the lock: the host stays locked and the unlock is tried again later; |
| 62 | +3. adds a TPM protector back if the drive had one, as `-forcerecovery` deleted it and Windows would otherwise ask for |
| 63 | + the key at every start (exit 11 if it can't); |
| 64 | +4. restores the recovery message policy and removes the record. |
| 65 | + |
| 66 | +Exit code 0 makes the host unlocked, as upstream, and records `unlocked_host` with no user. A failed unlock records |
| 67 | +nothing. |
| 68 | + |
| 69 | +Wipe is refused while a host is locked, by upstream's checks. Fleet can't turn MDM off for a Windows host. |
| 70 | + |
| 71 | +## Scripts in OpenFrame mode |
| 72 | + |
| 73 | +fleetd on Windows runs scripts only when started with `--enable-scripts`, so OpenFrame has to start it with that flag; |
| 74 | +without it the lock is refused. In |
| 75 | +OpenFrame and shared mode the fork then refuses every script that isn't Fleet's own (`openframeRefuseScript`, in |
| 76 | +upstream's `insertNewHostScriptExecution`): a user's, a batch's or a policy's script is refused (422) and not queued. |
| 77 | +Internal scripts (lock, unlock, upstream's internal cleanups) and software installs and uninstalls are not affected. |
| 78 | + |
| 79 | +## Tenancy |
| 80 | + |
| 81 | +The lock reads the host through the fenced `Host`, so another tenant's host is 404, and decrypts the key with the |
| 82 | +host's tenant's WSTEP pair. The unlock is queued for the host that authenticated the check-in, and its result is |
| 83 | +recorded in that request's tenant. |
| 84 | + |
| 85 | +## Not verified on a real PC yet |
| 86 | + |
| 87 | +- that the recovery screen shows the message set by the policy; |
| 88 | +- that fleetd always reports the lock's result within the 30 seconds before the restart. A result that is lost |
| 89 | + leaves the host pending lock. |
| 90 | + |
| 91 | +## Tests |
| 92 | + |
| 93 | +- `server/service/openframe_windows_lock_test.go` |
| 94 | +- `server/datastore/mysql/openframe_windows_lock_test.go` (`MYSQL_TEST=1`) |
0 commit comments