Skip to content
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

SE: CLI setup experience changes #22956

Merged
merged 29 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3853841
Add macos setup fields to yaml struct
mna Oct 16, 2024
1d0a09b
Adjust all fleetctl tests
mna Oct 16, 2024
003ae35
Fix missing software/scripts in fleetctl get teams in yaml format
mna Oct 16, 2024
0c7cce7
Add mdm software slice to cloner implementation
mna Oct 16, 2024
8dd4e4f
Comment-out tests that cause OOM
mna Oct 16, 2024
bdd60e5
Fix other service test
mna Oct 16, 2024
25f48b2
Some pointers for implementation
mna Oct 16, 2024
fb2239c
Add support to set the setup experience script for a team
mna Oct 21, 2024
0684f23
Support matching software package by referenced yaml path
mna Oct 21, 2024
05a4eaa
Setting install_during_setup works for a team with software packages
mna Oct 21, 2024
1f4bd19
Software setup works for a team, not for no team
mna Oct 22, 2024
eb22853
Fix mysql tests
mna Oct 22, 2024
de0bae1
Remove debug log
mna Oct 22, 2024
22551a9
Fix integration test
mna Oct 22, 2024
bda9a2e
Add viaGitOps arg to ApplyGroup, use it to guard gitops-only features
mna Oct 22, 2024
6142738
Make it all work for no team too
mna Oct 22, 2024
4b6f21f
Add changes file
mna Oct 22, 2024
989062f
Remove obsolete todo
mna Oct 22, 2024
f3cf436
Fix fleetctl tests
mna Oct 22, 2024
a0094a0
Merge branch 'feat-setup-experience' into mna-22385-cli-setup-experience
mna Oct 22, 2024
07bab9e
Address unrelated lint issues
mna Oct 22, 2024
0ca593f
Fix stray paste
mna Oct 22, 2024
16da8a4
Some more lint fixes
mna Oct 23, 2024
9881f06
Fix conflict in schema
mna Oct 23, 2024
07de1b6
More lint
mna Oct 23, 2024
00c25a3
Fix conflict
mna Oct 23, 2024
2f0d46c
Merge branch 'feat-setup-experience' into mna-22385-cli-setup-experience
mna Oct 23, 2024
aed8653
Merge branch 'feat-setup-experience' into mna-22385-cli-setup-experience
mna Oct 23, 2024
779f998
Clarify comment for the marshal dance
mna Oct 23, 2024
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 changes/22385-cli-gitops-macos-setup-software-and-script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Added support to `fleetctl gitops` to specify a setup experience script to run and software to install, for a team or no team.
2 changes: 1 addition & 1 deletion cmd/fleetctl/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func applyCommand() *cli.Command {
teamsSoftwareInstallers := make(map[string][]fleet.SoftwarePackageResponse)
teamsScripts := make(map[string][]fleet.ScriptResponse)

_, _, _, err = fleetClient.ApplyGroup(c.Context, specs, baseDir, logf, nil, opts, teamsSoftwareInstallers, teamsScripts)
_, _, _, err = fleetClient.ApplyGroup(c.Context, false, specs, baseDir, logf, nil, opts, teamsSoftwareInstallers, teamsScripts)
if err != nil {
return err
}
Expand Down
15 changes: 15 additions & 0 deletions cmd/fleetctl/gitops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ func TestGitOpsBasicTeam(t *testing.T) {
ds.ListSoftwareTitlesFunc = func(ctx context.Context, opt fleet.SoftwareTitleListOptions, tmFilter fleet.TeamFilter) ([]fleet.SoftwareTitleListResult, int, *fleet.PaginationMetadata, error) {
return nil, 0, nil, nil
}
ds.DeleteSetupExperienceScriptFunc = func(ctx context.Context, teamID *uint) error {
return nil
}

tmpFile, err := os.CreateTemp(t.TempDir(), "*.yml")
require.NoError(t, err)
Expand Down Expand Up @@ -903,6 +906,9 @@ func TestGitOpsFullTeam(t *testing.T) {
ds.ListSoftwareTitlesFunc = func(ctx context.Context, opt fleet.SoftwareTitleListOptions, tmFilter fleet.TeamFilter) ([]fleet.SoftwareTitleListResult, int, *fleet.PaginationMetadata, error) {
return nil, 0, nil, nil
}
ds.DeleteSetupExperienceScriptFunc = func(ctx context.Context, teamID *uint) error {
return nil
}

startSoftwareInstallerServer(t)

Expand Down Expand Up @@ -1159,6 +1165,9 @@ func TestGitOpsBasicGlobalAndTeam(t *testing.T) {
ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) {
return []*fleet.ABMToken{}, nil
}
ds.DeleteSetupExperienceScriptFunc = func(ctx context.Context, teamID *uint) error {
return nil
}

globalFile, err := os.CreateTemp(t.TempDir(), "*.yml")
require.NoError(t, err)
Expand Down Expand Up @@ -1437,6 +1446,9 @@ func TestGitOpsBasicGlobalAndNoTeam(t *testing.T) {
ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) {
return []*fleet.ABMToken{}, nil
}
ds.DeleteSetupExperienceScriptFunc = func(ctx context.Context, teamID *uint) error {
return nil
}

globalFileBasic, err := os.CreateTemp(t.TempDir(), "*.yml")
require.NoError(t, err)
Expand Down Expand Up @@ -2354,6 +2366,9 @@ func setupFullGitOpsPremiumServer(t *testing.T) (*mock.Store, **fleet.AppConfig,
ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) {
return []*fleet.ABMToken{}, nil
}
ds.DeleteSetupExperienceScriptFunc = func(ctx context.Context, teamID *uint) error {
return nil
}

t.Setenv("FLEET_SERVER_URL", fleetServerURL)
t.Setenv("ORG_NAME", orgName)
Expand Down
2 changes: 1 addition & 1 deletion cmd/fleetctl/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ Use the stop and reset subcommands to manage the server and dependencies once st
// so pass in the current working directory.
teamsSoftwareInstallers := make(map[string][]fleet.SoftwarePackageResponse)
teamsScripts := make(map[string][]fleet.ScriptResponse)
_, _, _, err = client.ApplyGroup(c.Context, specs, ".", logf, nil, fleet.ApplyClientSpecOptions{}, teamsSoftwareInstallers, teamsScripts)
_, _, _, err = client.ApplyGroup(c.Context, false, specs, ".", logf, nil, fleet.ApplyClientSpecOptions{}, teamsSoftwareInstallers, teamsScripts)
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/fleetctl/testdata/expectedGetConfigAppConfigJson.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@
"bootstrap_package": null,
"enable_end_user_authentication": false,
"macos_setup_assistant": null,
"enable_release_device_manually": false
"enable_release_device_manually": false,
"script": null,
"software": null
},
"windows_settings": {
"custom_settings": null
Expand Down
2 changes: 2 additions & 0 deletions cmd/fleetctl/testdata/expectedGetConfigAppConfigYaml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ spec:
enable_end_user_authentication: false
enable_release_device_manually: false
macos_setup_assistant:
script:
software:
windows_settings:
custom_settings: null
end_user_authentication:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@
"bootstrap_package": null,
"enable_end_user_authentication": false,
"macos_setup_assistant": null,
"enable_release_device_manually": false
"enable_release_device_manually": false,
"script": null,
"software": null
},
"windows_settings": {
"custom_settings": null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ spec:
enable_end_user_authentication: false
enable_release_device_manually: false
macos_setup_assistant:
script:
software:
windows_settings:
custom_settings:
end_user_authentication:
Expand Down
8 changes: 6 additions & 2 deletions cmd/fleetctl/testdata/expectedGetTeamsJson.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
"bootstrap_package": null,
"enable_end_user_authentication": false,
"macos_setup_assistant": null,
"enable_release_device_manually": false
"enable_release_device_manually": false,
"script": null,
"software": null
},
"windows_settings": {
"custom_settings": null
Expand Down Expand Up @@ -137,7 +139,9 @@
"bootstrap_package": null,
"enable_end_user_authentication": false,
"macos_setup_assistant": null,
"enable_release_device_manually": false
"enable_release_device_manually": false,
"script": null,
"software": null
},
"windows_settings": {
"custom_settings": null
Expand Down
4 changes: 4 additions & 0 deletions cmd/fleetctl/testdata/expectedGetTeamsYaml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ spec:
enable_end_user_authentication: false
enable_release_device_manually: false
macos_setup_assistant:
script:
software:
scripts: null
secrets: null
webhook_settings:
Expand Down Expand Up @@ -84,6 +86,8 @@ spec:
enable_end_user_authentication: false
enable_release_device_manually: false
macos_setup_assistant:
script:
software:
scripts: null
webhook_settings:
host_status_webhook: null
Expand Down
2 changes: 2 additions & 0 deletions cmd/fleetctl/testdata/macosSetupExpectedAppConfigEmpty.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ spec:
enable_end_user_authentication: false
macos_setup_assistant: null
enable_release_device_manually: false
script: null
software: null
macos_updates:
deadline: null
minimum_version: null
Expand Down
2 changes: 2 additions & 0 deletions cmd/fleetctl/testdata/macosSetupExpectedAppConfigSet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ spec:
enable_end_user_authentication: false
macos_setup_assistant: %s
enable_release_device_manually: false
script: null
software: null
macos_updates:
deadline: null
minimum_version: null
Expand Down
4 changes: 4 additions & 0 deletions cmd/fleetctl/testdata/macosSetupExpectedTeam1And2Empty.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ spec:
enable_end_user_authentication: false
macos_setup_assistant: null
enable_release_device_manually: false
script: null
software: null
macos_updates:
deadline: null
minimum_version: null
Expand Down Expand Up @@ -62,6 +64,8 @@ spec:
bootstrap_package: null
macos_setup_assistant: null
enable_release_device_manually: false
script: null
software: null
macos_updates:
deadline: null
minimum_version: null
Expand Down
4 changes: 4 additions & 0 deletions cmd/fleetctl/testdata/macosSetupExpectedTeam1And2Set.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ spec:
enable_end_user_authentication: false
macos_setup_assistant: %s
enable_release_device_manually: false
script: null
software: null
macos_updates:
deadline: null
minimum_version: null
Expand Down Expand Up @@ -62,6 +64,8 @@ spec:
bootstrap_package: %s
macos_setup_assistant: %s
enable_release_device_manually: false
script: null
software: null
macos_updates:
deadline: null
minimum_version: null
Expand Down
2 changes: 2 additions & 0 deletions cmd/fleetctl/testdata/macosSetupExpectedTeam1Empty.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ spec:
enable_end_user_authentication: false
macos_setup_assistant: null
enable_release_device_manually: false
script: null
software: null
macos_updates:
deadline: null
minimum_version: null
Expand Down
2 changes: 2 additions & 0 deletions cmd/fleetctl/testdata/macosSetupExpectedTeam1Set.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ spec:
enable_end_user_authentication: false
macos_setup_assistant: %s
enable_release_device_manually: false
script: null
software: null
macos_updates:
deadline: null
minimum_version: null
Expand Down
19 changes: 10 additions & 9 deletions ee/server/service/software_installers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1301,15 +1301,16 @@ func (svc *Service) softwareBatchUpload(
}

installer := &fleet.UploadSoftwareInstallerPayload{
TeamID: teamID,
InstallScript: p.InstallScript,
PreInstallQuery: p.PreInstallQuery,
PostInstallScript: p.PostInstallScript,
UninstallScript: p.UninstallScript,
InstallerFile: bytes.NewReader(bodyBytes),
SelfService: p.SelfService,
UserID: userID,
URL: p.URL,
TeamID: teamID,
InstallScript: p.InstallScript,
PreInstallQuery: p.PreInstallQuery,
PostInstallScript: p.PostInstallScript,
UninstallScript: p.UninstallScript,
InstallerFile: bytes.NewReader(bodyBytes),
SelfService: p.SelfService,
UserID: userID,
URL: p.URL,
InstallDuringSetup: p.InstallDuringSetup,
}

// set the filename before adding metadata, as it is used as fallback
Expand Down
9 changes: 9 additions & 0 deletions ee/server/service/teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,15 @@ func (svc *Service) editTeamFromSpec(
}
}

// if the setup experience script was cleared, remove it for that team
if spec.MDM.MacOSSetup.Script.Set &&
spec.MDM.MacOSSetup.Script.Value == "" &&
oldMacOSSetup.Script.Value != "" {
if err := svc.DeleteSetupExperienceScript(ctx, &team.ID); err != nil {
return ctxerr.Wrapf(ctx, err, "clear setup experience script for team %d", team.ID)
}
}

if didUpdateMacOSEndUserAuth {
if err := svc.updateMacOSSetupEnableEndUserAuth(
ctx, spec.MDM.MacOSSetup.EnableEndUserAuthentication, &team.ID, &team.Name,
Expand Down
32 changes: 21 additions & 11 deletions ee/server/service/vpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ func (svc *Service) BatchAssociateVPPApps(ctx context.Context, teamName string,
SelfService: false,
Platform: fleet.IPadOSPlatform,
}, {
AppStoreID: payload.AppStoreID,
SelfService: payload.SelfService,
Platform: fleet.MacOSPlatform,
AppStoreID: payload.AppStoreID,
SelfService: payload.SelfService,
Platform: fleet.MacOSPlatform,
InstallDuringSetup: payload.InstallDuringSetup,
}}...)
}

Expand All @@ -101,7 +102,14 @@ func (svc *Service) BatchAssociateVPPApps(ctx context.Context, teamName string,
return fleet.NewInvalidArgumentError("app_store_apps.platform",
fmt.Sprintf("platform must be one of '%s', '%s', or '%s", fleet.IOSPlatform, fleet.IPadOSPlatform, fleet.MacOSPlatform))
}
vppAppTeams = append(vppAppTeams, fleet.VPPAppTeam{VPPAppID: fleet.VPPAppID{AdamID: payload.AppStoreID, Platform: payload.Platform}, SelfService: payload.SelfService})
vppAppTeams = append(vppAppTeams, fleet.VPPAppTeam{
VPPAppID: fleet.VPPAppID{
AdamID: payload.AppStoreID,
Platform: payload.Platform,
},
SelfService: payload.SelfService,
InstallDuringSetup: payload.InstallDuringSetup,
})
}

