From 888ee793e629ba43bd5d5e35493a2d88f9c34bb2 Mon Sep 17 00:00:00 2001 From: Magnus Jensen Date: Mon, 4 May 2026 07:43:34 -0600 Subject: [PATCH] add missing IDP required check for OTA profiles (#44644) Found this missed TODO from some old story work. ## Summary by CodeRabbit * **Bug Fixes** * Enhanced OTA enrollment profile validation to properly enforce end-user authentication requirements when configured, now returning appropriate error responses for requests missing required authentication credentials. --- server/service/apple_mdm.go | 13 +++++++++++-- server/service/integration_mdm_profiles_test.go | 13 +++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/server/service/apple_mdm.go b/server/service/apple_mdm.go index f3c290c9fb..27378399e8 100644 --- a/server/service/apple_mdm.go +++ b/server/service/apple_mdm.go @@ -6961,8 +6961,17 @@ func (svc *Service) GetOTAProfile(ctx context.Context, enrollSecret, idpUUID str return nil, ctxerr.Wrap(ctx, err, "getting app config to get org name") } - // TODO(IB): Validate that the IdpUUID should be populated based on the criteria for showing the SSO in the first place - // Should be added with the work of #30660 or afterwars. + requiresIDPUUID, err := shared_mdm.RequiresEnrollOTAAuthentication(ctx, svc.ds, enrollSecret, cfg.MDM.MacOSSetup.EnableEndUserAuthentication) + if err != nil { + return nil, ctxerr.Wrap(ctx, err, "checking if IDP UUID is required for OTA enrollment") + } + if requiresIDPUUID && idpUUID == "" { + return nil, ctxerr.Wrap( + ctx, + authz.ForbiddenWithInternal("required idp uuid to be set, but none found", nil, nil, nil), + "missing required idp uuid", + ) + } profBytes, err := apple_mdm.GenerateOTAEnrollmentProfileMobileconfig(cfg.OrgInfo.OrgName, cfg.MDMUrl(), enrollSecret, idpUUID) if err != nil { diff --git a/server/service/integration_mdm_profiles_test.go b/server/service/integration_mdm_profiles_test.go index 49e0c48d92..c3dad91f0e 100644 --- a/server/service/integration_mdm_profiles_test.go +++ b/server/service/integration_mdm_profiles_test.go @@ -6410,6 +6410,19 @@ func (s *integrationMDMTestSuite) TestOTAProfile() { require.NotContains(t, string(b), "idp_uuid=") require.Contains(t, string(b), cfg.OrgInfo.OrgName) }) + + t.Run("returns 403 if no idp_uuid is set when required by config", func(t *testing.T) { + // update config to require idp_uuid + cfg.MDM.MacOSSetup.EnableEndUserAuthentication = true + err := s.ds.SaveAppConfig(ctx, cfg) + require.NoError(t, err) + t.Cleanup(func() { + cfg.MDM.MacOSSetup.EnableEndUserAuthentication = false + err := s.ds.SaveAppConfig(ctx, cfg) + require.NoError(t, err) + }) + s.Do("GET", "/api/latest/fleet/enrollment_profiles/ota", &getOTAProfileRequest{}, http.StatusForbidden, "enroll_secret", globalEnrollSec) + }) } // TestAppleDDMSecretVariablesUpload tests uploading DDM profiles with secrets via the /configuration_profiles endpoint