Fixing Fleet variable validation in <data> (#27604)

For #27603

Only fixing the UI issue. GitOps also has this issue, but GitOps does
not validate Fleet variables locally, so not an easy fix.

# Checklist for submitter
- [x] Manual QA for all new/changed functionality
- [x] For unreleased bug fixes in a release candidate, confirmed that
the fix is not expected to adversely impact load test results or alerted
the release DRI if additional load testing is needed.
This commit is contained in:
Victor Lyuboslavsky 2025-03-27 17:27:58 -05:00 committed by GitHub
parent db485718e9
commit 54e18d87bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -397,6 +397,17 @@ func (svc *Service) NewMDMAppleConfigProfile(ctx context.Context, teamID uint, r
return nil, ctxerr.Wrap(ctx, fleet.NewInvalidArgumentError("profile", err.Error()))
}
// We validate Fleet variables before we unmarshal the profile because bad variables can break unmarshal.
// For example: <data>$FLEET_VAR_BOZO</data>
appConfig, err := svc.ds.AppConfig(ctx)
if err != nil {
return nil, ctxerr.Wrap(ctx, err)
}
err = validateConfigProfileFleetVariables(appConfig, expanded)
if err != nil {
return nil, ctxerr.Wrap(ctx, err, "validating fleet variables")
}
cp, err := fleet.NewMDMAppleConfigProfile([]byte(expanded), &teamID)
if err != nil {
return nil, ctxerr.Wrap(ctx, &fleet.BadRequestError{
@ -410,14 +421,6 @@ func (svc *Service) NewMDMAppleConfigProfile(ctx context.Context, teamID uint, r
}
return nil, ctxerr.Wrap(ctx, &fleet.BadRequestError{Message: err.Error()})
}
appConfig, err := svc.ds.AppConfig(ctx)
if err != nil {
return nil, ctxerr.Wrap(ctx, err)
}
err = validateConfigProfileFleetVariables(appConfig, string(cp.Mobileconfig))
if err != nil {
return nil, ctxerr.Wrap(ctx, err, "validating fleet variables")
}
// Save the original unexpanded profile
cp.Mobileconfig = b