add missing IDP required check for OTA profiles (#44644)

Found this missed TODO from some old story work.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## 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.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Magnus Jensen
2026-05-04 15:43:34 +02:00
committed by GitHub
parent 2ee5404ed3
commit 888ee793e6
2 changed files with 24 additions and 2 deletions
+11 -2
View File
@@ -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 {
@@ -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