Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions openframe/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ The agent has its own switch, `--openframe-mode` / `ORBIT_OPENFRAME_MODE`.
| [enroll-machine-identity.md](enroll-machine-identity.md) | One Fleet host per OpenFrame machine: with `FLEET_OPENFRAME_MACHINE_IDENTITY` on, agents enroll with the OpenFrame machine id and move their host to it with the node key they held, so machines sharing a hardware UUID stop overwriting each other; a second machine (another osquery instance) with the same hardware UUID refused while the owner is live, takeover log for alerting, MDM refused for a UUID shared within a team. |
| [windows-wipe.md](windows-wipe.md) | `POST /hosts/{id}/wipe` wipes Windows hosts on Fleet Free, over Windows MDM (RemoteWipe CSP); refused, or cancelled before it is sent, when the hardware UUID does not identify one device; `completed_wipe` activity when the device accepts it. |
| [windows-disk-encryption.md](windows-disk-encryption.md) | BitLocker required per Windows host on Fleet Free (`POST`/`DELETE /disk_encryption/hosts`): the fleetd notification, the key and the status follow the host, not its team; archived keys are never looked up by serial. |
| [windows-lock.md](windows-lock.md) | `POST /hosts/{id}/lock` locks Windows hosts on Fleet Free with BitLocker: forced recovery and a restart, with an optional message on the recovery screen; refused without a recovery key Fleet can decrypt and finds on the drive, and for a second concurrent lock; a startup task on the PC and the unlock script Fleet queues when the PC checks in restore the TPM protector; only Fleet's own scripts in OpenFrame mode; `completed_lock`, `failed_lock` and `failed_unlock` activities. |

## Agent-side (orbit / fleetd)

Expand Down
1 change: 1 addition & 0 deletions openframe/docs/fork-file-manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ and the heaviest standing rebase cost.
| Shared-mode MDM | instance-wide MDM flags: `server/fleet/openframe.go`, `server/datastore/mysql/app_configs.go`, `server/service/mdm.go`; instance settings and instance-config reads: `cmd/fleet/serve.go`, `server/datastore/cached_mysql/cached_mysql.go`, `server/mdm/android/service/service.go`; enrollment routes: `server/service/openframe_middleware.go`; Android enrollment: `server/mdm/android/service/pubsub.go`; tenant change: `server/datastore/mysql/{hosts,openframe}.go`; Apple OTA: `server/datastore/mysql/apple_mdm.go`; Windows profile cleanup: `server/datastore/mysql/mdm.go`; per-tenant Windows MDM: `server/fleet/{app,datastore,microsoft_mdm,openframe_windows_mdm}.go`, `server/service/{openframe_windows_mdm,orbit,microsoft_mdm,hosts,appconfig,service,openframe_middleware}.go`, `server/service/osquery_utils/{queries,queries_openframe_windows_mdm}.go`, `{cmd/fleet,server/datastore/mysql}/openframe_windows_wstep.go`, `server/datastore/mysql/{microsoft_mdm,microsoft_mdm_batched,apple_mdm,openframe_windows_mdm}.go`, `migrations/openframe/20261127000001_AddTeamIdToMdmWindowsEnrollments.go`, `server/mdm/microsoft/openframe_wstep.go`, `server/mock/datastore_mock.go`; tests: `server/datastore/mysql/{app_configs,android,apple_ota,windows_mdm}_openframe_test.go`, `server/datastore/mysql/openframe_windows_{wstep,mdm}_test.go`, `server/service/{openframe_middleware,openframe_windows_mdm}_test.go`, `server/service/osquery_utils/queries_openframe_mdm_link_test.go`, `migrations/openframe/migration_test.go`, `server/fleet/openframe_windows_mdm_test.go`, `cmd/fleet/openframe_windows_wstep_test.go`, `server/mdm/android/service/pubsub_openframe_test.go` — see [mysql-multitenancy-feature.md](mysql-multitenancy-feature.md) |
| Windows wipe (`openframe/docs/windows-wipe.md`) | `server/service/{scripts,mdm,microsoft_mdm,openframe_windows_mdm,openframe_windows_wipe}.go`, `server/fleet/{datastore,microsoft_mdm,openframe_windows_wipe}.go`, `server/mock/datastore_mock.go`, `server/datastore/mysql/{microsoft_mdm,hosts,openframe_windows_wipe}.go`; tests: `server/service/openframe_windows_wipe_test.go`, `server/datastore/mysql/openframe_windows_wipe_test.go` |
| Windows disk encryption (`openframe/docs/windows-disk-encryption.md`) | `server/service/{orbit,hosts,handler,openframe_windows_disk_encryption}.go`, `server/fleet/{datastore,service,openframe_windows_disk_encryption}.go`, `server/mock/datastore_mock.go`, `server/mock/service/service_mock.go`, `server/datastore/mysql/{apple_mdm,disk_encryption,hosts,microsoft_mdm,openframe_windows_disk_encryption}.go`, `migrations/openframe/20261201000001_AddHostDiskEncryptionTable.go`, `schema.sql`; tests: `server/service/openframe_windows_disk_encryption_test.go`, `server/datastore/mysql/openframe_windows_disk_encryption_test.go`, `server/datastore/mysql/hosts_test.go`, `migrations/openframe/migration_test.go` |
| Windows lock (`openframe/docs/windows-lock.md`) | `server/service/{scripts,orbit,osquery,openframe_windows_lock}.go`, `server/fleet/{api_scripts,datastore,service,openframe_windows_lock}.go`, `server/mock/datastore_mock.go`, `server/mock/service/service_mock.go`, `server/datastore/mysql/{scripts,openframe_windows_lock}.go`; tests: `server/service/openframe_windows_lock_test.go`, `server/datastore/mysql/openframe_windows_lock_test.go`, `server/fleet/openframe_windows_lock_test.go` |
| Agent options kept | `cmd/fleet/serve.go` (starter-library skip under multitenancy), `server/fleet/openframe.go` (trimmed seed/fallback defaults), `server/datastore/mysql/teams_openframe_test.go`, `server/fleet/openframe_test.go` |
| Agent JSON content-type | `client/orbit_client.go`, `client/device_client.go`, `orbit/cmd/fetch_cert/main.go`, `client/orbit_client_content_type_test.go` |
| Orbit 401 streak across restarts | `client/orbit_client.go`, `client/orbit_reenroll_openframe.go`; tests: `client/orbit_reenroll_openframe_test.go` — see [node-key-management.md](node-key-management.md) |
Expand Down
114 changes: 114 additions & 0 deletions openframe/docs/windows-lock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Windows lock on Fleet Free (OpenFrame)

