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 @@ -47,6 +47,7 @@ The agent has its own switch, `--openframe-mode` / `ORBIT_OPENFRAME_MODE`.
| [server-private-key-kms.md](server-private-key-kms.md) | Server private key wrapped with Google Cloud KMS and stored in MySQL (`FLEET_SERVER_PRIVATE_KEY_KMS_KEY`) instead of passed in plaintext. |
| [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. |

## 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 @@ -175,6 +175,7 @@ and the heaviest standing rebase cost.
| Agent OpenFrame mode | `orbit/cmd/orbit/orbit.go`, `orbit/cmd/orbit/openframe_identifier_test.go`, `orbit/pkg/constant/constant.go`, `orbit/pkg/osquery/osquery.go`, `orbit/pkg/osquery/openframe_command.go`, `orbit/pkg/osquery/openframe_command_test.go`, `client/orbit_client.go`, `server/fleet/api_orbit.go`, `server/fleet/orbit.go`, `server/service/orbit.go`, `server/service/orbit_client.go`, `server/service/base_client.go` |
| 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` |
| 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
8 changes: 6 additions & 2 deletions openframe/docs/mysql-multitenancy-feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ role-authz grouping upstream; here it is a hard boundary regardless of token rol
Fleet where every tenant operates as the same Admin user.
- **host-assignments** (`policy_hosts`/`query_hosts`) — parent verified in team + foreign host ids
dropped (pre-existing `OPENFRAME(host-assignments)` feature, extended here).
- **disk encryption** (`openframe_host_disk_encryption`): only the pinned team's Windows hosts can be required or
released, a call without a tenant is refused in shared mode, and the requirement counts only in the tenant it was set
in (`OpenframeSetHostsDiskEncryption`, `OpenframeHostDiskEncryption`). `GetHostArchivedDiskEncryptionKey` does not
fall back to the hardware serial in OpenFrame mode or for a pinned request ([windows-disk-encryption.md](windows-disk-encryption.md)).
- **teams** — `TeamLite`/`ListTeams` read fence.
- **app_config** cache (`cached_mysql.go`) — cache key includes the pinned team so one tenant's
config is never served to another; unpinned keeps the constant key.
Expand Down Expand Up @@ -233,8 +237,8 @@ and a malformed URL or flag stops the boot.
Windows MDM runs per tenant. Each tenant has its own public Windows MDM address,
`mdm.windows_server_url` on its tenant row (`https://<tenant domain>/mdm`, an https URL with a valid
host and no query, fragment, credentials or whitespace; `server/fleet/openframe_windows_mdm.go`),
written by OpenFrame. A tenant row is seeded without an org name and a server URL, so a pinned config
update accepts them empty as long as the row never had them (`openframeTenantNeverHad`); a tenant that
written by OpenFrame. A tenant row is seeded without an org name and a server URL, so in shared mode
a pinned config update accepts them empty as long as the row never had them (`openframeTenantNeverHad`); a tenant that
has them still can't clear them. Every Windows MDM URL is built from it
(`server/service/openframe_windows_mdm.go`): the discovery URL in the pinned orbit config; the policy
and enroll URLs of discovery, which the middleware pins by the gateway's `X-Tenant-Id` (the only
Expand Down
69 changes: 69 additions & 0 deletions openframe/docs/windows-disk-encryption.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# 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. The move lifts the old tenant's requirement in the same row, which keeps the old tenant: a consumer of the
row sees the requirement end. 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 or the host left MDM. 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. Outside MDM only a key is taken: an
error is refused, as upstream refuses everything.
- **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, and for a
request pinned to a tenant, it does not, on any platform: the serial can be another machine's, of the tenant or of
another one.

## Known limits

- A host that was deleted and enrolls again is a new host: it is not required, and its archived key stays under the old
host and is not found. Requiring the new host makes fleetd send a new key.
- 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, or the host leaves MDM, 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`)
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; 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; 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
5 changes: 5 additions & 0 deletions server/datastore/mysql/apple_mdm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4424,6 +4424,11 @@ func (ds *Datastore) MDMResetEnrollment(ctx context.Context, hostUUID string, sc
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).
Expand Down
11 changes: 9 additions & 2 deletions server/datastore/mysql/disk_encryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ LIMIT 1`

