diff --git a/pkg/services/ngalert/accesscontrol.go b/pkg/services/ngalert/accesscontrol.go index 31fe1bdc8941f..44e3cf2141730 100644 --- a/pkg/services/ngalert/accesscontrol.go +++ b/pkg/services/ngalert/accesscontrol.go @@ -181,7 +181,7 @@ var ( }, }, }, - Grants: []string{string(org.RoleAdmin)}, + Grants: []string{string(org.RoleEditor), string(org.RoleAdmin)}, // LOGZ.IO GRAFANA CHANGE :: DEV-46158 - Allow editors to manage alerting provisioning } alertingProvisioningReaderWithSecretsRole = accesscontrol.RoleRegistration{ diff --git a/pkg/tests/api/alerting/api_provisioning_test.go b/pkg/tests/api/alerting/api_provisioning_test.go index c0f7e6a48084a..6b804ef55724d 100644 --- a/pkg/tests/api/alerting/api_provisioning_test.go +++ b/pkg/tests/api/alerting/api_provisioning_test.go @@ -108,15 +108,17 @@ func TestIntegrationProvisioning(t *testing.T) { require.Equal(t, 403, resp.StatusCode) }) - t.Run("editor GET should 403", func(t *testing.T) { + // LOGZ.IO GRAFANA CHANGE :: DEV-46158 - Allow editors to manage alerting provisioning + t.Run("editor GET should succeed", func(t *testing.T) { req := createTestRequest("GET", url, "editor", "") resp, err := http.DefaultClient.Do(req) require.NoError(t, err) require.NoError(t, resp.Body.Close()) - require.Equal(t, 403, resp.StatusCode) + require.Equal(t, 200, resp.StatusCode) }) + // LOGZ.IO GRAFANA CHANGE :: End t.Run("admin GET should succeed", func(t *testing.T) { req := createTestRequest("GET", url, "admin", "") @@ -148,15 +150,17 @@ func TestIntegrationProvisioning(t *testing.T) { require.Equal(t, 403, resp.StatusCode) }) - t.Run("editor PUT should 403", func(t *testing.T) { + // LOGZ.IO GRAFANA CHANGE :: DEV-46158 - Allow editors to manage alerting provisioning + t.Run("editor PUT should succeed", func(t *testing.T) { req := createTestRequest("PUT", url, "editor", body) resp, err := http.DefaultClient.Do(req) require.NoError(t, err) require.NoError(t, resp.Body.Close()) - require.Equal(t, 403, resp.StatusCode) + require.Equal(t, 202, resp.StatusCode) }) + // LOGZ.IO GRAFANA CHANGE :: End t.Run("admin PUT should succeed", func(t *testing.T) { req := createTestRequest("PUT", url, "admin", body) @@ -200,15 +204,17 @@ func TestIntegrationProvisioning(t *testing.T) { require.Equal(t, 403, resp.StatusCode) }) - t.Run("editor GET should 403", func(t *testing.T) { + // LOGZ.IO GRAFANA CHANGE :: DEV-46158 - Allow editors to manage alerting provisioning + t.Run("editor GET should succeed", func(t *testing.T) { req := createTestRequest("GET", url, "editor", "") resp, err := http.DefaultClient.Do(req) require.NoError(t, err) require.NoError(t, resp.Body.Close()) - require.Equal(t, 403, resp.StatusCode) + require.Equal(t, 200, resp.StatusCode) }) + // LOGZ.IO GRAFANA CHANGE :: End t.Run("admin GET should succeed", func(t *testing.T) { req := createTestRequest("GET", url, "admin", "") @@ -240,15 +246,17 @@ func TestIntegrationProvisioning(t *testing.T) { require.Equal(t, 403, resp.StatusCode) }) - t.Run("editor POST should 403", func(t *testing.T) { + // LOGZ.IO GRAFANA CHANGE :: DEV-46158 - Allow editors to manage alerting provisioning + t.Run("editor POST should succeed", func(t *testing.T) { req := createTestRequest("POST", url, "editor", body) resp, err := http.DefaultClient.Do(req) require.NoError(t, err) require.NoError(t, resp.Body.Close()) - require.Equal(t, 403, resp.StatusCode) + require.Equal(t, 202, resp.StatusCode) }) + // LOGZ.IO GRAFANA CHANGE :: End t.Run("admin POST should succeed", func(t *testing.T) { req := createTestRequest("POST", url, "admin", body) @@ -284,15 +292,17 @@ func TestIntegrationProvisioning(t *testing.T) { require.Equal(t, 403, resp.StatusCode) }) - t.Run("editor GET should 403", func(t *testing.T) { + // LOGZ.IO GRAFANA CHANGE :: DEV-46158 - Allow editors to manage alerting provisioning + t.Run("editor GET should succeed", func(t *testing.T) { req := createTestRequest("GET", url, "editor", "") resp, err := http.DefaultClient.Do(req) require.NoError(t, err) require.NoError(t, resp.Body.Close()) - require.Equal(t, 403, resp.StatusCode) + require.Equal(t, 200, resp.StatusCode) }) + // LOGZ.IO GRAFANA CHANGE :: End t.Run("admin GET should succeed", func(t *testing.T) { req := createTestRequest("GET", url, "admin", "") @@ -328,15 +338,17 @@ func TestIntegrationProvisioning(t *testing.T) { require.Equal(t, 403, resp.StatusCode) }) - t.Run("editor GET should 403", func(t *testing.T) { + // LOGZ.IO GRAFANA CHANGE :: DEV-46158 - Allow editors to manage alerting provisioning + t.Run("editor GET should succeed", func(t *testing.T) { req := createTestRequest("GET", url, "editor", "") resp, err := http.DefaultClient.Do(req) require.NoError(t, err) require.NoError(t, resp.Body.Close()) - require.Equal(t, 403, resp.StatusCode) + require.Equal(t, 200, resp.StatusCode) }) + // LOGZ.IO GRAFANA CHANGE :: End t.Run("admin GET should succeed", func(t *testing.T) { req := createTestRequest("GET", url, "admin", "") diff --git a/pkg/tsdb/elasticsearch/elasticsearch.go b/pkg/tsdb/elasticsearch/elasticsearch.go index bc9138c657692..9be05a2ef15e3 100644 --- a/pkg/tsdb/elasticsearch/elasticsearch.go +++ b/pkg/tsdb/elasticsearch/elasticsearch.go @@ -6,6 +6,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/grafana/grafana/pkg/models" // LOGZ.IO GRAFANA CHANGE :: DEV-43889 - Add headers for logzio datasources support "io" "net/http" "net/url" @@ -225,6 +226,13 @@ func (s *Service) CallResource(ctx context.Context, req *backend.CallResourceReq logger.Debug("Sending request to Elasticsearch", "resourcePath", req.Path) start := time.Now() + + // LOGZ.IO GRAFANA CHANGE :: DEV-43889 - Add headers for logzio datasources support + logzIoHeaders := &models.LogzIoHeaders{RequestHeaders: req.Headers} + request.Header = logzIoHeaders.GetDatasourceQueryHeaders(request.Header) + request.Header.Set("Content-Type", "application/json") + logger.Debug("request details", "headers", request.Header, "url", request.URL.String()) + // LOGZ.IO GRAFANA CHANGE :: End response, err := ds.HTTPClient.Do(request) if err != nil { status := "error"