Upstream locks Windows hosts on Premium only, with a script that disables local accounts. The fork's lock on Free
is a hard lock with BitLocker: the system drive is forced into recovery and the PC restarts to the BitLocker
recovery screen. It starts again only with the drive's recovery key, which Fleet holds. There is no unlock command:
someone types the key at the PC, and Fleet notices when the PC checks in again.

Only in OpenFrame mode (`FLEET_OPENFRAME_MODE`) or shared mode, and only for Windows hosts; otherwise the request goes
to upstream's `LockHost` (402 on Free).

## Request

`POST /api/_version_/fleet/hosts/{id}/lock`, with an optional body `{"message": "..."}`
(`server/service/scripts.go`, `server/service/openframe_windows_lock.go`). The message, up to 240 characters with no
line breaks or other control characters, is set as the custom message of the recovery screen.

Refused:

- without permission to run MDM commands on the host's team (403); another tenant's host is 404;
- when fleetd doesn't run scripts on the host (`scripts_enabled` not true, or no fleetd) (422);
- with a pending lock, unlock or wipe, or when the host is locked (422) or wiped (409);
- when Fleet has no current recovery key for the host that it can decrypt (422, "Lock needs BitLocker"). An archived
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
pair has to decrypt the key.

The lock is queued as an internal script with upstream's `lock_ref`, so the host's status is upstream's: pending lock
until fleetd reports the result, locked once it reports exit code 0. The host's lock, unlock and wipe references are
read before its status is checked, and the lock is queued only if they are still the same, in one transaction under
the host's row lock (`OpenframeLockWindowsHostViaScript`): of two concurrent locks one is queued, the other answers
422. `locked_host` is recorded with the request.

## The lock script

It runs on the PC as SYSTEM, in PowerShell, and on `%SystemDrive%`. Each request gets its own id.

1. exits 0 if this request's lock ran on the PC already (`BitLockerLastLockId` under `HKLM\SOFTWARE\OpenFrame`, kept
after the unlock). fleetd keeps no record of the scripts it ran: when the result of a lock is lost before the
restart, fleetd runs the script again once the PC is back, and it must not lock the PC a second time;
2. checks that BitLocker protects the drive (exit 2);
3. checks that one of the drive's recovery passwords is the key Fleet holds: the script carries its SHA-256, never
the key (exit 3). A locked PC that Fleet's key doesn't open could not be started again;
4. refuses a drive with a TPM protector that has a PIN or a startup key, which the lock would delete and the unlock
couldn't restore (exit 4);
5. records under `HKLM\SOFTWARE\OpenFrame\BitLockerLock` whether the drive had a TPM protector and the recovery message
policy it replaces. A record left by a lock that didn't finish is kept, and its message is restored when the new
lock has none;
6. sets the message, if any, as the recovery message policy (`HKLM\SOFTWARE\Policies\Microsoft\FVE`,
`RecoveryKeyMessageSource` = 2 and `RecoveryKeyMessage`). The message reaches the script in base64, so nothing in
it runs;
7. registers the startup task `\OpenFrame\BitLocker unlock` (SYSTEM), which runs the unlock script below, carried in
the task as an encoded command and not as a file, and creates the volatile key
`HKLM\SOFTWARE\OpenFrame\BitLockerLockBoot`, which Windows drops at restart (exit 6 if either fails);
8. runs `manage-bde -forcerecovery`, which also deletes the drive's TPM protectors (exit 5 if it fails, with the
message, the record, the task and the volatile key undone). Its error output doesn't end the script;
9. records the request's id, restarts the PC in 30 seconds, closing open apps, and exits 0, so that fleetd reports
the result before it.

