Alerting: Relax permissions for access a rule (#103664)
This makes it so that it is: - No longer required to have datasource permissions to delete a rule. - No longer required to have datasource permissions to update non-query related fields of a rule.
This commit is contained in:
@@ -145,23 +145,12 @@ func (srv RulerSrv) RouteDeleteAlertRules(c *contextmodel.ReqContext, namespaceU
|
||||
}
|
||||
rulesToDelete := make([]string, 0)
|
||||
provisioned := false
|
||||
auth := true
|
||||
for groupKey, rules := range deletionCandidates {
|
||||
if containsProvisionedAlerts(provenances, rules) {
|
||||
logger.Debug("Alert group cannot be deleted because it is provisioned", "group", groupKey.RuleGroup)
|
||||
provisioned = true
|
||||
continue
|
||||
}
|
||||
// XXX: Currently delete requires data source query access to all rules in the group.
|
||||
if err := srv.authz.AuthorizeDatasourceAccessForRuleGroup(ctx, c.SignedInUser, rules); err != nil {
|
||||
if errors.Is(err, authz.ErrAuthorizationBase) {
|
||||
logger.Debug("User is not authorized to delete rules in the group", "group", groupKey.RuleGroup)
|
||||
auth = false
|
||||
continue
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
uid := make([]string, 0, len(rules))
|
||||
for _, rule := range rules {
|
||||
uid = append(uid, rule.UID)
|
||||
@@ -177,17 +166,10 @@ func (srv RulerSrv) RouteDeleteAlertRules(c *contextmodel.ReqContext, namespaceU
|
||||
return nil
|
||||
}
|
||||
// if none rules were deleted return an error.
|
||||
|
||||
// Check whether provisioned check failed first because if it is true, then all rules that the user can access (actually read via GET API) are provisioned.
|
||||
if provisioned {
|
||||
return errProvisionedResource
|
||||
}
|
||||
|
||||
// If auth is false, then the user is not authorized to delete any of the rules.
|
||||
if !auth {
|
||||
return authz.NewAuthorizationErrorGeneric("delete any existing rules in the namespace")
|
||||
}
|
||||
|
||||
logger.Info("No alert rules were deleted")
|
||||
return nil
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user