var key fleet.HostArchivedDiskEncryptionKey
err := sqlx.GetContext(ctx, ds.reader(ctx), &key, fmt.Sprintf(sqlFmt, `WHERE host_id = ?`), host.ID)
if err == sql.ErrNoRows && host.HardwareSerial != "" {
// >>> OPENFRAME(windows-disk-encryption): in OpenFrame mode or pinned to a tenant a key is never looked up by serial: it can be another machine's, of any tenant — openframe/docs/windows-disk-encryption.md
if err == sql.ErrNoRows && host.HardwareSerial != "" && openframeArchivedKeyBySerial(ctx) {
// <<< OPENFRAME(windows-disk-encryption)
// If we didn't find a key by host ID, try to find it by hardware serial.
ds.logger.DebugContext(ctx, "get archived disk encryption key by host serial", "serial", host.HardwareSerial, "host_id", host.ID)
err = sqlx.GetContext(ctx, ds.reader(ctx), &key, fmt.Sprintf(sqlFmt, `WHERE hardware_serial = ?`), host.HardwareSerial)
Expand Down Expand Up @@ -380,5 +382,10 @@ func bulkDeleteHostDiskEncryptionKeysDB(ctx context.Context, tx sqlx.ExtContext,
}

_, err = tx.ExecContext(ctx, deleteStmt, deleteArgs...)
return err
// >>> OPENFRAME(windows-disk-encryption): the result goes with the key — openframe/docs/windows-disk-encryption.md
if err != nil {
return err
}
return openframeClearDiskEncryptionResults(ctx, tx, hostIDs)
// <<< OPENFRAME(windows-disk-encryption)
}
6 changes: 6 additions & 0 deletions server/datastore/mysql/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ var hostRefs = []string{
"host_disks",
"host_updates",
"host_disk_encryption_keys",
"openframe_host_disk_encryption", // OPENFRAME(windows-disk-encryption)
"host_software_installed_paths",
"host_software_windows_details", // OPENFRAME(software-windows-details)
"query_results",
Expand Down Expand Up @@ -3735,6 +3736,11 @@ func (ds *Datastore) AddHostsToTeam(ctx context.Context, params *fleet.AddHostsT
if err := cleanupDiskEncryptionKeysOnTeamChangeDB(ctx, tx, hostIDsBatch, teamID); err != nil {
return ctxerr.Wrap(ctx, err, "AddHostsToTeam cleanup disk encryption keys")
}
// >>> OPENFRAME(windows-disk-encryption): the tenant a host left no longer requires it — openframe/docs/windows-disk-encryption.md
if err := openframeLiftDiskEncryptionOnTeamChange(ctx, tx, hostIDsBatch, teamID); err != nil {
return ctxerr.Wrap(ctx, err, "AddHostsToTeam lift disk encryption requirement")
}
// <<< OPENFRAME(windows-disk-encryption)

return nil
},
Expand Down
7 changes: 7 additions & 0 deletions server/datastore/mysql/hosts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9400,6 +9400,13 @@ func testHostsDeleteHosts(t *testing.T, ds *Datastore) {
Username: "test-user",
}}, fleet.HostCertificateOriginOsquery))

// OPENFRAME(windows-disk-encryption)
_, err = ds.writer(context.Background()).Exec(`
INSERT INTO openframe_host_disk_encryption (host_id, team_id, required)
VALUES (?, ?, 1);
`, host.ID, team.ID)
require.NoError(t, err)

// create an android device from this host
deviceID := strings.ReplaceAll(uuid.NewString(), "-", "")
_, err = ds.writer(context.Background()).Exec(`
Expand Down
4 changes: 3 additions & 1 deletion server/datastore/mysql/microsoft_mdm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,9 @@ func (ds *Datastore) GetMDMWindowsBitLockerStatus(ctx context.Context, host *fle
return nil, nil
}

diskEncryptionConfig, err := ds.GetConfigEnableDiskEncryption(ctx, host.TeamID)
// >>> OPENFRAME(windows-disk-encryption): in OpenFrame mode the host's own requirement, not its team's — openframe/docs/windows-disk-encryption.md
diskEncryptionConfig, err := ds.openframeDiskEncryptionConfig(ctx, host)
// <<< OPENFRAME(windows-disk-encryption)
if err != nil {
return nil, err
}
Expand Down
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
}
Comment thread
andrii-flamingo marked this conversation as resolved.
Resolved
Comment thread
andrii-flamingo marked this conversation as resolved.
Resolved

func Down_20261201000001(tx *sql.Tx) error {
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func TestAllOpenframeMigrationsRegistered(t *testing.T) {
20261123000001, // WidenSoftwareCveId
20261123000002, // AddHostEnrollOwnersTable
20261127000001, // AddTeamIdToMdmWindowsEnrollments
20261201000001, // AddHostDiskEncryptionTable
}

var got []int64
Expand Down
Loading
Loading