SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
feat(authz): enable FGA for ingestion keys and limits (#12626)
Vikrant Gupta7faab60ea749
diff --git a/docs/api/openapi.yml b/docs/api/openapi.ymlindex c2bd5dc553..9c13b7e609 100644--- a/docs/api/openapi.yml+++ b/docs/api/openapi.yml@@ -16127,9 +16127,9 @@ paths:description: Internal Server Errorsecurity:- api_key:- - EDITOR+ - ingestion-key:list- tokenizer:- - EDITOR+ - ingestion-key:listsummary: Get ingestion keys for workspacetags:- gateway@@ -16177,9 +16177,9 @@ paths:description: Internal Server Errorsecurity:- api_key:- - EDITOR+ - ingestion-key:create- tokenizer:- - EDITOR+ - ingestion-key:createsummary: Create ingestion key for workspacetags:- gateway@@ -16217,9 +16217,9 @@ paths:description: Internal Server Errorsecurity:- api_key:- - EDITOR+ - ingestion-key:delete- tokenizer:- - EDITOR+ - ingestion-key:deletesummary: Delete ingestion key for workspacetags:- gateway@@ -16274,9 +16274,9 @@ paths:description: Internal Server Errorsecurity:- api_key:- - EDITOR+ - ingestion-key:read- tokenizer:- - EDITOR+ - ingestion-key:readsummary: Get ingestion key for workspacetags:- gateway@@ -16318,9 +16318,9 @@ paths:description: Internal Server Errorsecurity:- api_key:- - EDITOR+ - ingestion-key:update- tokenizer:- - EDITOR+ - ingestion-key:updatesummary: Update ingestion key for workspacetags:- gateway@@ -16379,15 +16379,15 @@ paths:description: Internal Server Errorsecurity:- api_key:- - EDITOR+ - ingestion-limit:list- tokenizer:- - EDITOR+ - ingestion-limit:listsummary: Get limits for the ingestion keytags:- gatewaypost:deprecated: true- description: This endpoint creates an ingestion key limit+ description: This endpoint creates an ingestion key limit.operationId: CreateIngestionKeyLimitparameters:- in: path@@ -16435,9 +16435,11 @@ paths:description: Internal Server Errorsecurity:- api_key:- - EDITOR+ - ingestion-limit:create+ - ingestion-key:attach- tokenizer:- - EDITOR+ - ingestion-limit:create+ - ingestion-key:attachsummary: Create limit for the ingestion keytags:- gateway@@ -16475,15 +16477,17 @@ paths:description: Internal Server Errorsecurity:- api_key:- - EDITOR+ - ingestion-limit:delete+ - ingestion-key:detach- tokenizer:- - EDITOR+ - ingestion-limit:delete+ - ingestion-key:detachsummary: Delete limit for the ingestion keytags:- gatewaypatch:deprecated: true- description: This endpoint updates an ingestion key limit+ description: This endpoint updates an ingestion key limit.operationId: UpdateIngestionKeyLimitparameters:- in: path@@ -16519,9 +16523,9 @@ paths:description: Internal Server Errorsecurity:- api_key:- - EDITOR+ - ingestion-limit:update- tokenizer:- - EDITOR+ - ingestion-limit:updatesummary: Update limit for the ingestion keytags:- gateway@@ -16579,9 +16583,9 @@ paths:description: Internal Server Errorsecurity:- api_key:- - EDITOR+ - ingestion-key:list- tokenizer:- - EDITOR+ - ingestion-key:listsummary: Search ingestion keys for workspacetags:- gateway@@ -16637,9 +16641,11 @@ paths:description: Internal Server Errorsecurity:- api_key:- - EDITOR+ - ingestion-limit:create+ - ingestion-key:attach- tokenizer:- - EDITOR+ - ingestion-limit:create+ - ingestion-key:attachsummary: Create ingestion limittags:- gateway@@ -16677,9 +16683,11 @@ paths:description: Internal Server Errorsecurity:- api_key:- - EDITOR+ - ingestion-limit:delete+ - ingestion-key:detach- tokenizer:- - EDITOR+ - ingestion-limit:delete+ - ingestion-key:detachsummary: Delete ingestion limittags:- gateway@@ -16734,9 +16742,9 @@ paths:description: Internal Server Errorsecurity:- api_key:- - EDITOR+ - ingestion-limit:read- tokenizer:- - EDITOR+ - ingestion-limit:readsummary: Get ingestion limittags:- gateway@@ -16778,9 +16786,9 @@ paths:description: Internal Server Errorsecurity:- api_key:- - EDITOR+ - ingestion-limit:update- tokenizer:- - EDITOR+ - ingestion-limit:updatesummary: Update ingestion limittags:- gatewaydiff --git a/frontend/src/api/generated/services/gateway/index.ts b/frontend/src/api/generated/services/gateway/index.tsindex f377455982..eafa0f640c 100644--- a/frontend/src/api/generated/services/gateway/index.ts+++ b/frontend/src/api/generated/services/gateway/index.ts@@ -614,7 +614,7 @@ export const invalidateGetIngestionKeyLimits = async (};/**- * This endpoint creates an ingestion key limit+ * This endpoint creates an ingestion key limit.* @deprecated* @summary Create limit for the ingestion key*/@@ -798,7 +798,7 @@ export const useDeleteIngestionKeyLimit = <return useMutation(getDeleteIngestionKeyLimitMutationOptions(options));};/**- * This endpoint updates an ingestion key limit+ * This endpoint updates an ingestion key limit.* @deprecated* @summary Update limit for the ingestion key*/diff --git a/pkg/apiserver/signozapiserver/gateway.go b/pkg/apiserver/signozapiserver/gateway.goindex 27cf75abe3..c3939d1f47 100644--- a/pkg/apiserver/signozapiserver/gateway.go+++ b/pkg/apiserver/signozapiserver/gateway.go@@ -5,250 +5,454 @@ import ("github.com/SigNoz/signoz/pkg/http/handler""github.com/SigNoz/signoz/pkg/types"+ "github.com/SigNoz/signoz/pkg/types/authtypes"+ "github.com/SigNoz/signoz/pkg/types/coretypes""github.com/SigNoz/signoz/pkg/types/gatewaytypes"+ "github.com/SigNoz/signoz/pkg/valuer""github.com/gorilla/mux")func (provider *provider) addGatewayRoutes(router *mux.Router) error {- if err := router.Handle("/api/v2/gateway/ingestion_keys", handler.New(provider.authzMiddleware.EditAccess(provider.gatewayHandler.GetIngestionKeys), handler.OpenAPIDef{- ID: "GetIngestionKeys",- Tags: []string{"gateway"},- Summary: "Get ingestion keys for workspace",- Description: "This endpoint returns the ingestion keys for a workspace",- Request: nil,- RequestQuery: new(gatewaytypes.IngestionKeysParams),- RequestContentType: "",- Response: new(gatewaytypes.GettableIngestionKeys),- ResponseContentType: "application/json",- SuccessStatusCode: http.StatusOK,- ErrorStatusCodes: []int{},- Deprecated: false,- SecuritySchemes: newSecuritySchemes(types.RoleEditor),- })).Methods(http.MethodGet).GetError(); err != nil {+ if err := router.Handle("/api/v2/gateway/ingestion_keys", handler.New(+ provider.authzMiddleware.CheckResources(provider.gatewayHandler.GetIngestionKeys, authtypes.SigNozAdminRoleName, authtypes.SigNozEditorRoleName),+ handler.OpenAPIDef{+ ID: "GetIngestionKeys",+ Tags: []string{"gateway"},+ Summary: "Get ingestion keys for workspace",+ Description: "This endpoint returns the ingestion keys for a workspace",+ Request: nil,+ RequestQuery: new(gatewaytypes.IngestionKeysParams),+ RequestContentType: "",+ Response: new(gatewaytypes.GettableIngestionKeys),+ ResponseContentType: "application/json",+ SuccessStatusCode: http.StatusOK,+ ErrorStatusCodes: []int{},+ Deprecated: false,+ SecuritySchemes: newScopedSecuritySchemes([]string{coretypes.ResourceMetaResourceIngestionKey.Scope(coretypes.VerbList)}),+ },+ handler.WithResourceDefs(handler.BasicResourceDef{+ Resource: coretypes.ResourceMetaResourceIngestionKey,+ Verb: coretypes.VerbList,+ Category: coretypes.ActionCategoryDataAccess,+ Selector: coretypes.WildcardSelector,+ }),+ )).Methods(http.MethodGet).GetError(); err != nil {return err}- if err := router.Handle("/api/v2/gateway/ingestion_keys/search", handler.New(provider.authzMiddleware.EditAccess(provider.gatewayHandler.SearchIngestionKeys), handler.OpenAPIDef{- ID: "SearchIngestionKeys",- Tags: []string{"gateway"},- Summary: "Search ingestion keys for workspace",- Description: "This endpoint returns the ingestion keys for a workspace",- Request: nil,- RequestQuery: new(gatewaytypes.SearchIngestionKeysParams),- RequestContentType: "",- Response: new(gatewaytypes.GettableIngestionKeys),- ResponseContentType: "application/json",- SuccessStatusCode: http.StatusOK,- ErrorStatusCodes: []int{},- Deprecated: false,- SecuritySchemes: newSecuritySchemes(types.RoleEditor),- })).Methods(http.MethodGet).GetError(); err != nil {+ if err := router.Handle("/api/v2/gateway/ingestion_keys/search", handler.New(+ provider.authzMiddleware.CheckResources(provider.gatewayHandler.SearchIngestionKeys, authtypes.SigNozAdminRoleName, authtypes.SigNozEditorRoleName),+ handler.OpenAPIDef{+ ID: "SearchIngestionKeys",+ Tags: []string{"gateway"},+ Summary: "Search ingestion keys for workspace",+ Description: "This endpoint returns the ingestion keys for a workspace",+ Request: nil,+ RequestQuery: new(gatewaytypes.SearchIngestionKeysParams),+ RequestContentType: "",+ Response: new(gatewaytypes.GettableIngestionKeys),+ ResponseContentType: "application/json",+ SuccessStatusCode: http.StatusOK,+ ErrorStatusCodes: []int{},+ Deprecated: false,+ SecuritySchemes: newScopedSecuritySchemes([]string{coretypes.ResourceMetaResourceIngestionKey.Scope(coretypes.VerbList)}),+ },+ handler.WithResourceDefs(handler.BasicResourceDef{+ Resource: coretypes.ResourceMetaResourceIngestionKey,+ Verb: coretypes.VerbList,+ Category: coretypes.ActionCategoryDataAccess,+ Selector: coretypes.WildcardSelector,+ }),+ )).Methods(http.MethodGet).GetError(); err != nil {return err}- if err := router.Handle("/api/v2/gateway/ingestion_keys", handler.New(provider.authzMiddleware.EditAccess(provider.gatewayHandler.CreateIngestionKey), handler.OpenAPIDef{- ID: "CreateIngestionKey",- Tags: []string{"gateway"},- Summary: "Create ingestion key for workspace",- Description: "This endpoint creates an ingestion key for the workspace",- Request: new(gatewaytypes.PostableIngestionKey),- RequestContentType: "application/json",- Response: new(gatewaytypes.GettableCreatedIngestionKey),- ResponseContentType: "application/json",- SuccessStatusCode: http.StatusCreated,- ErrorStatusCodes: []int{},- Deprecated: false,- SecuritySchemes: newSecuritySchemes(types.RoleEditor),- })).Methods(http.MethodPost).GetError(); err != nil {+ if err := router.Handle("/api/v2/gateway/ingestion_keys", handler.New(+ provider.authzMiddleware.CheckResources(provider.gatewayHandler.CreateIngestionKey, authtypes.SigNozAdminRoleName, authtypes.SigNozEditorRoleName),+ handler.OpenAPIDef{+ ID: "CreateIngestionKey",+ Tags: []string{"gateway"},+ Summary: "Create ingestion key for workspace",+ Description: "This endpoint creates an ingestion key for the workspace",+ Request: new(gatewaytypes.PostableIngestionKey),+ RequestContentType: "application/json",+ Response: new(gatewaytypes.GettableCreatedIngestionKey),+ ResponseContentType: "application/json",+ SuccessStatusCode: http.StatusCreated,+ ErrorStatusCodes: []int{},+ Deprecated: false,+ SecuritySchemes: newScopedSecuritySchemes([]string{coretypes.ResourceMetaResourceIngestionKey.Scope(coretypes.VerbCreate)}),+ },+ handler.WithResourceDefs(handler.BasicResourceDef{+ Resource: coretypes.ResourceMetaResourceIngestionKey,+ Verb: coretypes.VerbCreate,+ Category: coretypes.ActionCategoryConfigurationChange,+ ID: coretypes.ResponseJSONPath("data.id"),+ Selector: coretypes.WildcardSelector,+ }),+ )).Methods(http.MethodPost).GetError(); err != nil {return err}- if err := router.Handle("/api/v2/gateway/ingestion_keys/{keyId}", handler.New(provider.authzMiddleware.EditAccess(provider.gatewayHandler.UpdateIngestionKey), handler.OpenAPIDef{- ID: "UpdateIngestionKey",- Tags: []string{"gateway"},- Summary: "Update ingestion key for workspace",- Description: "This endpoint updates an ingestion key for the workspace",- Request: new(gatewaytypes.PostableIngestionKey),- RequestContentType: "application/json",- Response: nil,- ResponseContentType: "",- SuccessStatusCode: http.StatusNoContent,- ErrorStatusCodes: []int{},- Deprecated: false,- SecuritySchemes: newSecuritySchemes(types.RoleEditor),- })).Methods(http.MethodPatch).GetError(); err != nil {+ if err := router.Handle("/api/v2/gateway/ingestion_keys/{keyId}", handler.New(+ provider.authzMiddleware.CheckResources(provider.gatewayHandler.UpdateIngestionKey, authtypes.SigNozAdminRoleName, authtypes.SigNozEditorRoleName),+ handler.OpenAPIDef{+ ID: "UpdateIngestionKey",+ Tags: []string{"gateway"},+ Summary: "Update ingestion key for workspace",+ Description: "This endpoint updates an ingestion key for the workspace",+ Request: new(gatewaytypes.PostableIngestionKey),+ RequestContentType: "application/json",+ Response: nil,+ ResponseContentType: "",+ SuccessStatusCode: http.StatusNoContent,+ ErrorStatusCodes: []int{},+ Deprecated: false,+ SecuritySchemes: newScopedSecuritySchemes([]string{coretypes.ResourceMetaResourceIngestionKey.Scope(coretypes.VerbUpdate)}),+ },+ handler.WithResourceDefs(handler.BasicResourceDef{+ Resource: coretypes.ResourceMetaResourceIngestionKey,+ Verb: coretypes.VerbUpdate,+ Category: coretypes.ActionCategoryConfigurationChange,+ ID: coretypes.PathParam("keyId"),+ Selector: coretypes.IDSelector,+ }),+ )).Methods(http.MethodPatch).GetError(); err != nil {return err}- if err := router.Handle("/api/v2/gateway/ingestion_keys/{keyId}", handler.New(provider.authzMiddleware.EditAccess(provider.gatewayHandler.DeleteIngestionKey), handler.OpenAPIDef{- ID: "DeleteIngestionKey",- Tags: []string{"gateway"},- Summary: "Delete ingestion key for workspace",- Description: "This endpoint deletes an ingestion key for the workspace",- Request: nil,- RequestContentType: "",- Response: nil,- ResponseContentType: "",- SuccessStatusCode: http.StatusNoContent,- ErrorStatusCodes: []int{},- Deprecated: false,- SecuritySchemes: newSecuritySchemes(types.RoleEditor),- })).Methods(http.MethodDelete).GetError(); err != nil {+ if err := router.Handle("/api/v2/gateway/ingestion_keys/{keyId}", handler.New(+ provider.authzMiddleware.CheckResources(provider.gatewayHandler.DeleteIngestionKey, authtypes.SigNozAdminRoleName, authtypes.SigNozEditorRoleName),+ handler.OpenAPIDef{+ ID: "DeleteIngestionKey",+ Tags: []string{"gateway"},+ Summary: "Delete ingestion key for workspace",+ Description: "This endpoint deletes an ingestion key for the workspace",+ Request: nil,+ RequestContentType: "",+ Response: nil,+ ResponseContentType: "",+ SuccessStatusCode: http.StatusNoContent,+ ErrorStatusCodes: []int{},+ Deprecated: false,+ SecuritySchemes: newScopedSecuritySchemes([]string{coretypes.ResourceMetaResourceIngestionKey.Scope(coretypes.VerbDelete)}),+ },+ handler.WithResourceDefs(handler.BasicResourceDef{+ Resource: coretypes.ResourceMetaResourceIngestionKey,+ Verb: coretypes.VerbDelete,+ Category: coretypes.ActionCategoryConfigurationChange,+ ID: coretypes.PathParam("keyId"),+ Selector: coretypes.IDSelector,+ }),+ )).Methods(http.MethodDelete).GetError(); err != nil {return err}- if err := router.Handle("/api/v2/gateway/ingestion_keys/{keyId}", handler.New(provider.authzMiddleware.EditAccess(provider.gatewayHandler.GetIngestionKey), handler.OpenAPIDef{- ID: "GetIngestionKey",- Tags: []string{"gateway"},- Summary: "Get ingestion key for workspace",- Description: "This endpoint returns an ingestion key for the workspace",- Request: nil,- RequestContentType: "",- Response: new(gatewaytypes.IngestionKey),- ResponseContentType: "application/json",- SuccessStatusCode: http.StatusOK,- ErrorStatusCodes: []int{http.StatusNotFound},- Deprecated: false,- SecuritySchemes: newSecuritySchemes(types.RoleEditor),- })).Methods(http.MethodGet).GetError(); err != nil {+ if err := router.Handle("/api/v2/gateway/ingestion_keys/{keyId}", handler.New(+ provider.authzMiddleware.CheckResources(provider.gatewayHandler.GetIngestionKey, authtypes.SigNozAdminRoleName, authtypes.SigNozEditorRoleName),+ handler.OpenAPIDef{+ ID: "GetIngestionKey",+ Tags: []string{"gateway"},+ Summary: "Get ingestion key for workspace",+ Description: "This endpoint returns an ingestion key for the workspace",+ Request: nil,+ RequestContentType: "",+ Response: new(gatewaytypes.IngestionKey),+ ResponseContentType: "application/json",+ SuccessStatusCode: http.StatusOK,+ ErrorStatusCodes: []int{http.StatusNotFound},+ Deprecated: false,+ SecuritySchemes: newScopedSecuritySchemes([]string{coretypes.ResourceMetaResourceIngestionKey.Scope(coretypes.VerbRead)}),+ },+ handler.WithResourceDefs(handler.BasicResourceDef{+ Resource: coretypes.ResourceMetaResourceIngestionKey,+ Verb: coretypes.VerbRead,+ Category: coretypes.ActionCategoryDataAccess,+ ID: coretypes.PathParam("keyId"),+ Selector: coretypes.IDSelector,+ }),+ )).Methods(http.MethodGet).GetError(); err != nil {return err}- if err := router.Handle("/api/v2/gateway/ingestion_keys/{keyId}/limits", handler.New(provider.authzMiddleware.EditAccess(provider.gatewayHandler.DeprecatedCreateIngestionKeyLimit), handler.OpenAPIDef{- ID: "CreateIngestionKeyLimit",- Tags: []string{"gateway"},- Summary: "Create limit for the ingestion key",- Description: "This endpoint creates an ingestion key limit",- Request: new(gatewaytypes.DeprecatedPostableIngestionKeyLimit),- RequestContentType: "application/json",- Response: new(gatewaytypes.GettableCreatedIngestionKeyLimit),- ResponseContentType: "application/json",- SuccessStatusCode: http.StatusCreated,- ErrorStatusCodes: []int{},- Deprecated: true,- SecuritySchemes: newSecuritySchemes(types.RoleEditor),- })).Methods(http.MethodPost).GetError(); err != nil {+ if err := router.Handle("/api/v2/gateway/ingestion_keys/{keyId}/limits", handler.New(+ provider.authzMiddleware.CheckResources(provider.gatewayHandler.GetIngestionKeyLimits, authtypes.SigNozAdminRoleName, authtypes.SigNozEditorRoleName),+ handler.OpenAPIDef{+ ID: "GetIngestionKeyLimits",+ Tags: []string{"gateway"},+ Summary: "Get limits for the ingestion key",+ Description: "This endpoint returns the ingestion limits for an ingestion key",+ Request: nil,+ RequestContentType: "",+ Response: new([]gatewaytypes.Limit),+ ResponseContentType: "application/json",+ SuccessStatusCode: http.StatusOK,+ ErrorStatusCodes: []int{http.StatusNotFound},+ Deprecated: false,+ SecuritySchemes: newScopedSecuritySchemes([]string{coretypes.ResourceMetaResourceIngestionLimit.Scope(coretypes.VerbList)}),+ },+ handler.WithResourceDefs(handler.BasicResourceDef{+ Resource: coretypes.ResourceMetaResourceIngestionLimit,+ Verb: coretypes.VerbList,+ Category: coretypes.ActionCategoryDataAccess,+ Selector: coretypes.WildcardSelector,+ }),+ )).Methods(http.MethodGet).GetError(); err != nil {return err}- if err := router.Handle("/api/v2/gateway/ingestion_keys/{keyId}/limits", handler.New(provider.authzMiddleware.EditAccess(provider.gatewayHandler.GetIngestionKeyLimits), handler.OpenAPIDef{- ID: "GetIngestionKeyLimits",- Tags: []string{"gateway"},- Summary: "Get limits for the ingestion key",- Description: "This endpoint returns the ingestion limits for an ingestion key",- Request: nil,- RequestContentType: "",- Response: new([]gatewaytypes.Limit),- ResponseContentType: "application/json",- SuccessStatusCode: http.StatusOK,- ErrorStatusCodes: []int{http.StatusNotFound},- Deprecated: false,- SecuritySchemes: newSecuritySchemes(types.RoleEditor),- })).Methods(http.MethodGet).GetError(); err != nil {+ if err := router.Handle("/api/v2/gateway/ingestion_keys/{keyId}/limits", handler.New(+ provider.authzMiddleware.CheckResources(provider.gatewayHandler.DeprecatedCreateIngestionKeyLimit, authtypes.SigNozAdminRoleName, authtypes.SigNozEditorRoleName),+ handler.OpenAPIDef{+ ID: "CreateIngestionKeyLimit",+ Tags: []string{"gateway"},+ Summary: "Create limit for the ingestion key",+ Description: "This endpoint creates an ingestion key limit.",+ Request: new(gatewaytypes.DeprecatedPostableIngestionKeyLimit),+ RequestContentType: "application/json",+ Response: new(gatewaytypes.GettableCreatedIngestionKeyLimit),+ ResponseContentType: "application/json",+ SuccessStatusCode: http.StatusCreated,+ ErrorStatusCodes: []int{},+ Deprecated: true,+ SecuritySchemes: newScopedSecuritySchemes([]string{coretypes.ResourceMetaResourceIngestionLimit.Scope(coretypes.VerbCreate), coretypes.ResourceMetaResourceIngestionKey.Scope(coretypes.VerbAttach)}),+ },+ handler.WithResourceDefs(+ handler.BasicResourceDef{+ Resource: coretypes.ResourceMetaResourceIngestionLimit,+ Verb: coretypes.VerbCreate,+ Category: coretypes.ActionCategoryConfigurationChange,+ ID: coretypes.ResponseJSONPath("data.id"),+ Selector: coretypes.WildcardSelector,+ },+ handler.AttachDetachParentChildResourceDef{+ Verb: coretypes.VerbAttach,+ Category: coretypes.ActionCategoryConfigurationChange,+ ParentResource: coretypes.ResourceMetaResourceIngestionKey,+ ParentID: coretypes.PathParam("keyId"),+ ParentSelector: coretypes.IDSelector,+ ChildResource: coretypes.ResourceMetaResourceIngestionLimit,+ ChildIDs: coretypes.OneID(coretypes.ResponseJSONPath("data.id")),+ },+ ),+ )).Methods(http.MethodPost).GetError(); err != nil {return err}- if err := router.Handle("/api/v2/gateway/ingestion_keys/limits/{limitId}", handler.New(provider.authzMiddleware.EditAccess(provider.gatewayHandler.UpdateIngestionKeyLimit), handler.OpenAPIDef{- ID: "UpdateIngestionKeyLimit",- Tags: []string{"gateway"},- Summary: "Update limit for the ingestion key",- Description: "This endpoint updates an ingestion key limit",- Request: new(gatewaytypes.UpdatableIngestionKeyLimit),- RequestContentType: "application/json",- Response: nil,- ResponseContentType: "",- SuccessStatusCode: http.StatusNoContent,- ErrorStatusCodes: []int{},- Deprecated: true,- SecuritySchemes: newSecuritySchemes(types.RoleEditor),- })).Methods(http.MethodPatch).GetError(); err != nil {+ if err := router.Handle("/api/v2/gateway/ingestion_keys/limits/{limitId}", handler.New(+ provider.authzMiddleware.CheckResources(provider.gatewayHandler.UpdateIngestionKeyLimit, authtypes.SigNozAdminRoleName, authtypes.SigNozEditorRoleName),+ handler.OpenAPIDef{+ ID: "UpdateIngestionKeyLimit",+ Tags: []string{"gateway"},+ Summary: "Update limit for the ingestion key",+ Description: "This endpoint updates an ingestion key limit.",+ Request: new(gatewaytypes.UpdatableIngestionKeyLimit),+ RequestContentType: "application/json",+ Response: nil,+ ResponseContentType: "",+ SuccessStatusCode: http.StatusNoContent,+ ErrorStatusCodes: []int{},+ Deprecated: true,+ SecuritySchemes: newScopedSecuritySchemes([]string{coretypes.ResourceMetaResourceIngestionLimit.Scope(coretypes.VerbUpdate)}),+ },+ handler.WithResourceDefs(handler.BasicResourceDef{+ Resource: coretypes.ResourceMetaResourceIngestionLimit,+ Verb: coretypes.VerbUpdate,+ Category: coretypes.ActionCategoryConfigurationChange,+ ID: coretypes.PathParam("limitId"),+ Selector: coretypes.IDSelector,+ }),+ )).Methods(http.MethodPatch).GetError(); err != nil {return err}- if err := router.Handle("/api/v2/gateway/ingestion_keys/limits/{limitId}", handler.New(provider.authzMiddleware.EditAccess(provider.gatewayHandler.DeleteIngestionKeyLimit), handler.OpenAPIDef{- ID: "DeleteIngestionKeyLimit",- Tags: []string{"gateway"},- Summary: "Delete limit for the ingestion key",- Description: "This endpoint deletes an ingestion key limit",- Request: nil,- RequestContentType: "application/json",- Response: nil,- ResponseContentType: "",- SuccessStatusCode: http.StatusNoContent,- ErrorStatusCodes: []int{},- Deprecated: true,- SecuritySchemes: newSecuritySchemes(types.RoleEditor),- })).Methods(http.MethodDelete).GetError(); err != nil {+ if err := router.Handle("/api/v2/gateway/ingestion_keys/limits/{limitId}", handler.New(+ provider.authzMiddleware.CheckResources(provider.gatewayHandler.DeleteIngestionKeyLimit, authtypes.SigNozAdminRoleName, authtypes.SigNozEditorRoleName),+ handler.OpenAPIDef{+ ID: "DeleteIngestionKeyLimit",+ Tags: []string{"gateway"},+ Summary: "Delete limit for the ingestion key",+ Description: "This endpoint deletes an ingestion key limit",+ Request: nil,+ RequestContentType: "application/json",+ Response: nil,+ ResponseContentType: "",+ SuccessStatusCode: http.StatusNoContent,+ ErrorStatusCodes: []int{},+ Deprecated: true,+ SecuritySchemes: newScopedSecuritySchemes([]string{coretypes.ResourceMetaResourceIngestionLimit.Scope(coretypes.VerbDelete), coretypes.ResourceMetaResourceIngestionKey.Scope(coretypes.VerbDetach)}),+ },+ handler.WithResourceDefs(+ handler.BasicResourceDef{+ Resource: coretypes.ResourceMetaResourceIngestionLimit,+ Verb: coretypes.VerbDelete,+ Category: coretypes.ActionCategoryConfigurationChange,+ ID: coretypes.PathParam("limitId"),+ Selector: coretypes.IDSelector,+ },+ handler.AttachDetachParentChildResourceDef{+ Verb: coretypes.VerbDetach,+ Category: coretypes.ActionCategoryConfigurationChange,+ ParentResource: coretypes.ResourceMetaResourceIngestionKey,+ ParentID: provider.ingestionLimitParentKeyIDExtractor(),+ ParentSelector: coretypes.IDSelector,+ ChildResource: coretypes.ResourceMetaResourceIngestionLimit,+ ChildIDs: coretypes.OneID(coretypes.PathParam("limitId")),+ },+ ),+ )).Methods(http.MethodDelete).GetError(); err != nil {return err}- if err := router.Handle("/api/v2/gateway/ingestion_limits", handler.New(provider.authzMiddleware.EditAccess(provider.gatewayHandler.CreateIngestionKeyLimit), handler.OpenAPIDef{- ID: "CreateIngestionLimit",- Tags: []string{"gateway"},- Summary: "Create ingestion limit",- Description: "This endpoint creates an ingestion limit for the ingestion key referenced by keyId",- Request: new(gatewaytypes.PostableIngestionKeyLimit),- RequestContentType: "application/json",- Response: new(types.Identifiable),- ResponseContentType: "application/json",- SuccessStatusCode: http.StatusCreated,- ErrorStatusCodes: []int{http.StatusBadRequest},- Deprecated: false,- SecuritySchemes: newSecuritySchemes(types.RoleEditor),- })).Methods(http.MethodPost).GetError(); err != nil {+ if err := router.Handle("/api/v2/gateway/ingestion_limits", handler.New(+ provider.authzMiddleware.CheckResources(provider.gatewayHandler.CreateIngestionKeyLimit, authtypes.SigNozAdminRoleName, authtypes.SigNozEditorRoleName),+ handler.OpenAPIDef{+ ID: "CreateIngestionLimit",+ Tags: []string{"gateway"},+ Summary: "Create ingestion limit",+ Description: "This endpoint creates an ingestion limit for the ingestion key referenced by keyId",+ Request: new(gatewaytypes.PostableIngestionKeyLimit),+ RequestContentType: "application/json",+ Response: new(types.Identifiable),+ ResponseContentType: "application/json",+ SuccessStatusCode: http.StatusCreated,+ ErrorStatusCodes: []int{http.StatusBadRequest},+ Deprecated: false,+ SecuritySchemes: newScopedSecuritySchemes([]string{coretypes.ResourceMetaResourceIngestionLimit.Scope(coretypes.VerbCreate), coretypes.ResourceMetaResourceIngestionKey.Scope(coretypes.VerbAttach)}),+ },+ handler.WithResourceDefs(+ handler.BasicResourceDef{+ Resource: coretypes.ResourceMetaResourceIngestionLimit,+ Verb: coretypes.VerbCreate,+ Category: coretypes.ActionCategoryConfigurationChange,+ ID: coretypes.ResponseJSONPath("data.id"),+ Selector: coretypes.WildcardSelector,+ },+ handler.AttachDetachParentChildResourceDef{+ Verb: coretypes.VerbAttach,+ Category: coretypes.ActionCategoryConfigurationChange,+ ParentResource: coretypes.ResourceMetaResourceIngestionKey,+ ParentID: coretypes.BodyJSONPath("keyId"),+ ParentSelector: coretypes.IDSelector,+ ChildResource: coretypes.ResourceMetaResourceIngestionLimit,+ ChildIDs: coretypes.OneID(coretypes.ResponseJSONPath("data.id")),+ },+ ),+ )).Methods(http.MethodPost).GetError(); err != nil {return err}- if err := router.Handle("/api/v2/gateway/ingestion_limits/{limitId}", handler.New(provider.authzMiddleware.EditAccess(provider.gatewayHandler.GetIngestionKeyLimit), handler.OpenAPIDef{- ID: "GetIngestionLimit",- Tags: []string{"gateway"},- Summary: "Get ingestion limit",- Description: "This endpoint returns an ingestion limit",- Request: nil,- RequestContentType: "",- Response: new(gatewaytypes.Limit),- ResponseContentType: "application/json",- SuccessStatusCode: http.StatusOK,- ErrorStatusCodes: []int{http.StatusNotFound},- Deprecated: false,- SecuritySchemes: newSecuritySchemes(types.RoleEditor),- })).Methods(http.MethodGet).GetError(); err != nil {+ if err := router.Handle("/api/v2/gateway/ingestion_limits/{limitId}", handler.New(+ provider.authzMiddleware.CheckResources(provider.gatewayHandler.GetIngestionKeyLimit, authtypes.SigNozAdminRoleName, authtypes.SigNozEditorRoleName),+ handler.OpenAPIDef{+ ID: "GetIngestionLimit",+ Tags: []string{"gateway"},+ Summary: "Get ingestion limit",+ Description: "This endpoint returns an ingestion limit",+ Request: nil,+ RequestContentType: "",+ Response: new(gatewaytypes.Limit),+ ResponseContentType: "application/json",+ SuccessStatusCode: http.StatusOK,+ ErrorStatusCodes: []int{http.StatusNotFound},+ Deprecated: false,+ SecuritySchemes: newScopedSecuritySchemes([]string{coretypes.ResourceMetaResourceIngestionLimit.Scope(coretypes.VerbRead)}),+ },+ handler.WithResourceDefs(handler.BasicResourceDef{+ Resource: coretypes.ResourceMetaResourceIngestionLimit,+ Verb: coretypes.VerbRead,+ Category: coretypes.ActionCategoryDataAccess,+ ID: coretypes.PathParam("limitId"),+ Selector: coretypes.IDSelector,+ }),+ )).Methods(http.MethodGet).GetError(); err != nil {return err}- if err := router.Handle("/api/v2/gateway/ingestion_limits/{limitId}", handler.New(provider.authzMiddleware.EditAccess(provider.gatewayHandler.UpdateIngestionKeyLimit), handler.OpenAPIDef{- ID: "UpdateIngestionLimit",- Tags: []string{"gateway"},- Summary: "Update ingestion limit",- Description: "This endpoint updates an ingestion limit",- Request: new(gatewaytypes.UpdatableIngestionKeyLimit),- RequestContentType: "application/json",- Response: nil,- ResponseContentType: "",- SuccessStatusCode: http.StatusNoContent,- ErrorStatusCodes: []int{},- Deprecated: false,- SecuritySchemes: newSecuritySchemes(types.RoleEditor),- })).Methods(http.MethodPatch).GetError(); err != nil {+ if err := router.Handle("/api/v2/gateway/ingestion_limits/{limitId}", handler.New(+ provider.authzMiddleware.CheckResources(provider.gatewayHandler.UpdateIngestionKeyLimit, authtypes.SigNozAdminRoleName, authtypes.SigNozEditorRoleName),+ handler.OpenAPIDef{+ ID: "UpdateIngestionLimit",+ Tags: []string{"gateway"},+ Summary: "Update ingestion limit",+ Description: "This endpoint updates an ingestion limit",+ Request: new(gatewaytypes.UpdatableIngestionKeyLimit),+ RequestContentType: "application/json",+ Response: nil,+ ResponseContentType: "",+ SuccessStatusCode: http.StatusNoContent,+ ErrorStatusCodes: []int{},+ Deprecated: false,+ SecuritySchemes: newScopedSecuritySchemes([]string{coretypes.ResourceMetaResourceIngestionLimit.Scope(coretypes.VerbUpdate)}),+ },+ handler.WithResourceDefs(handler.BasicResourceDef{+ Resource: coretypes.ResourceMetaResourceIngestionLimit,+ Verb: coretypes.VerbUpdate,+ Category: coretypes.ActionCategoryConfigurationChange,+ ID: coretypes.PathParam("limitId"),+ Selector: coretypes.IDSelector,+ }),+ )).Methods(http.MethodPatch).GetError(); err != nil {return err}- if err := router.Handle("/api/v2/gateway/ingestion_limits/{limitId}", handler.New(provider.authzMiddleware.EditAccess(provider.gatewayHandler.DeleteIngestionKeyLimit), handler.OpenAPIDef{- ID: "DeleteIngestionLimit",- Tags: []string{"gateway"},- Summary: "Delete ingestion limit",- Description: "This endpoint deletes an ingestion limit",- Request: nil,- RequestContentType: "",- Response: nil,- ResponseContentType: "",- SuccessStatusCode: http.StatusNoContent,- ErrorStatusCodes: []int{},- Deprecated: false,- SecuritySchemes: newSecuritySchemes(types.RoleEditor),- })).Methods(http.MethodDelete).GetError(); err != nil {+ if err := router.Handle("/api/v2/gateway/ingestion_limits/{limitId}", handler.New(+ provider.authzMiddleware.CheckResources(provider.gatewayHandler.DeleteIngestionKeyLimit, authtypes.SigNozAdminRoleName, authtypes.SigNozEditorRoleName),+ handler.OpenAPIDef{+ ID: "DeleteIngestionLimit",+ Tags: []string{"gateway"},+ Summary: "Delete ingestion limit",+ Description: "This endpoint deletes an ingestion limit",+ Request: nil,+ RequestContentType: "",+ Response: nil,+ ResponseContentType: "",+ SuccessStatusCode: http.StatusNoContent,+ ErrorStatusCodes: []int{},+ Deprecated: false,+ SecuritySchemes: newScopedSecuritySchemes([]string{coretypes.ResourceMetaResourceIngestionLimit.Scope(coretypes.VerbDelete), coretypes.ResourceMetaResourceIngestionKey.Scope(coretypes.VerbDetach)}),+ },+ handler.WithResourceDefs(+ handler.BasicResourceDef{+ Resource: coretypes.ResourceMetaResourceIngestionLimit,+ Verb: coretypes.VerbDelete,+ Category: coretypes.ActionCategoryConfigurationChange,+ ID: coretypes.PathParam("limitId"),+ Selector: coretypes.IDSelector,+ },+ handler.AttachDetachParentChildResourceDef{+ Verb: coretypes.VerbDetach,+ Category: coretypes.ActionCategoryConfigurationChange,+ ParentResource: coretypes.ResourceMetaResourceIngestionKey,+ ParentID: provider.ingestionLimitParentKeyIDExtractor(),+ ParentSelector: coretypes.IDSelector,+ ChildResource: coretypes.ResourceMetaResourceIngestionLimit,+ ChildIDs: coretypes.OneID(coretypes.PathParam("limitId")),+ },+ ),+ )).Methods(http.MethodDelete).GetError(); err != nil {return err}return nil}++func (provider *provider) ingestionLimitParentKeyIDExtractor() coretypes.ResourceIDExtractor {+ return coretypes.NewResourceIDExtractor(coretypes.PhaseRequest, func(ec coretypes.ExtractorContext) (string, error) {+ if ec.Request == nil {+ return "", nil+ }++ claims, err := authtypes.ClaimsFromContext(ec.Request.Context())+ if err != nil {+ return "", err+ }++ limit, err := provider.gatewayService.GetIngestionKeyLimit(ec.Request.Context(), valuer.MustNewUUID(claims.OrgID), mux.Vars(ec.Request)["limitId"])+ if err != nil {+ return "", err+ }++ return limit.KeyID, nil+ })+}diff --git a/pkg/apiserver/signozapiserver/provider.go b/pkg/apiserver/signozapiserver/provider.goindex 80a916bf6c..4842ee910a 100644--- a/pkg/apiserver/signozapiserver/provider.go+++ b/pkg/apiserver/signozapiserver/provider.go@@ -65,6 +65,7 @@ type provider struct {metricReductionRuleHandler metricreductionrule.HandlerinfraMonitoringHandler inframonitoring.HandlergatewayHandler gateway.Handler+ gatewayService gateway.GatewayfieldsHandler fields.HandleraiObservabilityHandler aiobservability.HandlerauthzHandler authz.Handler@@ -107,6 +108,7 @@ func NewFactory(metricReductionRuleHandler metricreductionrule.Handler,infraMonitoringHandler inframonitoring.Handler,gatewayHandler gateway.Handler,+ gatewayService gateway.Gateway,fieldsHandler fields.Handler,aiObservabilityHandler aiobservability.Handler,authzHandler authz.Handler,@@ -152,6 +154,7 @@ func NewFactory(metricReductionRuleHandler,infraMonitoringHandler,gatewayHandler,+ gatewayService,fieldsHandler,aiObservabilityHandler,authzHandler,@@ -199,6 +202,7 @@ func newProvider(metricReductionRuleHandler metricreductionrule.Handler,infraMonitoringHandler inframonitoring.Handler,gatewayHandler gateway.Handler,+ gatewayService gateway.Gateway,fieldsHandler fields.Handler,aiObservabilityHandler aiobservability.Handler,authzHandler authz.Handler,@@ -245,6 +249,7 @@ func newProvider(metricReductionRuleHandler: metricReductionRuleHandler,infraMonitoringHandler: infraMonitoringHandler,gatewayHandler: gatewayHandler,+ gatewayService: gatewayService,fieldsHandler: fieldsHandler,aiObservabilityHandler: aiObservabilityHandler,authzHandler: authzHandler,diff --git a/pkg/signoz/openapi.go b/pkg/signoz/openapi.goindex b4ad7416bb..8fe8aaf0c0 100644--- a/pkg/signoz/openapi.go+++ b/pkg/signoz/openapi.go@@ -78,6 +78,7 @@ func NewOpenAPI(ctx context.Context, instrumentation instrumentation.Instrumentastruct{ metricreductionrule.Handler }{},struct{ inframonitoring.Handler }{},struct{ gateway.Handler }{},+ struct{ gateway.Gateway }{},struct{ fields.Handler }{},struct{ aiobservability.Handler }{},struct{ authz.Handler }{},diff --git a/pkg/signoz/provider.go b/pkg/signoz/provider.goindex 1246e2bbc9..74fe2b5eb0 100644--- a/pkg/signoz/provider.go+++ b/pkg/signoz/provider.go@@ -22,6 +22,7 @@ import ("github.com/SigNoz/signoz/pkg/factory""github.com/SigNoz/signoz/pkg/flagger""github.com/SigNoz/signoz/pkg/flagger/configflagger"+ "github.com/SigNoz/signoz/pkg/gateway""github.com/SigNoz/signoz/pkg/global""github.com/SigNoz/signoz/pkg/global/signozglobal""github.com/SigNoz/signoz/pkg/identn"@@ -250,6 +251,7 @@ func NewSQLMigrationProviderFactories(sqlmigration.NewAddChannelDisplayNameFactory(sqlstore, sqlschema),sqlmigration.NewMigrateQuickFiltersFactory(sqlstore),sqlmigration.NewAddQuickFilterTuplesFactory(sqlstore),+ sqlmigration.NewAddIngestionTuplesFactory(sqlstore),)}@@ -315,7 +317,7 @@ func NewQuerierProviderFactories(telemetryStore telemetrystore.TelemetryStore, p)}-func NewAPIServerProviderFactories(orgGetter organization.Getter, authz authz.AuthZ, modules Modules, handlers Handlers, globalConfig global.Config) factory.NamedMap[factory.ProviderFactory[apiserver.APIServer, apiserver.Config]] {+func NewAPIServerProviderFactories(orgGetter organization.Getter, authz authz.AuthZ, modules Modules, handlers Handlers, globalConfig global.Config, gatewayService gateway.Gateway) factory.NamedMap[factory.ProviderFactory[apiserver.APIServer, apiserver.Config]] {return factory.MustNewNamedMap(signozapiserver.NewFactory(orgGetter,@@ -335,6 +337,7 @@ func NewAPIServerProviderFactories(orgGetter organization.Getter, authz authz.Auhandlers.MetricReductionRule,handlers.InfraMonitoring,handlers.GatewayHandler,+ gatewayService,handlers.Fields,handlers.AIObservability,handlers.AuthzHandler,diff --git a/pkg/signoz/provider_test.go b/pkg/signoz/provider_test.goindex fc7f6c3457..6736ff6fa2 100644--- a/pkg/signoz/provider_test.go+++ b/pkg/signoz/provider_test.go@@ -101,6 +101,7 @@ func TestNewProviderFactories(t *testing.T) {Modules{},Handlers{},global.Config{},+ nil,)})}diff --git a/pkg/signoz/signoz.go b/pkg/signoz/signoz.goindex b11e3f74d3..3fab0be1a9 100644--- a/pkg/signoz/signoz.go+++ b/pkg/signoz/signoz.go@@ -631,7 +631,7 @@ func New(ctx,providerSettings,config.APIServer,- NewAPIServerProviderFactories(orgGetter, authz, modules, handlers, config.Global),+ NewAPIServerProviderFactories(orgGetter, authz, modules, handlers, config.Global, gateway),"signoz",)if err != nil {diff --git a/pkg/sqlmigration/124_add_ingestion_tuples.go b/pkg/sqlmigration/124_add_ingestion_tuples.gonew file mode 100644index 0000000000..bfaf33efc6--- /dev/null+++ b/pkg/sqlmigration/124_add_ingestion_tuples.go@@ -0,0 +1,181 @@+package sqlmigration++import (+ "context"+ "database/sql"+ "encoding/json"+ "time"++ "github.com/SigNoz/signoz/pkg/factory"+ "github.com/SigNoz/signoz/pkg/sqlstore"+ "github.com/SigNoz/signoz/pkg/types/authtypes"+ "github.com/SigNoz/signoz/pkg/types/coretypes"+ "github.com/oklog/ulid/v2"+ "github.com/uptrace/bun"+ "github.com/uptrace/bun/dialect"+ "github.com/uptrace/bun/migrate"+)++type addIngestionTuples struct {+ sqlstore sqlstore.SQLStore+}++func NewAddIngestionTuplesFactory(sqlstore sqlstore.SQLStore) factory.ProviderFactory[SQLMigration, Config] {+ return factory.NewProviderFactory(factory.MustNewName("add_ingestion_tuples"), func(ctx context.Context, ps factory.ProviderSettings, c Config) (SQLMigration, error) {+ return &addIngestionTuples{sqlstore: sqlstore}, nil+ })+}++func (migration *addIngestionTuples) Register(migrations *migrate.Migrations) error {+ return migrations.Register(migration.Up, migration.Down)+}++func (migration *addIngestionTuples) Up(ctx context.Context, db *bun.DB) error {+ tx, err := db.BeginTx(ctx, nil)+ if err != nil {+ return err+ }+ defer func() { _ = tx.Rollback() }()++ var storeID string+ err = tx.QueryRowContext(ctx, `SELECT id FROM store WHERE name = ? LIMIT 1`, "signoz").Scan(&storeID)+ if err != nil {+ return err+ }++ var orgIDs []string+ err = tx.NewSelect().+ Table("organizations").+ Column("id").+ Scan(ctx, &orgIDs)+ if err != nil && err != sql.ErrNoRows {+ return err+ }++ isPG := migration.sqlstore.BunDB().Dialect().Name() == dialect.PG++ // ingestion-key and ingestion-limit moved from the legacy EditAccess role gate to+ // CheckResources, which on enterprise requires real tuples -- existing orgs+ // never had these written, only new orgs get them from the registry at bootstrap.+ tuples := []migrationTuple{+ {authtypes.SigNozAdminRoleName, "metaresource", "ingestion-key", "create"},+ {authtypes.SigNozAdminRoleName, "metaresource", "ingestion-key", "read"},+ {authtypes.SigNozAdminRoleName, "metaresource", "ingestion-key", "update"},+ {authtypes.SigNozAdminRoleName, "metaresource", "ingestion-key", "delete"},+ {authtypes.SigNozAdminRoleName, "metaresource", "ingestion-key", "list"},+ {authtypes.SigNozAdminRoleName, "metaresource", "ingestion-key", "attach"},+ {authtypes.SigNozAdminRoleName, "metaresource", "ingestion-key", "detach"},+ {authtypes.SigNozAdminRoleName, "metaresource", "ingestion-limit", "create"},+ {authtypes.SigNozAdminRoleName, "metaresource", "ingestion-limit", "read"},+ {authtypes.SigNozAdminRoleName, "metaresource", "ingestion-limit", "update"},+ {authtypes.SigNozAdminRoleName, "metaresource", "ingestion-limit", "delete"},+ {authtypes.SigNozAdminRoleName, "metaresource", "ingestion-limit", "list"},+ {authtypes.SigNozEditorRoleName, "metaresource", "ingestion-key", "create"},+ {authtypes.SigNozEditorRoleName, "metaresource", "ingestion-key", "read"},+ {authtypes.SigNozEditorRoleName, "metaresource", "ingestion-key", "update"},+ {authtypes.SigNozEditorRoleName, "metaresource", "ingestion-key", "delete"},+ {authtypes.SigNozEditorRoleName, "metaresource", "ingestion-key", "list"},+ {authtypes.SigNozEditorRoleName, "metaresource", "ingestion-key", "attach"},+ {authtypes.SigNozEditorRoleName, "metaresource", "ingestion-key", "detach"},+ {authtypes.SigNozEditorRoleName, "metaresource", "ingestion-limit", "create"},+ {authtypes.SigNozEditorRoleName, "metaresource", "ingestion-limit", "read"},+ {authtypes.SigNozEditorRoleName, "metaresource", "ingestion-limit", "update"},+ {authtypes.SigNozEditorRoleName, "metaresource", "ingestion-limit", "delete"},+ {authtypes.SigNozEditorRoleName, "metaresource", "ingestion-limit", "list"},+ }++ for _, orgID := range orgIDs {+ for _, tuple := range tuples {+ entropy := ulid.DefaultEntropy()+ now := time.Now().UTC()+ tupleID := ulid.MustNew(ulid.Timestamp(now), entropy).String()++ objectID := "organization/" + orgID + "/" + tuple.objectName + "/*"+ roleSubject := "organization/" + orgID + "/role/" + tuple.roleName++ if isPG {+ user := "role:" + roleSubject + "#assignee"+ result, err := tx.ExecContext(ctx, `+ INSERT INTO tuple (store, object_type, object_id, relation, _user, user_type, ulid, inserted_at)+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)+ ON CONFLICT (store, object_type, object_id, relation, _user) DO NOTHING`,+ storeID, tuple.objectType, objectID, tuple.relation, user, "userset", tupleID, now,+ )+ if err != nil {+ return err+ }+ rowsAffected, err := result.RowsAffected()+ if err != nil {+ return err+ }+ if rowsAffected == 0 {+ continue+ }+ _, err = tx.ExecContext(ctx, `+ INSERT INTO changelog (store, object_type, object_id, relation, _user, operation, ulid, inserted_at)+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)+ ON CONFLICT (store, ulid, object_type) DO NOTHING`,+ storeID, tuple.objectType, objectID, tuple.relation, user, 0, tupleID, now,+ )+ if err != nil {+ return err+ }+ } else {+ result, err := tx.ExecContext(ctx, `+ INSERT INTO tuple (store, object_type, object_id, relation, user_object_type, user_object_id, user_relation, user_type, ulid, inserted_at)+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)+ ON CONFLICT (store, object_type, object_id, relation, user_object_type, user_object_id, user_relation) DO NOTHING`,+ storeID, tuple.objectType, objectID, tuple.relation, "role", roleSubject, "assignee", "userset", tupleID, now,+ )+ if err != nil {+ return err+ }+ rowsAffected, err := result.RowsAffected()+ if err != nil {+ return err+ }+ if rowsAffected == 0 {+ continue+ }+ _, err = tx.ExecContext(ctx, `+ INSERT INTO changelog (store, object_type, object_id, relation, user_object_type, user_object_id, user_relation, operation, ulid, inserted_at)+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)+ ON CONFLICT (store, ulid, object_type) DO NOTHING`,+ storeID, tuple.objectType, objectID, tuple.relation, "role", roleSubject, "assignee", 0, tupleID, now,+ )+ if err != nil {+ return err+ }+ }+ }+ }++ managedRoleGroups := make(map[string]string, len(coretypes.ManagedRoleToTransactions))+ for roleName, transactions := range coretypes.ManagedRoleToTransactions {+ data, err := json.Marshal(authtypes.NewTransactionGroupsFromTransactions(transactions))+ if err != nil {+ return err+ }+ managedRoleGroups[roleName] = string(data)+ }++ for _, orgID := range orgIDs {+ for roleName, data := range managedRoleGroups {+ if _, err := tx.NewUpdate().+ Model(new(roles)).+ Set("transaction_groups = ?", data).+ Where("org_id = ?", orgID).+ Where("type = ?", authtypes.RoleTypeManaged.StringValue()).+ Where("name = ?", roleName).+ Exec(ctx); err != nil {+ return err+ }+ }+ }++ return tx.Commit()+}++func (migration *addIngestionTuples) Down(context.Context, *bun.DB) error {+ return nil+}diff --git a/pkg/types/coretypes/registry_managed_role.go b/pkg/types/coretypes/registry_managed_role.goindex 947ff99be5..d141075950 100644--- a/pkg/types/coretypes/registry_managed_role.go+++ b/pkg/types/coretypes/registry_managed_role.go@@ -160,6 +160,8 @@ var ManagedRoleToTransactions = map[string][]Transaction{{Verb: VerbDelete, Object: *MustNewObject(ResourceRef{Type: TypeMetaResource, Kind: KindIngestionKey}, WildCardSelectorString)},{Verb: VerbCreate, Object: *MustNewObject(ResourceRef{Type: TypeMetaResource, Kind: KindIngestionKey}, WildCardSelectorString)},{Verb: VerbList, Object: *MustNewObject(ResourceRef{Type: TypeMetaResource, Kind: KindIngestionKey}, WildCardSelectorString)},+ {Verb: VerbAttach, Object: *MustNewObject(ResourceRef{Type: TypeMetaResource, Kind: KindIngestionKey}, WildCardSelectorString)},+ {Verb: VerbDetach, Object: *MustNewObject(ResourceRef{Type: TypeMetaResource, Kind: KindIngestionKey}, WildCardSelectorString)},// ingestion-limit — editor+admin only{Verb: VerbRead, Object: *MustNewObject(ResourceRef{Type: TypeMetaResource, Kind: KindIngestionLimit}, WildCardSelectorString)},{Verb: VerbUpdate, Object: *MustNewObject(ResourceRef{Type: TypeMetaResource, Kind: KindIngestionLimit}, WildCardSelectorString)},@@ -264,6 +266,8 @@ var ManagedRoleToTransactions = map[string][]Transaction{{Verb: VerbDelete, Object: *MustNewObject(ResourceRef{Type: TypeMetaResource, Kind: KindIngestionKey}, WildCardSelectorString)},{Verb: VerbCreate, Object: *MustNewObject(ResourceRef{Type: TypeMetaResource, Kind: KindIngestionKey}, WildCardSelectorString)},{Verb: VerbList, Object: *MustNewObject(ResourceRef{Type: TypeMetaResource, Kind: KindIngestionKey}, WildCardSelectorString)},+ {Verb: VerbAttach, Object: *MustNewObject(ResourceRef{Type: TypeMetaResource, Kind: KindIngestionKey}, WildCardSelectorString)},+ {Verb: VerbDetach, Object: *MustNewObject(ResourceRef{Type: TypeMetaResource, Kind: KindIngestionKey}, WildCardSelectorString)},// ingestion-limit — editor+admin only{Verb: VerbRead, Object: *MustNewObject(ResourceRef{Type: TypeMetaResource, Kind: KindIngestionLimit}, WildCardSelectorString)},{Verb: VerbUpdate, Object: *MustNewObject(ResourceRef{Type: TypeMetaResource, Kind: KindIngestionLimit}, WildCardSelectorString)},diff --git a/tests/fixtures/gateway.py b/tests/fixtures/gateway.pyindex 6d31b97304..86aa4c72d9 100644--- a/tests/fixtures/gateway.py+++ b/tests/fixtures/gateway.py@@ -5,8 +5,8 @@ from wiremock.client import WireMockMatchersfrom fixtures import types-TEST_KEY_ID = "test-key-id-001"-TEST_LIMIT_ID = "test-limit-id-001"+TEST_KEY_ID = "0a3f5b1c-2d4e-4f6a-8b9c-1d2e3f4a5b6c"+TEST_LIMIT_ID = "1b4a6c2d-3e5f-4a7b-9c8d-2e3f4a5b6c7d"def common_gateway_headers():diff --git a/tests/integration/testdata/role/managed_role_transactions.json b/tests/integration/testdata/role/managed_role_transactions.jsonindex f94b56f281..b6bdcce6d8 100644--- a/tests/integration/testdata/role/managed_role_transactions.json+++ b/tests/integration/testdata/role/managed_role_transactions.json@@ -232,7 +232,9 @@"read","update","delete",- "list"+ "list",+ "attach",+ "detach"]},{@@ -452,7 +454,9 @@"read","update","delete",- "list"+ "list",+ "attach",+ "detach"]},{diff --git a/tests/integration/tests/ingestionkeys/02_ingestion_keys_limits.py b/tests/integration/tests/ingestionkeys/02_ingestion_keys_limits.pyindex f64e868c69..a6e68aaab7 100644--- a/tests/integration/tests/ingestionkeys/02_ingestion_keys_limits.py+++ b/tests/integration/tests/ingestionkeys/02_ingestion_keys_limits.py@@ -368,6 +368,21 @@ def test_delete_ingestion_key_limit(make_http_mocks(signoz.gateway,[+ Mapping(+ request=MappingRequest(+ method=HttpMethods.GET,+ url=gateway_url,+ headers=common_gateway_headers(),+ ),+ response=MappingResponse(+ status=200,+ json_body={+ "status": "success",+ "data": {"id": TEST_LIMIT_ID, "key_id": TEST_KEY_ID, "signal": "logs"},+ },+ ),+ persistent=False,+ ),Mapping(request=MappingRequest(method=HttpMethods.DELETE,@@ -631,6 +646,21 @@ def test_delete_ingestion_limit(make_http_mocks(signoz.gateway,[+ Mapping(+ request=MappingRequest(+ method=HttpMethods.GET,+ url=gateway_url,+ headers=common_gateway_headers(),+ ),+ response=MappingResponse(+ status=200,+ json_body={+ "status": "success",+ "data": {"id": TEST_LIMIT_ID, "key_id": TEST_KEY_ID, "signal": "logs"},+ },+ ),+ persistent=False,+ ),Mapping(request=MappingRequest(method=HttpMethods.DELETE,