@@ -903,22 +903,27 @@ func (svc *Service) DeleteMDMAppleDeclaration(ctx context.Context, declUUID stri
903
903
return ctxerr .Wrap (ctx , err )
904
904
}
905
905
906
- if _ , ok := mdm_types .FleetReservedProfileNames ()[decl .Name ]; ok {
907
- return & fleet.BadRequestError {
908
- Message : "profiles managed by Fleet can't be deleted using this endpoint." ,
909
- InternalErr : fmt .Errorf ("deleting profile %s is not allowed because it's managed by Fleet" , decl .Name ),
906
+ // Check if the declaration contains a secret variable. If it does, this means that the declaration
907
+ // has been provided by the user and can be deleted. We don't need to validate that it is a Fleet declaration.
908
+ hasSecretVariable := len (fleet .ContainsPrefixVars (string (decl .RawJSON ), fleet .ServerSecretPrefix )) > 0
909
+ if ! hasSecretVariable {
910
+ if _ , ok := mdm_types .FleetReservedProfileNames ()[decl .Name ]; ok {
911
+ return & fleet.BadRequestError {
912
+ Message : "profiles managed by Fleet can't be deleted using this endpoint." ,
913
+ InternalErr : fmt .Errorf ("deleting profile %s is not allowed because it's managed by Fleet" , decl .Name ),
914
+ }
910
915
}
911
- }
912
916
913
- // TODO: refine our approach to deleting restricted/forbidden types of declarations so that we
914
- // can check that Fleet-managed aren't being deleted; this can be addressed once we add support
915
- // for more types of declarations
916
- var d fleet.MDMAppleRawDeclaration
917
- if err := json .Unmarshal (decl .RawJSON , & d ); err != nil {
918
- return ctxerr .Wrap (ctx , err , "unmarshalling declaration" )
919
- }
920
- if err := d .ValidateUserProvided (); err != nil {
921
- return ctxerr .Wrap (ctx , & fleet.BadRequestError {Message : err .Error ()})
917
+ // TODO: refine our approach to deleting restricted/forbidden types of declarations so that we
918
+ // can check that Fleet-managed aren't being deleted; this can be addressed once we add support
919
+ // for more types of declarations
920
+ var d fleet.MDMAppleRawDeclaration
921
+ if err := json .Unmarshal (decl .RawJSON , & d ); err != nil {
922
+ return ctxerr .Wrap (ctx , err , "unmarshalling declaration" )
923
+ }
924
+ if err := d .ValidateUserProvided (); err != nil {
925
+ return ctxerr .Wrap (ctx , & fleet.BadRequestError {Message : err .Error ()})
926
+ }
922
927
}
923
928
924
929
var teamName string
0 commit comments