Skip to content

Commit 2522cc5

Browse files
authored
Recategorize MDM endpoints to new mdm-less paths (#17372)
1 parent c358bde commit 2522cc5

17 files changed

+431
-210
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Migrate MDM-related endpoints to new paths, deprecating (but still supporting indefinitely) the old endpoints.

ee/server/service/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func NewService(
6868
svc.SetEnterpriseOverrides(fleet.EnterpriseOverrides{
6969
HostFeatures: eeservice.HostFeatures,
7070
TeamByIDOrName: eeservice.teamByIDOrName,
71-
UpdateTeamMDMAppleSettings: eeservice.updateTeamMDMAppleSettings,
71+
UpdateTeamMDMDiskEncryption: eeservice.updateTeamMDMDiskEncryption,
7272
MDMAppleEnableFileVaultAndEscrow: eeservice.MDMAppleEnableFileVaultAndEscrow,
7373
MDMAppleDisableFileVaultAndEscrow: eeservice.MDMAppleDisableFileVaultAndEscrow,
7474
DeleteMDMAppleSetupAssistant: eeservice.DeleteMDMAppleSetupAssistant,

ee/server/service/teams.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,11 +1181,11 @@ func unmarshalWithGlobalDefaults(b *json.RawMessage) (fleet.Features, error) {
11811181
return *defaults, nil
11821182
}
11831183

1184-
func (svc *Service) updateTeamMDMAppleSettings(ctx context.Context, tm *fleet.Team, payload fleet.MDMAppleSettingsPayload) error {
1184+
func (svc *Service) updateTeamMDMDiskEncryption(ctx context.Context, tm *fleet.Team, enable *bool) error {
11851185
var didUpdate, didUpdateMacOSDiskEncryption bool
1186-
if payload.EnableDiskEncryption != nil {
1187-
if tm.Config.MDM.EnableDiskEncryption != *payload.EnableDiskEncryption {
1188-
tm.Config.MDM.EnableDiskEncryption = *payload.EnableDiskEncryption
1186+
if enable != nil {
1187+
if tm.Config.MDM.EnableDiskEncryption != *enable {
1188+
tm.Config.MDM.EnableDiskEncryption = *enable
11891189
didUpdate = true
11901190
didUpdateMacOSDiskEncryption = true
11911191
}

server/fleet/service.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import (
1818
type EnterpriseOverrides struct {
1919
HostFeatures func(context context.Context, host *Host) (*Features, error)
2020
TeamByIDOrName func(ctx context.Context, id *uint, name *string) (*Team, error)
21-
// UpdateTeamMDMAppleSettings is the team-specific service method for when
22-
// a team ID is provided to the UpdateMDMAppleSettings method.
23-
UpdateTeamMDMAppleSettings func(ctx context.Context, tm *Team, payload MDMAppleSettingsPayload) error
21+
// UpdateTeamMDMDiskEncryption is the team-specific service method for when
22+
// a team ID is provided to the UpdateMDMDiskEncryption method.
23+
UpdateTeamMDMDiskEncryption func(ctx context.Context, tm *Team, enable *bool) error
2424

2525
// The next two functions are implemented by the ee/service, and called
2626
// properly when called from an ee/service method (e.g. Modify Team), but
@@ -761,9 +761,9 @@ type Service interface {
761761
// profile for the given team.
762762
MDMAppleDisableFileVaultAndEscrow(ctx context.Context, teamID *uint) error
763763

764-
// UpdateMDMAppleSettings updates the specified MDM Apple settings for a
764+
// UpdateMDMDiskEncryption updates the disk encryption setting for a
765765
// specified team or for hosts with no team.
766-
UpdateMDMAppleSettings(ctx context.Context, payload MDMAppleSettingsPayload) error
766+
UpdateMDMDiskEncryption(ctx context.Context, teamID *uint, enableDiskEncryption *bool) error
767767

768768
// VerifyMDMAppleConfigured verifies that the server is configured for
769769
// Apple MDM. If an error is returned, authorization is skipped so the

server/service/apple_mdm.go

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,37 +1631,13 @@ func (r updateMDMAppleSettingsResponse) Status() int { return http.StatusNoConte
16311631
// team endpoints only allow write access to admins.
16321632
func updateMDMAppleSettingsEndpoint(ctx context.Context, request interface{}, svc fleet.Service) (errorer, error) {
16331633
req := request.(*updateMDMAppleSettingsRequest)
1634-
if err := svc.UpdateMDMAppleSettings(ctx, req.MDMAppleSettingsPayload); err != nil {
1634+
if err := svc.UpdateMDMDiskEncryption(ctx, req.MDMAppleSettingsPayload.TeamID, req.MDMAppleSettingsPayload.EnableDiskEncryption); err != nil {
16351635
return updateMDMAppleSettingsResponse{Err: err}, nil
16361636
}
16371637
return updateMDMAppleSettingsResponse{}, nil
16381638
}
16391639

1640-
func (svc *Service) UpdateMDMAppleSettings(ctx context.Context, payload fleet.MDMAppleSettingsPayload) error {
1641-
// for now, assume all settings require premium (this is true for the first
1642-
// supported setting, enable_disk_encryption. Adjust as needed in the future
1643-
// if this is not always the case).
1644-
lic, _ := license.FromContext(ctx)
1645-
if lic == nil || !lic.IsPremium() {
1646-
svc.authz.SkipAuthorization(ctx) // so that the error message is not replaced by "forbidden"
1647-
return ErrMissingLicense
1648-
}
1649-
1650-
if err := svc.authz.Authorize(ctx, payload, fleet.ActionWrite); err != nil {
1651-
return ctxerr.Wrap(ctx, err)
1652-
}
1653-
1654-
if payload.TeamID != nil {
1655-
tm, err := svc.EnterpriseOverrides.TeamByIDOrName(ctx, payload.TeamID, nil)
1656-
if err != nil {
1657-
return err
1658-
}
1659-
return svc.EnterpriseOverrides.UpdateTeamMDMAppleSettings(ctx, tm, payload)
1660-
}
1661-
return svc.updateAppConfigMDMAppleSettings(ctx, payload)
1662-
}
1663-
1664-
func (svc *Service) updateAppConfigMDMAppleSettings(ctx context.Context, payload fleet.MDMAppleSettingsPayload) error {
1640+
func (svc *Service) updateAppConfigMDMDiskEncryption(ctx context.Context, enabled *bool) error {
16651641
// appconfig is only used internally, it's fine to read it unobfuscated
16661642
// (svc.AppConfigObfuscated must not be used because the write-only users
16671643
// such as gitops will fail to access it).
@@ -1671,9 +1647,9 @@ func (svc *Service) updateAppConfigMDMAppleSettings(ctx context.Context, payload
16711647
}
16721648

16731649
var didUpdate, didUpdateMacOSDiskEncryption bool
1674-
if payload.EnableDiskEncryption != nil {
1675-
if ac.MDM.EnableDiskEncryption.Value != *payload.EnableDiskEncryption {
1676-
ac.MDM.EnableDiskEncryption = optjson.SetBool(*payload.EnableDiskEncryption)
1650+
if enabled != nil {
1651+
if ac.MDM.EnableDiskEncryption.Value != *enabled {
1652+
ac.MDM.EnableDiskEncryption = optjson.SetBool(*enabled)
16771653
didUpdate = true
16781654
didUpdateMacOSDiskEncryption = true
16791655
}

server/service/apple_mdm_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,7 @@ func TestUpdateMDMAppleSettings(t *testing.T) {
19031903
}
19041904
ctx = license.NewContext(ctx, &fleet.LicenseInfo{Tier: tier})
19051905

1906-
err := svc.UpdateMDMAppleSettings(ctx, fleet.MDMAppleSettingsPayload{TeamID: tt.teamID})
1906+
err := svc.UpdateMDMDiskEncryption(ctx, tt.teamID, nil)
19071907
if tt.wantErr == "" {
19081908
require.NoError(t, err)
19091909
return

0 commit comments

Comments
 (0)