var missingAssets []string
Expand Down Expand Up @@ -374,14 +382,15 @@ func (svc *Service) AddAppStoreApp(ctx context.Context, teamID *uint, appID flee
func getVPPAppsMetadata(ctx context.Context, ids []fleet.VPPAppTeam) ([]*fleet.VPPApp, error) {
var apps []*fleet.VPPApp

// Map of adamID to platform, then to whether it's available as self-service.
adamIDMap := make(map[string]map[fleet.AppleDevicePlatform]bool)
// Map of adamID to platform, then to whether it's available as self-service
// and installed during setup.
adamIDMap := make(map[string]map[fleet.AppleDevicePlatform]fleet.VPPAppTeam)
for _, id := range ids {
if _, ok := adamIDMap[id.AdamID]; !ok {
adamIDMap[id.AdamID] = make(map[fleet.AppleDevicePlatform]bool, 1)
adamIDMap[id.AdamID][id.Platform] = id.SelfService
adamIDMap[id.AdamID] = make(map[fleet.AppleDevicePlatform]fleet.VPPAppTeam, 1)
adamIDMap[id.AdamID][id.Platform] = fleet.VPPAppTeam{SelfService: id.SelfService, InstallDuringSetup: id.InstallDuringSetup}
} else {
adamIDMap[id.AdamID][id.Platform] = id.SelfService
adamIDMap[id.AdamID][id.Platform] = fleet.VPPAppTeam{SelfService: id.SelfService, InstallDuringSetup: id.InstallDuringSetup}
}
}

Expand All @@ -397,14 +406,15 @@ func getVPPAppsMetadata(ctx context.Context, ids []fleet.VPPAppTeam) ([]*fleet.V
for adamID, metadata := range assetMetatada {
platforms := getPlatformsFromSupportedDevices(metadata.SupportedDevices)
for platform := range platforms {
if selfService, ok := adamIDMap[adamID][platform]; ok {
if props, ok := adamIDMap[adamID][platform]; ok {
app := &fleet.VPPApp{
VPPAppTeam: fleet.VPPAppTeam{
VPPAppID: fleet.VPPAppID{
AdamID: adamID,
Platform: platform,
},
SelfService: selfService,
SelfService: props.SelfService,
InstallDuringSetup: props.InstallDuringSetup,
},
BundleIdentifier: metadata.BundleID,
IconURL: metadata.ArtworkURL,
Expand Down
3 changes: 2 additions & 1 deletion pkg/spec/gitops.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,8 @@ func parseSoftware(top map[string]json.RawMessage, result *GitOps, baseDir strin
for _, item := range software.Packages {
var softwarePackageSpec fleet.SoftwarePackageSpec
if item.Path != nil {
fileBytes, err := os.ReadFile(resolveApplyRelativePath(baseDir, *item.Path))
softwarePackageSpec.ReferencedYamlPath = resolveApplyRelativePath(baseDir, *item.Path)
fileBytes, err := os.ReadFile(softwarePackageSpec.ReferencedYamlPath)
if err != nil {
multiError = multierror.Append(multiError, fmt.Errorf("failed to read policies file %s: %v", *item.Path, err))
continue
Expand Down
Loading
Loading