Alerting: Fix prometheus API to check folder permissions (#36301)

This commit is contained in:
Sofia Papagiannaki
2021-07-05 10:49:14 +03:00
committed by GitHub
parent 7fb233cfb1
commit 8a3edf280e
3 changed files with 156 additions and 1 deletions
@@ -2,6 +2,7 @@ package api
import (
"encoding/json"
"errors"
"fmt"
"net/http"
"time"
@@ -76,6 +77,13 @@ func (srv PrometheusSrv) RouteGetRuleStatuses(c *models.ReqContext) response.Res
continue
}
groupId, namespaceUID, namespace := r[0], r[1], r[2]
if _, err := srv.store.GetNamespaceByUID(namespaceUID, c.SignedInUser.OrgId, c.SignedInUser); err != nil {
if errors.Is(err, models.ErrFolderAccessDenied) {
// do not include it in the response
continue
}
return toNamespaceErrorResponse(err)
}
alertRuleQuery := ngmodels.ListRuleGroupAlertRulesQuery{OrgID: c.SignedInUser.OrgId, NamespaceUID: namespaceUID, RuleGroup: groupId}
if err := srv.store.GetRuleGroupAlertRules(&alertRuleQuery); err != nil {
ruleResponse.DiscoveryBase.Status = "error"