-
Notifications
You must be signed in to change notification settings - Fork 392
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
Fetch installed apps from iPhone/iPad devices. #20733
Merged
+788
−95
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
804a175
Fetch installed apps from iPhone/iPad devices.
getvictor 7f4a18c
osquery-perf updates
getvictor fce85aa
osquery-perf fixes and doc update
getvictor 74baf86
Support unique titles for iOS and iPadOS for the same bundle identifier.
getvictor 7e8d84b
Unique titles tests and bug fixes.
getvictor 308627b
Increased timestamp precision in nano queue
getvictor 238017f
Some test refactoring.
getvictor bbba104
set title id on duplicate key
roperzh beb5a57
Merge remote-tracking branch 'origin/main' into 20468-ios-apps
roperzh 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 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
- iOS and iPadOS device details refetch can now be triggered with the existing `POST /api/latest/fleet/hosts/:id/refetch` endpoint. | ||
- iOS and iPadOS user-installed apps can be viewed in Fleet |
This file contains 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 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 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 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 |
---|---|---|
|
@@ -500,6 +500,26 @@ func (c *TestAppleMDMClient) AcknowledgeDeviceInformation(udid, cmdUUID, deviceN | |
return c.sendAndDecodeCommandResponse(payload) | ||
} | ||
|
||
func (c *TestAppleMDMClient) AcknowledgeInstalledApplicationList(udid, cmdUUID string, software []fleet.Software) (*mdm.Command, error) { | ||
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. my personal preference would be to keep the methods of the |
||
mdmSoftware := make([]map[string]interface{}, 0, len(software)) | ||
for _, s := range software { | ||
mdmSoftware = append(mdmSoftware, map[string]interface{}{ | ||
"Name": s.Name, | ||
"ShortVersion": s.Version, | ||
"Identifier": s.BundleIdentifier, | ||
}) | ||
} | ||
|
||
payload := map[string]any{ | ||
"Status": "Acknowledged", | ||
"UDID": udid, | ||
"CommandUUID": cmdUUID, | ||
"InstalledApplicationList": mdmSoftware, | ||
} | ||
|
||
return c.sendAndDecodeCommandResponse(payload) | ||
} | ||
|
||
func (c *TestAppleMDMClient) GetBootstrapToken() ([]byte, error) { | ||
payload := map[string]any{ | ||
"MessageType": "GetBootstrapToken", | ||
|
45 changes: 45 additions & 0 deletions
45
...tastore/mysql/migrations/tables/20240725182118_AddAdditionalIdentifierToSoftwareTitles.go
This file contains 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,45 @@ | ||
package tables | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
) | ||
|
||
func init() { | ||
MigrationClient.AddMigration(Up_20240725182118, Down_20240725182118) | ||
} | ||
|
||
func Up_20240725182118(tx *sql.Tx) error { | ||
if columnExists(tx, "software_titles", "additional_identifier") { | ||
return nil | ||
} | ||
|
||
_, err := tx.Exec(` | ||
ALTER TABLE software_titles | ||
ADD COLUMN additional_identifier TINYINT UNSIGNED GENERATED ALWAYS AS | ||
(CASE | ||
WHEN source = 'ios_apps' then 1 | ||
WHEN source = 'ipados_apps' then 2 | ||
WHEN bundle_identifier IS NOT NULL THEN 0 | ||
ELSE NULL | ||
END) VIRTUAL`) | ||
if err != nil { | ||
return fmt.Errorf("adding additional_identifier to software_titles: %w", err) | ||
} | ||
|
||
_, err = tx.Exec(`ALTER TABLE software_titles DROP INDEX idx_software_titles_bundle_identifier`) | ||
if err != nil { | ||
return fmt.Errorf("dropping unique key for bundle_identifier in software_titles: %w", err) | ||
} | ||
|
||
_, err = tx.Exec(`ALTER TABLE software_titles ADD UNIQUE KEY idx_software_titles_bundle_identifier (bundle_identifier, additional_identifier)`) | ||
if err != nil { | ||
return fmt.Errorf("adding unique key for identifiers in software_titles: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func Down_20240725182118(_ *sql.Tx) error { | ||
return nil | ||
} |
86 changes: 86 additions & 0 deletions
86
...re/mysql/migrations/tables/20240725182118_AddAdditionalIdentifierToSoftwareTitles_test.go
This file contains 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,86 @@ | ||
package tables | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/fleetdm/fleet/v4/server/ptr" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestUp_20240725182118(t *testing.T) { | ||
db := applyUpToPrev(t) | ||
|
||
// Data before ios and ipados apps were added | ||
dataStmt := ` | ||
INSERT INTO software_titles (id, name, source, browser, bundle_identifier) VALUES | ||
(1, 'Foo.app', 'apps', '', 'com.example.foo'), | ||
(2, 'Foo2.app', 'apps', '', 'com.example.foo2'), | ||
(3, 'Chrome Extension', 'chrome_extensions', 'chrome', NULL), | ||
(4, 'Microsoft Teams.exe', 'programs', '', NULL); | ||
` | ||
|
||
_, err := db.Exec(dataStmt) | ||
require.NoError(t, err) | ||
applyNext(t, db) | ||
|
||
type softwareTitle struct { | ||
Name string `db:"name"` | ||
Source string `db:"source"` | ||
Browser string `db:"browser"` | ||
BundleIdentifier *string `db:"bundle_identifier"` | ||
AdditionalIdentifier *uint32 `db:"additional_identifier"` | ||
} | ||
|
||
var titles []softwareTitle | ||
err = db.Select(&titles, `SELECT name, source, browser, bundle_identifier, additional_identifier FROM software_titles`) | ||
require.NoError(t, err) | ||
zero := uint32(0) | ||
expectedTitles := []softwareTitle{ | ||
{"Foo.app", "apps", "", ptr.String("com.example.foo"), &zero}, | ||
{"Foo2.app", "apps", "", ptr.String("com.example.foo2"), &zero}, | ||
{"Chrome Extension", "chrome_extensions", "chrome", nil, nil}, | ||
{"Microsoft Teams.exe", "programs", "", nil, nil}, | ||
} | ||
assert.ElementsMatch(t, expectedTitles, titles) | ||
|
||
// Ensure that the unique key is enforced | ||
dataStmt = ` | ||
INSERT INTO software_titles (id, name, source, browser, bundle_identifier) VALUES | ||
(100, 'Foo3', 'foo', '', 'com.example.foo'); | ||
` | ||
_, err = db.Exec(dataStmt) | ||
assert.ErrorContains(t, err, "Duplicate entry") | ||
|
||
// Add ios and ipados apps | ||
dataStmt = ` | ||
INSERT INTO software_titles (id, name, source, browser, bundle_identifier) VALUES | ||
(5, 'Foo', 'ios_apps', '', 'com.example.foo'), | ||
(6, 'Foo', 'ipados_apps', '', 'com.example.foo'), | ||
(7, 'Bar-Pocket', 'ios_apps', '', 'com.example.bar-pocket'), | ||
(8, 'Bar', 'ipados_apps', '', 'com.example.bar'); | ||
` | ||
_, err = db.Exec(dataStmt) | ||
require.NoError(t, err) | ||
|
||
err = db.Select(&titles, `SELECT name, source, browser, bundle_identifier, additional_identifier FROM software_titles`) | ||
require.NoError(t, err) | ||
one := uint32(1) | ||
two := uint32(2) | ||
expectedTitles = append(expectedTitles, []softwareTitle{ | ||
{"Foo", "ios_apps", "", ptr.String("com.example.foo"), &one}, | ||
{"Foo", "ipados_apps", "", ptr.String("com.example.foo"), &two}, | ||
{"Bar-Pocket", "ios_apps", "", ptr.String("com.example.bar-pocket"), &one}, | ||
{"Bar", "ipados_apps", "", ptr.String("com.example.bar"), &two}, | ||
}...) | ||
assert.ElementsMatch(t, expectedTitles, titles) | ||
|
||
// Ensure that the unique key is enforced | ||
dataStmt = ` | ||
INSERT INTO software_titles (id, name, source, browser, bundle_identifier) VALUES | ||
(200, 'Foo-Pocket', 'ipados_apps', '', 'com.example.foo'); | ||
` | ||
_, err = db.Exec(dataStmt) | ||
assert.ErrorContains(t, err, "Duplicate entry") | ||
|
||
} |
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.
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.
leftover?
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.
Yes, I'll clean up in the next PR.