-
Notifications
You must be signed in to change notification settings - Fork 1
fix(OPENFRAM-010-2): CU-86akbhhtv 4 review findings in 20250731151000_EnforceFileVaultAtLogin.go #164
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
base: main
Are you sure you want to change the base?
fix(OPENFRAM-010-2): CU-86akbhhtv 4 review findings in 20250731151000_EnforceFileVaultAtLogin.go #164
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ import ( | |
| ) | ||
|
|
||
| func init() { | ||
| MigrationClient.AddMigration(Up_20250723111413, Down_20250723111413) | ||
| MigrationClient.AddMigration(Up_20250731151000, Down_20250731151000) | ||
| } | ||
|
|
||
| // enforceFileVaultAtLogin is used to set | ||
|
|
@@ -31,6 +31,7 @@ func enforceFileVaultAtLogin(original []byte) ([]byte, error) { | |
| return nil, errors.New("failed to access PayloadContent element") | ||
| } | ||
|
|
||
| found := false | ||
| for _, c := range payloadContent { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π enforceFileVaultAtLogin does not validate that any payload actually matched com.apple.MCX.FileVault2 In π€ Prompt for AI agentsfix confidence: π‘ 75 medium β react π/π to teach the reviewer |
||
| payload, ok := c.(map[string]interface{}) | ||
| if !ok { | ||
|
|
@@ -39,9 +40,14 @@ func enforceFileVaultAtLogin(original []byte) ([]byte, error) { | |
|
|
||
| if payload["PayloadType"] == "com.apple.MCX.FileVault2" { | ||
| payload["DeferForceAtUserLoginMaxBypassAttempts"] = 0 | ||
| found = true | ||
| } | ||
| } | ||
|
|
||
| if !found { | ||
| return nil, errors.New("failed to find com.apple.MCX.FileVault2 payload in profile") | ||
| } | ||
|
|
||
| out, err := plist.MarshalIndent(configuration, " ") | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to marshal new payload: %w", err) | ||
|
|
@@ -50,7 +56,7 @@ func enforceFileVaultAtLogin(original []byte) ([]byte, error) { | |
| return out, nil | ||
| } | ||
|
|
||
| func Up_20250723111413(tx *sql.Tx) error { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π΄ FileVault migration is not idempotent β reapplies DeferForceAtUserLoginMaxBypassAttempts=0 unconditionally on every run No explicit idempotency guard was added around the plist mutation itself, since the finding's premise (a re-run could double-apply changes) can't be fully addressed here: setting π€ Prompt for AI agentsfix confidence: π΄ 35 low β review closely β react π/π to teach the reviewer |
||
| func Up_20250731151000(tx *sql.Tx) error { | ||
| // Idempotent migration. | ||
| txx := sqlx.Tx{Tx: tx, Mapper: reflectx.NewMapperFunc("db", sqlx.NameMapper)} | ||
|
|
||
|
|
@@ -79,7 +85,7 @@ CREATE TABLE IF NOT EXISTS legacy_host_filevault_profiles ( | |
| return err | ||
| } | ||
|
|
||
| _, err = txx.Exec(` | ||
| res, err := txx.Exec(` | ||
| INSERT IGNORE INTO legacy_host_filevault_profiles | ||
| (host_uuid, status, operation_type, profile_uuid, detail, command_uuid, scope, created_at, updated_at) | ||
| SELECT | ||
|
|
@@ -99,6 +105,25 @@ CREATE TABLE IF NOT EXISTS legacy_host_filevault_profiles ( | |
| return fmt.Errorf("inserting legacy filevault profile hosts %w", err) | ||
| } | ||
|
|
||
| legacyRowsAffected, err := res.RowsAffected() | ||
| if err != nil { | ||
| return fmt.Errorf("getting rows affected for legacy filevault profile hosts insert: %w", err) | ||
| } | ||
|
|
||
| var legacyHostCount int | ||
| if err := txx.Get(&legacyHostCount, ` | ||
| SELECT COUNT(*) FROM host_mdm_apple_profiles WHERE profile_identifier = 'com.fleetdm.fleet.mdm.filevault' | ||
| `); err != nil { | ||
| return fmt.Errorf("counting host_mdm_apple_profiles filevault rows: %w", err) | ||
| } | ||
|
|
||
| if legacyHostCount > 0 && legacyRowsAffected == 0 { | ||
| return fmt.Errorf( | ||
| "expected to back up %d filevault host profile rows into legacy_host_filevault_profiles but inserted 0", | ||
| legacyHostCount, | ||
| ) | ||
| } | ||
|
|
||
| fvProfiles := []struct { | ||
| ID uint `db:"profile_id"` | ||
| Mobileconfig []byte `db:"mobileconfig"` | ||
|
Comment on lines
105
to
129
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π FileVault migration silently returns nil when zero profiles found, skipping legacy-table population verification In π€ Prompt for AI agentsfix confidence: π΄ 40 low β review closely β react π/π to teach the reviewer |
||
|
|
@@ -132,6 +157,6 @@ CREATE TABLE IF NOT EXISTS legacy_host_filevault_profiles ( | |
| return nil | ||
| } | ||
|
|
||
| func Down_20250723111413(tx *sql.Tx) error { | ||
| func Down_20250731151000(tx *sql.Tx) error { | ||
| return nil | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
𦩠π΄ Migration file name timestamp does not match its internal function/init timestamp identifiers
Renamed
Up_20250723111413/Down_20250723111413toUp_20250731151000/Down_20250731151000and updated theinit()call toMigrationClient.AddMigration(Up_20250731151000, Down_20250731151000), so the internal identifiers now match the filename timestamp 20250731151000.π€ Prompt for AI agents
fix confidence: π’ 90 high β react π/π to teach the reviewer