Skip to content

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.

fix(authz): drop the organization grant tuples (#11922)

Vikrant Gupta984b2d01382b
diff --git a/pkg/signoz/provider.go b/pkg/signoz/provider.go
index 1e72c8fc24..e94748393c 100644
--- a/pkg/signoz/provider.go
+++ b/pkg/signoz/provider.go
@@ -217,6 +217,7 @@ func NewSQLMigrationProviderFactories(
sqlmigration.NewAddDashboardViewFactory(sqlstore, sqlschema),
sqlmigration.NewMigrateSSORoleMappingNamesFactory(sqlstore),
sqlmigration.NewAddMetricReductionRulesFactory(sqlstore, sqlschema),
+ sqlmigration.NewRemoveOrganizationTuplesFactory(sqlstore),
)
}
diff --git a/pkg/sqlmigration/098_remove_organization_tuples.go b/pkg/sqlmigration/098_remove_organization_tuples.go
new file mode 100644
index 0000000000..eb268446b7
--- /dev/null
+++ b/pkg/sqlmigration/098_remove_organization_tuples.go
@@ -0,0 +1,52 @@
+package sqlmigration
+
+import (
+ "context"
+
+ "github.com/SigNoz/signoz/pkg/factory"
+ "github.com/SigNoz/signoz/pkg/sqlstore"
+ "github.com/uptrace/bun"
+ "github.com/uptrace/bun/migrate"
+)
+
+type removeOrganizationTuples struct {
+ sqlstore sqlstore.SQLStore
+}
+
+func NewRemoveOrganizationTuplesFactory(sqlstore sqlstore.SQLStore) factory.ProviderFactory[SQLMigration, Config] {
+ return factory.NewProviderFactory(factory.MustNewName("remove_organization_tuples"), func(ctx context.Context, ps factory.ProviderSettings, c Config) (SQLMigration, error) {
+ return &removeOrganizationTuples{sqlstore: sqlstore}, nil
+ })
+}
+
+func (migration *removeOrganizationTuples) Register(migrations *migrate.Migrations) error {
+ return migrations.Register(migration.Up, migration.Down)
+}
+
+func (migration *removeOrganizationTuples) 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
+ }
+
+ if _, err := tx.ExecContext(ctx, `DELETE FROM tuple WHERE store = ? AND object_type = ?`, storeID, "organization"); err != nil {
+ return err
+ }
+
+ if _, err := tx.ExecContext(ctx, `DELETE FROM changelog WHERE store = ? AND object_type = ?`, storeID, "organization"); err != nil {
+ return err
+ }
+
+ return tx.Commit()
+}
+
+func (migration *removeOrganizationTuples) Down(context.Context, *bun.DB) error {
+ return nil
+}
diff --git a/pkg/types/coretypes/object.go b/pkg/types/coretypes/object.go
index d7cb07599f..638f421fdc 100644
--- a/pkg/types/coretypes/object.go
+++ b/pkg/types/coretypes/object.go
@@ -46,18 +46,33 @@ func MustNewObject(resource ResourceRef, inputSelector string) *Object {
}
func MustNewObjectFromString(input string) *Object {
+ typeParts := strings.SplitN(input, ":", 2)
+ if len(typeParts) != 2 {
+ panic(errors.Newf(errors.TypeInternal, errors.CodeInternal, "invalid type format: %s", input))
+ }
+
+ typed := MustNewType(typeParts[0])
+
+ // The organization resource is the root entity and encodes its object as
+ // "organization:organization/<selector>" — without the orgID and kind
+ // segments used by every other resource ("<type>:organization/<orgID>/<kind>/<selector>").
+ if typed.Equals(TypeOrganization) {
+ orgParts := strings.Split(typeParts[1], "/")
+ if len(orgParts) != 2 {
+ panic(errors.Newf(errors.TypeInternal, errors.CodeInternal, "invalid input format: %s", input))
+ }
+
+ resource := ResourceRef{Type: typed, Kind: MustNewKind(orgParts[0])}
+ return &Object{Resource: resource, Selector: typed.MustSelector(orgParts[1])}
+ }
+
parts := strings.Split(input, "/")
if len(parts) != 4 {
panic(errors.Newf(errors.TypeInternal, errors.CodeInternal, "invalid input format: %s", input))
}
- typeParts := strings.Split(parts[0], ":")
- if len(typeParts) != 2 {
- panic(errors.Newf(errors.TypeInternal, errors.CodeInternal, "invalid type format: %s", parts[0]))
- }
-
resource := ResourceRef{
- Type: MustNewType(typeParts[0]),
+ Type: typed,
Kind: MustNewKind(parts[2]),
}
diff --git a/pkg/types/coretypes/registry_managed_role.go b/pkg/types/coretypes/registry_managed_role.go
index 49e0f29255..c2a2eecb93 100644
--- a/pkg/types/coretypes/registry_managed_role.go
+++ b/pkg/types/coretypes/registry_managed_role.go
@@ -83,9 +83,6 @@ var ManagedRoleToTransactions = map[string][]Transaction{
{Verb: VerbDelete, Object: *MustNewObject(ResourceRef{Type: TypeMetaResource, Kind: KindSubscription}, WildCardSelectorString)},
{Verb: VerbCreate, Object: *MustNewObject(ResourceRef{Type: TypeMetaResource, Kind: KindSubscription}, WildCardSelectorString)},
{Verb: VerbList, Object: *MustNewObject(ResourceRef{Type: TypeMetaResource, Kind: KindSubscription}, WildCardSelectorString)},
- // organization — admin only
- {Verb: VerbRead, Object: *MustNewObject(ResourceRef{Type: TypeOrganization, Kind: KindOrganization}, WildCardSelectorString)},
- {Verb: VerbUpdate, Object: *MustNewObject(ResourceRef{Type: TypeOrganization, Kind: KindOrganization}, WildCardSelectorString)},
// org-preference — admin only
{Verb: VerbRead, Object: *MustNewObject(ResourceRef{Type: TypeMetaResource, Kind: KindOrgPreference}, WildCardSelectorString)},
{Verb: VerbUpdate, Object: *MustNewObject(ResourceRef{Type: TypeMetaResource, Kind: KindOrgPreference}, WildCardSelectorString)},