-
Notifications
You must be signed in to change notification settings - Fork 625
Add VPP policy automation support to backend #25154
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
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
33e6aea
Add changes file, migration for VPP policy automation (#23529)
iansltx 3e52848
Start building policy VPP association load/save
iansltx ce558a2
Implement VPP automation visibility on policy object, implement orbit…
iansltx 621f6f4
Allow multi-platform and "macos" filtering on software titles, includ…
iansltx fa1c4a8
Fix linting issues
iansltx 68a54e1
Fix core test issues
iansltx c4a5f6a
Fix integration tests
iansltx 97400f4
Switch to vpp_apps_teams_id fkey on policies table rather than join t…
iansltx a0ca81b
Drop VPPAppsTeamsID from comparison for equality check in VPP metadat…
iansltx 9c311f7
Merge branch 'main' into 23115-vpp-policy-be, renumber migration
iansltx 08b566f
Error when deleting a single policy-associated VPP app, clear policy …
iansltx c7dae46
Add tests other than integration test, fix bugs found in automated te…
iansltx 5ffa085
Lint fix
iansltx 92bdd78
Merge branch 'main' into 23115-vpp-policy-be
iansltx 3306f85
Update audit logs docs
iansltx a384c97
Add more tests, fix bugs found by tests
iansltx ac7f860
Add remaining data store tests for VPP automation
iansltx 82b06cf
Merge branch 'main' into 23115-vpp-policy-be
iansltx 35258f3
Revise error message on get VPP title info from VPP apps team ID
iansltx 6e3e01f
Note new API capability in changes file
iansltx 28763a5
Tweak changes file
iansltx d7775b3
Add integration test, fix bugs found by integration test, don't queue…
iansltx 87b3219
Fix lint issues
iansltx 06eedd0
Add more test coverage, fix variable naming
iansltx 6028d05
Lint fix
iansltx 1ce8ab5
Merge branch 'main' into 23115-vpp-policy-be
iansltx ec21ec3
Add missing automatic install policies on single software title endpo…
iansltx 4900d95
Add test for individual software title response to ensure automatic i…
iansltx 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 hidden or 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,2 @@ | ||
* Added ability to install VPP apps on policy failure | ||
* Allowed filtering titles by "any of these platforms" in `GET /api/v1/fleet/software/titles` |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
34 changes: 34 additions & 0 deletions
34
server/datastore/mysql/migrations/tables/20250110205257_PolicyAutomationInstallVPP.go
This file contains hidden or 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,34 @@ | ||
package tables | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
) | ||
|
||
func init() { | ||
MigrationClient.AddMigration(Up_20250110205257, Down_20250110205257) | ||
} | ||
|
||
func Up_20250110205257(tx *sql.Tx) error { | ||
if _, err := tx.Exec(` | ||
ALTER TABLE policies | ||
ADD COLUMN vpp_apps_teams_id INT UNSIGNED DEFAULT NULL, | ||
ADD FOREIGN KEY fk_policies_vpp_apps_team_id (vpp_apps_teams_id) REFERENCES vpp_apps_teams (id); | ||
`); err != nil { | ||
return fmt.Errorf("failed to add vpp_apps_teams_id to policies: %w", err) | ||
} | ||
|
||
if _, err := tx.Exec(` | ||
ALTER TABLE host_vpp_software_installs | ||
ADD COLUMN policy_id INT UNSIGNED DEFAULT NULL, | ||
ADD FOREIGN KEY fk_host_vpp_software_installs_policy_id (policy_id) REFERENCES policies (id) ON DELETE SET NULL | ||
`); err != nil { | ||
return fmt.Errorf("failed to add policy_id to host VPP software installs: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func Down_20250110205257(tx *sql.Tx) error { | ||
return nil | ||
} |
99 changes: 99 additions & 0 deletions
99
server/datastore/mysql/migrations/tables/20250110205257_PolicyAutomationInstallVPP_test.go
This file contains hidden or 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,99 @@ | ||
package tables | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/fleetdm/fleet/v4/server/fleet" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestUp_20250110205257(t *testing.T) { | ||
db := applyUpToPrev(t) | ||
|
||
// Create user | ||
u1 := execNoErrLastID(t, db, `INSERT INTO users (name, email, password, salt) VALUES (?, ?, ?, ?)`, "u1", "u1@b.c", "1234", "salt") | ||
|
||
// insert a team | ||
teamID := execNoErrLastID(t, db, `INSERT INTO teams (name) VALUES ("Foo")`) | ||
|
||
// Create host | ||
insertHostStmt := ` | ||
INSERT INTO hosts ( | ||
hostname, uuid, platform, osquery_version, os_version, build, platform_like, code_name, | ||
cpu_type, cpu_subtype, cpu_brand, hardware_vendor, hardware_model, hardware_version, | ||
hardware_serial, computer_name, team_id | ||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) | ||
` | ||
hostName := "Dummy Hostname" | ||
hostUUID := "12345678-1234-1234-1234-123456789012" | ||
hostPlatform := "ios" | ||
osqueryVer := "5.9.1" | ||
osVersion := "Windows 10" | ||
buildVersion := "10.0.19042.1234" | ||
platformLike := "apple" | ||
codeName := "20H2" | ||
cpuType := "x86_64" | ||
cpuSubtype := "x86_64" | ||
cpuBrand := "Intel" | ||
hwVendor := "Dell Inc." | ||
hwModel := "OptiPlex 7090" | ||
hwVersion := "1.0" | ||
hwSerial := "ABCDEFGHIJ" | ||
computerName := "DESKTOP-TEST" | ||
|
||
hostID := execNoErrLastID(t, db, insertHostStmt, hostName, hostUUID, hostPlatform, osqueryVer, | ||
osVersion, buildVersion, platformLike, codeName, cpuType, cpuSubtype, cpuBrand, hwVendor, hwModel, hwVersion, hwSerial, computerName, teamID) | ||
|
||
// Create VPP app, token, and associated team | ||
adamID := "a" | ||
execNoErr( | ||
t, db, `INSERT INTO vpp_apps (adam_id, platform) VALUES (?,?)`, adamID, hostPlatform, | ||
) | ||
vppTokenID := execNoErrLastID(t, db, ` | ||
INSERT INTO vpp_tokens ( | ||
organization_name, | ||
location, | ||
renew_at, | ||
token | ||
) VALUES | ||
(?, ?, ?, ?) | ||
`, | ||
"org1", "loc1", "2030-01-01 10:10:10", "blob1", | ||
) | ||
|
||
vppAppsTeamsID := execNoErrLastID( | ||
t, | ||
db, | ||
`INSERT INTO vpp_apps_teams (adam_id, platform, global_or_team_id, team_id, vpp_token_id) VALUES (?,?,?,?,?)`, | ||
adamID, | ||
fleet.IOSPlatform, | ||
teamID, | ||
teamID, | ||
vppTokenID, | ||
) | ||
|
||
// Apply current migration. | ||
applyNext(t, db) | ||
|
||
// create a policy associated with a VPP apps teams record | ||
policyID := execNoErrLastID(t, db, `INSERT INTO policies (name, query, description, team_id, vpp_apps_teams_id, checksum) | ||
VALUES ('test_policy', "SELECT 1", "", ?, ?, "a123b123")`, teamID, vppAppsTeamsID) | ||
|
||
// create a VPP install with the policy ID | ||
hvsi1 := execNoErrLastID(t, db, `INSERT INTO host_vpp_software_installs (host_id, adam_id, platform, command_uuid, user_id, policy_id) VALUES (?,?,?,?,?, ?)`, hostID, adamID, hostPlatform, "command_uuid", u1, policyID) | ||
|
||
// attempt to delete the VPP app; should error | ||
_, err := db.Exec(`DELETE FROM vpp_apps_teams WHERE id = ?`, vppAppsTeamsID) | ||
require.Error(t, err) | ||
|
||
// delete the policy | ||
execNoErr(t, db, `DELETE FROM policies WHERE id = ?`, policyID) | ||
|
||
// confirm that the policy ID on the existing install is null | ||
var retrievedPolicyID *uint | ||
require.NoError(t, db.Get(&retrievedPolicyID, `SELECT policy_id FROM host_vpp_software_installs WHERE id = ?`, hvsi1)) | ||
require.Nil(t, retrievedPolicyID) | ||
|
||
// attempt to delete the VPP app; should succeed | ||
execNoErr(t, db, `DELETE FROM vpp_apps_teams WHERE id = ?`, vppAppsTeamsID) | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.