A failed lock clears the pending lock and records `failed_lock` with the exit code; a lock that succeeded records
`completed_lock` (`server/fleet/openframe_windows_lock.go`).

## Unlock

The unlock script runs twice over: on the PC at the first start after the recovery key was typed, from the startup
task, so the TPM protector comes back even when fleetd doesn't or the host's lock was cleared in Fleet (an agent
re-enrollment clears it); and from Fleet, which confirms the unlock and marks the host unlocked.

When a locked Windows host checks in (orbit config) at least 2 minutes after its lock succeeded, someone has typed the
recovery key. The fork then queues the internal unlock script with upstream's `unlock_ref` (`OpenframeQueueWindowsUnlock`,
`server/datastore/mysql/openframe_windows_lock.go`), unless an unlock or a wipe is pending. A failed attempt is tried
again 15 minutes later, then after twice as long each time, up to a day (`OpenframeWindowsUnlockDue`). The host's row
is locked while the script is queued, so concurrent check-ins queue one.

The script:

1. exits 0 if no lock is recorded on the PC, e.g. as the startup task has unlocked it already, and removes the task;
2. exits 10 if the volatile key is there: the PC hasn't restarted since the lock, e.g. as someone cancelled the
restart with `shutdown /a`. The host stays locked, the drive goes to recovery at the next restart, and nothing is
recorded;
3. adds a TPM protector back if the drive had one, as `-forcerecovery` deleted it and Windows would otherwise ask for
the key at every start (exit 11 if it can't);
4. restores the recovery message policy and removes the record, the volatile key and the startup task.

Exit code 0 makes the host unlocked, as upstream, and records `unlocked_host` with no user. Any other failure than
exit 10 records `failed_unlock` with the exit code.

Wipe is refused while a host is locked, by upstream's checks. Fleet can't turn MDM off for a Windows host.

## Scripts in OpenFrame mode

fleetd on Windows runs scripts only when started with `--enable-scripts`, so OpenFrame has to start it with that flag;
without it the lock is refused. In
OpenFrame and shared mode the fork then refuses every script that isn't Fleet's own (`openframeRefuseScript`, in
upstream's `insertNewHostScriptExecution`): a user's or a batch's script is refused (422) and not queued, and a policy's script
is not queued when the policy starts failing (`processScriptsForNewlyFailingPolicies`), so it logs no error.
Internal scripts (lock, unlock, upstream's internal cleanups) and software installs and uninstalls are not affected.

## Tenancy

The lock reads the host through the fenced `Host`, so another tenant's host is 404, and decrypts the key with the
host's tenant's WSTEP pair. The unlock is queued for the host that authenticated the check-in, and its result is
recorded in that request's tenant.

## Not verified on a real PC yet

- that the recovery screen shows the message set by the policy, and how it shows characters outside ASCII;
- the startup task, the volatile key (`RegistryOptions.Volatile` needs .NET Framework 4.6 or later) and
`Add-BitLockerKeyProtector` at startup;
- a lock whose result is lost before the restart stays pending lock in Fleet until fleetd runs it again after the
unlock, which then reports it done.

## Tests

- `server/service/openframe_windows_lock_test.go`
- `server/datastore/mysql/openframe_windows_lock_test.go` (`MYSQL_TEST=1`)
2 changes: 1 addition & 1 deletion openframe/scripts/verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ rm -f vet.err
# 3. Marker presence: if a merge silently dropped fork code, its OPENFRAME markers
# vanish too. A slug dropping to zero is a red flag worth a human look.
step "OPENFRAME marker presence (dropped-fork-code detector)"
for slug in host-assignments managed-policies managed-queries redis-key-prefix redis-seed-nodes query-results-ttl osquery-host-id agent-openframe-mode agent-json-content-type agent-skip-setup-experience agent-host-info-diagnostics agent-verify-server-tls migration-race server-private-key-kms enroll-machine-identity windows-disk-encryption; do
for slug in host-assignments managed-policies managed-queries redis-key-prefix redis-seed-nodes query-results-ttl osquery-host-id agent-openframe-mode agent-json-content-type agent-skip-setup-experience agent-host-info-diagnostics agent-verify-server-tls migration-race server-private-key-kms enroll-machine-identity windows-disk-encryption windows-lock; do
n=$(grep -rIl "OPENFRAME($slug" --include='*.go' --include='*.yaml' --include='*.tpl' . 2>/dev/null | wc -l | tr -d ' ')
if [ "$n" -gt 0 ]; then ok "$slug — present in $n file(s)"; else bad "$slug — NO markers found (fork code may have been dropped in the merge)"; fi
done
Expand Down
Loading
Loading