Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: change object owner check rule (#14272)
rebelice4751e8d05c0f
diff --git a/backend/plugin/advisor/builtin_rules.go b/backend/plugin/advisor/builtin_rules.goindex 610bf6693e..08f12e3671 100644--- a/backend/plugin/advisor/builtin_rules.go+++ b/backend/plugin/advisor/builtin_rules.go@@ -4,12 +4,11 @@ import storepb "github.com/bytebase/bytebase/proto/generated-go/store"const (BuiltinRulePriorBackupCheck SQLReviewRuleType = "builtin.prior-backup-check"- BuiltinRuleObjectOwnerCheck SQLReviewRuleType = "builtin.object-owner-check")func GetBuiltinRules(engine storepb.Engine) []*storepb.SQLReviewRule {switch engine {- case storepb.Engine_MYSQL, storepb.Engine_TIDB, storepb.Engine_MSSQL, storepb.Engine_ORACLE:+ case storepb.Engine_MYSQL, storepb.Engine_POSTGRES, storepb.Engine_TIDB, storepb.Engine_MSSQL, storepb.Engine_ORACLE:return []*storepb.SQLReviewRule{{Type: string(BuiltinRulePriorBackupCheck),@@ -19,23 +18,6 @@ func GetBuiltinRules(engine storepb.Engine) []*storepb.SQLReviewRule {Comment: "",},}- case storepb.Engine_POSTGRES:- return []*storepb.SQLReviewRule{- {- Type: string(BuiltinRulePriorBackupCheck),- Level: storepb.SQLReviewRuleLevel_ERROR,- Payload: "",- Engine: engine,- Comment: "",- },- {- Type: string(BuiltinRuleObjectOwnerCheck),- Level: storepb.SQLReviewRuleLevel_WARNING,- Payload: "",- Engine: engine,- Comment: "",- },- }default:return nil}diff --git a/backend/plugin/advisor/code.go b/backend/plugin/advisor/code.goindex 9a28ece621..4f2619f03e 100644--- a/backend/plugin/advisor/code.go+++ b/backend/plugin/advisor/code.go@@ -62,6 +62,7 @@ const (StatementNoMaxExecutionTime Code = 235StatementNoAlgorithmOption Code = 236StatementNoLockOption Code = 237+ StatementObjectOwnerCheck Code = 238// 301 ~ 399 naming error code// 301 table naming advisor error code.@@ -202,7 +203,6 @@ const (// 2001 ~ 2099 builtin error code.BuiltinPriorBackupCheck Code = 2001- BuiltinObjectOwnerCheck Code = 2002)// Int returns the int type of code.@@ -649,8 +649,8 @@ const (// PostgreSQLBuiltinPriorBackupCheck is an advisor type for PostgreSQL do prior backup check.PostgreSQLBuiltinPriorBackupCheck Type = "bb.plugin.advisor.postgresql.builtin.prior-backup-check"- // PostgreSQLBuiltinObjectOwnerCheck is an advisor type for PostgreSQL do object owner check.- PostgreSQLBuiltinObjectOwnerCheck Type = "bb.plugin.advisor.postgresql.builtin.object-owner-check"+ // PostgreSQLStatementObjectOwnerCheck is an advisor type for PostgreSQL do object owner check.+ PostgreSQLStatementObjectOwnerCheck Type = "bb.plugin.advisor.postgresql.statement.object-owner-check"// PostgreSQLStatementMaximumLimitValue is an advisor type for PostgreSQL statement maximum limit value.PostgreSQLStatementMaximumLimitValue Type = "bb.plugin.advisor.postgresql.statement.maximum-limit-value"diff --git a/backend/plugin/advisor/pg/advisor_builtin_object_owner_check.go b/backend/plugin/advisor/pg/advisor_statement_object_owner_check.gosimilarity index 91%rename from backend/plugin/advisor/pg/advisor_builtin_object_owner_check.gorename to backend/plugin/advisor/pg/advisor_statement_object_owner_check.goindex d1ec6e08ab..2591b852e0 100644--- a/backend/plugin/advisor/pg/advisor_builtin_object_owner_check.go+++ b/backend/plugin/advisor/pg/advisor_statement_object_owner_check.go@@ -12,21 +12,21 @@ import ()var (- _ advisor.Advisor = (*BuiltinObjectOwnerCheckAdvisor)(nil)+ _ advisor.Advisor = (*StatementObjectOwnerCheckAdvisor)(nil))func init() {- advisor.Register(storepb.Engine_POSTGRES, advisor.PostgreSQLBuiltinObjectOwnerCheck, &BuiltinObjectOwnerCheckAdvisor{})+ advisor.Register(storepb.Engine_POSTGRES, advisor.PostgreSQLStatementObjectOwnerCheck, &StatementObjectOwnerCheckAdvisor{})}const (pgDatabaseOwner = "pg_database_owner")-type BuiltinObjectOwnerCheckAdvisor struct {+type StatementObjectOwnerCheckAdvisor struct {}-func (*BuiltinObjectOwnerCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*storepb.Advice, error) {+func (*StatementObjectOwnerCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*storepb.Advice, error) {var adviceList []*storepb.AdvicestmtList, ok := ctx.AST.([]ast.Node)if !ok {@@ -71,7 +71,7 @@ func (*BuiltinObjectOwnerCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*Status: level,Title: title,Content: fmt.Sprintf("Sequence \"%s\" is owned by \"%s\", but the current role is \"%s\".", n.Name.Name, owner, currentRole),- Code: advisor.BuiltinObjectOwnerCheck.Int32(),+ Code: advisor.StatementObjectOwnerCheck.Int32(),StartPosition: &storepb.Position{Line: int32(stmt.LastLine()),},@@ -102,7 +102,7 @@ func (*BuiltinObjectOwnerCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*Status: level,Title: title,Content: fmt.Sprintf("Table \"%s\" is owned by \"%s\", but the current role is \"%s\".", n.Table.Name, owner, currentRole),- Code: advisor.BuiltinObjectOwnerCheck.Int32(),+ Code: advisor.StatementObjectOwnerCheck.Int32(),StartPosition: &storepb.Position{Line: int32(stmt.LastLine()),},@@ -130,7 +130,7 @@ func (*BuiltinObjectOwnerCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*Status: level,Title: title,Content: fmt.Sprintf("Type \"%s\" is owned by \"%s\", but the current role is \"%s\".", n.Type.Name, owner, currentRole),- Code: advisor.BuiltinObjectOwnerCheck.Int32(),+ Code: advisor.StatementObjectOwnerCheck.Int32(),StartPosition: &storepb.Position{Line: int32(stmt.LastLine()),},@@ -154,7 +154,7 @@ func (*BuiltinObjectOwnerCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*Status: level,Title: title,Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),- Code: advisor.BuiltinObjectOwnerCheck.Int32(),+ Code: advisor.StatementObjectOwnerCheck.Int32(),StartPosition: &storepb.Position{Line: int32(stmt.LastLine()),},@@ -181,7 +181,7 @@ func (*BuiltinObjectOwnerCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*Status: level,Title: title,Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),- Code: advisor.BuiltinObjectOwnerCheck.Int32(),+ Code: advisor.StatementObjectOwnerCheck.Int32(),StartPosition: &storepb.Position{Line: int32(stmt.LastLine()),},@@ -208,7 +208,7 @@ func (*BuiltinObjectOwnerCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*Status: level,Title: title,Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),- Code: advisor.BuiltinObjectOwnerCheck.Int32(),+ Code: advisor.StatementObjectOwnerCheck.Int32(),StartPosition: &storepb.Position{Line: int32(stmt.LastLine()),},@@ -221,7 +221,7 @@ func (*BuiltinObjectOwnerCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*Status: level,Title: title,Content: fmt.Sprintf("Database \"%s\" is owned by \"%s\", but the current role is \"%s\".", dbMetadata.GetName(), owner, currentRole),- Code: advisor.BuiltinObjectOwnerCheck.Int32(),+ Code: advisor.StatementObjectOwnerCheck.Int32(),StartPosition: &storepb.Position{Line: int32(stmt.LastLine()),},@@ -248,7 +248,7 @@ func (*BuiltinObjectOwnerCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*Status: level,Title: title,Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),- Code: advisor.BuiltinObjectOwnerCheck.Int32(),+ Code: advisor.StatementObjectOwnerCheck.Int32(),StartPosition: &storepb.Position{Line: int32(stmt.LastLine()),},@@ -275,7 +275,7 @@ func (*BuiltinObjectOwnerCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*Status: level,Title: title,Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),- Code: advisor.BuiltinObjectOwnerCheck.Int32(),+ Code: advisor.StatementObjectOwnerCheck.Int32(),StartPosition: &storepb.Position{Line: int32(stmt.LastLine()),},@@ -302,7 +302,7 @@ func (*BuiltinObjectOwnerCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*Status: level,Title: title,Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),- Code: advisor.BuiltinObjectOwnerCheck.Int32(),+ Code: advisor.StatementObjectOwnerCheck.Int32(),StartPosition: &storepb.Position{Line: int32(stmt.LastLine()),},@@ -329,7 +329,7 @@ func (*BuiltinObjectOwnerCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*Status: level,Title: title,Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),- Code: advisor.BuiltinObjectOwnerCheck.Int32(),+ Code: advisor.StatementObjectOwnerCheck.Int32(),StartPosition: &storepb.Position{Line: int32(stmt.LastLine()),},@@ -356,7 +356,7 @@ func (*BuiltinObjectOwnerCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*Status: level,Title: title,Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),- Code: advisor.BuiltinObjectOwnerCheck.Int32(),+ Code: advisor.StatementObjectOwnerCheck.Int32(),StartPosition: &storepb.Position{Line: int32(stmt.LastLine()),},@@ -384,7 +384,7 @@ func (*BuiltinObjectOwnerCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*Status: level,Title: title,Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),- Code: advisor.BuiltinObjectOwnerCheck.Int32(),+ Code: advisor.StatementObjectOwnerCheck.Int32(),StartPosition: &storepb.Position{Line: int32(stmt.LastLine()),},@@ -413,7 +413,7 @@ func (*BuiltinObjectOwnerCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*Status: level,Title: title,Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),- Code: advisor.BuiltinObjectOwnerCheck.Int32(),+ Code: advisor.StatementObjectOwnerCheck.Int32(),StartPosition: &storepb.Position{Line: int32(stmt.LastLine()),},@@ -435,7 +435,7 @@ func (*BuiltinObjectOwnerCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*Status: level,Title: title,Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),- Code: advisor.BuiltinObjectOwnerCheck.Int32(),+ Code: advisor.StatementObjectOwnerCheck.Int32(),StartPosition: &storepb.Position{Line: int32(stmt.LastLine()),},@@ -464,7 +464,7 @@ func (*BuiltinObjectOwnerCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*Status: level,Title: title,Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),- Code: advisor.BuiltinObjectOwnerCheck.Int32(),+ Code: advisor.StatementObjectOwnerCheck.Int32(),StartPosition: &storepb.Position{Line: int32(stmt.LastLine()),},@@ -494,7 +494,7 @@ func (*BuiltinObjectOwnerCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*Status: level,Title: title,Content: fmt.Sprintf("Table \"%s\" is owned by \"%s\", but the current role is \"%s\".", table.Name, owner, currentRole),- Code: advisor.BuiltinObjectOwnerCheck.Int32(),+ Code: advisor.StatementObjectOwnerCheck.Int32(),StartPosition: &storepb.Position{Line: int32(stmt.LastLine()),},@@ -522,7 +522,7 @@ func (*BuiltinObjectOwnerCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*Status: level,Title: title,Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),- Code: advisor.BuiltinObjectOwnerCheck.Int32(),+ Code: advisor.StatementObjectOwnerCheck.Int32(),StartPosition: &storepb.Position{Line: int32(stmt.LastLine()),},@@ -550,7 +550,7 @@ func (*BuiltinObjectOwnerCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*Status: level,Title: title,Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),- Code: advisor.BuiltinObjectOwnerCheck.Int32(),+ Code: advisor.StatementObjectOwnerCheck.Int32(),StartPosition: &storepb.Position{Line: int32(stmt.LastLine()),},@@ -575,7 +575,7 @@ func (*BuiltinObjectOwnerCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*Status: level,Title: title,Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),- Code: advisor.BuiltinObjectOwnerCheck.Int32(),+ Code: advisor.StatementObjectOwnerCheck.Int32(),StartPosition: &storepb.Position{Line: int32(stmt.LastLine()),},@@ -595,7 +595,7 @@ func (*BuiltinObjectOwnerCheckAdvisor) Check(ctx advisor.Context, _ string) ([]*Status: level,Title: title,Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", n.Schema, owner, currentRole),- Code: advisor.BuiltinObjectOwnerCheck.Int32(),+ Code: advisor.StatementObjectOwnerCheck.Int32(),StartPosition: &storepb.Position{Line: int32(stmt.LastLine()),},diff --git a/backend/plugin/advisor/sql_review.go b/backend/plugin/advisor/sql_review.goindex 3abcf774f5..26fc8e54dc 100644--- a/backend/plugin/advisor/sql_review.go+++ b/backend/plugin/advisor/sql_review.go@@ -139,6 +139,8 @@ const (SchemaRuleStatementRequireAlgorithmOption = "statement.require-algorithm-option"// SchemaRuleStatementRequireLockOption require set LOCK option in ALTER TABLE statement.SchemaRuleStatementRequireLockOption = "statement.require-lock-option"+ // SchemaRuleStatementObjectOwnerCheck checks the object owner for the statement.+ SchemaRuleStatementObjectOwnerCheck = "statement.object-owner-check"// SchemaRuleTableRequirePK require the table to have a primary key.SchemaRuleTableRequirePK SQLReviewRuleType = "table.require-pk"// SchemaRuleTableNoFK require the table disallow the foreign key.@@ -1548,6 +1550,10 @@ func getAdvisorTypeByRule(ruleType SQLReviewRuleType, engine storepb.Engine) (Tyif engine == storepb.Engine_MYSQL || engine == storepb.Engine_MARIADB {return MySQLStatementRequireLockOption, nil}+ case SchemaRuleStatementObjectOwnerCheck:+ if engine == storepb.Engine_POSTGRES {+ return PostgreSQLStatementObjectOwnerCheck, nil+ }case SchemaRuleCommentLength:if engine == storepb.Engine_POSTGRES {return PostgreSQLCommentConvention, nil@@ -1602,10 +1608,6 @@ func getAdvisorTypeByRule(ruleType SQLReviewRuleType, engine storepb.Engine) (Tycase storepb.Engine_ORACLE:return OracleBuiltinPriorBackupCheck, nil}- case BuiltinRuleObjectOwnerCheck:- if engine == storepb.Engine_POSTGRES {- return PostgreSQLBuiltinObjectOwnerCheck, nil- }}return "", errors.Errorf("unknown SQL review rule type %v for %v", ruleType, engine)}diff --git a/frontend/src/components/PlanCheckRun/PlanCheckRunDetail.vue b/frontend/src/components/PlanCheckRun/PlanCheckRunDetail.vueindex 6c19104c66..2236248c74 100644--- a/frontend/src/components/PlanCheckRun/PlanCheckRunDetail.vue+++ b/frontend/src/components/PlanCheckRun/PlanCheckRunDetail.vue@@ -366,8 +366,6 @@ const builtinRuleLevel = (type: string): SQLReviewRuleLevel => {switch (type) {case "builtin.prior-backup-check":return SQLReviewRuleLevel.ERROR;- case "builtin.object-owner-check":- return SQLReviewRuleLevel.WARNING;default:return SQLReviewRuleLevel.ERROR;}diff --git a/frontend/src/locales/sql-review/en-US.json b/frontend/src/locales/sql-review/en-US.jsonindex 8203300397..ccd4f07d04 100644--- a/frontend/src/locales/sql-review/en-US.json+++ b/frontend/src/locales/sql-review/en-US.json@@ -720,9 +720,9 @@"title": "Prior backup feasibility check","description": "This rule checks whether a backup can be created before data changes. It verifies the existence of the backup target database and disallows non-supported scenarios. It's builtin and cannot skip."},- "builtin-object-owner-check": {+ "statement-object-owner-check": {"title": "Object owner check",- "description": "This rule checks whether the object owner for DDL is the same as the current user. It's builtin and cannot skip."+ "description": "This rule checks whether the object owner for DDL is the same as the current user."}},"level": {diff --git a/frontend/src/locales/sql-review/es-ES.json b/frontend/src/locales/sql-review/es-ES.jsonindex b1a4302ca1..721e12f58c 100644--- a/frontend/src/locales/sql-review/es-ES.json+++ b/frontend/src/locales/sql-review/es-ES.json@@ -720,9 +720,9 @@"title": "Comprobación previa de viabilidad de la copia de seguridad","description": "Esta regla verifica si se puede crear una copia de seguridad antes de que se modifiquen los datos. Verifica la existencia de la base de datos de destino de la copia de seguridad y rechaza los escenarios no admitidos. Está incorporada y no se puede omitir."},- "builtin-object-owner-check": {+ "statement-object-owner-check": {"title": "Verificación del propietario del objeto",- "description": "Esta regla verifica si el propietario del objeto para DDL es el mismo que el usuario actual. Está incorporada y no se puede omitir."+ "description": "Esta regla verifica si el propietario del objeto para DDL es el mismo que el usuario actual."}},"level": {diff --git a/frontend/src/locales/sql-review/ja-JP.json b/frontend/src/locales/sql-review/ja-JP.jsonindex 830698bd6a..b901fec438 100644--- a/frontend/src/locales/sql-review/ja-JP.json+++ b/frontend/src/locales/sql-review/ja-JP.json@@ -720,9 +720,9 @@"title": "事前のバックアップ実行可能性チェック","description": "このルールは、データが変更される前にバックアップを作成できるかどうかを確認します。バックアップ ターゲット データベースの存在を確認し、サポートされていないシナリオを禁止します。これは組み込みであり、スキップできません。"},- "builtin-object-owner-check": {+ "statement-object-owner-check": {"title": "オブジェクト所有者のチェック",- "description": "このルールは、DDLのオブジェクト所有者が現在のユーザーと同じであるかどうかを確認します。これは組み込みであり、スキップできません。"+ "description": "このルールは、DDLのオブジェクト所有者が現在のユーザーと同じであるかどうかを確認します。"}},"level": {diff --git a/frontend/src/locales/sql-review/zh-CN.json b/frontend/src/locales/sql-review/zh-CN.jsonindex 778ae05cc6..38722c47ee 100644--- a/frontend/src/locales/sql-review/zh-CN.json+++ b/frontend/src/locales/sql-review/zh-CN.json@@ -720,9 +720,9 @@"title": "事先备份可行性检查","description": "此规则检查是否可以在数据更改之前创建备份。它会验证备份目标数据库是否存在,并禁止不支持的方案。它是内置的,无法跳过。"},- "builtin-object-owner-check": {+ "statement-object-owner-check": {"title": "对象所有者检查",- "description": "此规则检查 DDL 的对象所有者是否与当前用户相同。内置规则,无法跳过。"+ "description": "此规则检查 DDL 的对象所有者是否与当前用户相同。"}},"level": {diff --git a/frontend/src/types/sql-review-schema.yaml b/frontend/src/types/sql-review-schema.yamlindex 42d7b19369..df38ecc088 100644--- a/frontend/src/types/sql-review-schema.yaml+++ b/frontend/src/types/sql-review-schema.yaml@@ -2196,3 +2196,6 @@- type: statement.non-transactionalcategory: STATEMENTengine: POSTGRES+- type: statement.object-owner-check+ category: STATEMENT+ engine: POSTGRES\ No newline at end of filediff --git a/frontend/src/types/sql-review.dev.yaml b/frontend/src/types/sql-review.dev.yamlindex cf94ff933b..9e7a05529a 100644--- a/frontend/src/types/sql-review.dev.yaml+++ b/frontend/src/types/sql-review.dev.yaml@@ -1485,3 +1485,6 @@ ruleList:- UUID- SLEEPengine: MYSQL+ - type: statement.object-owner-check+ level: WARNING+ engine: POSTGRES\ No newline at end of filediff --git a/frontend/src/types/sql-review.prod.yaml b/frontend/src/types/sql-review.prod.yamlindex 0718da0353..a579059277 100644--- a/frontend/src/types/sql-review.prod.yaml+++ b/frontend/src/types/sql-review.prod.yaml@@ -1587,3 +1587,6 @@ ruleList:- type: statement.non-transactionallevel: WARNINGengine: POSTGRES+ - type: statement.object-owner-check+ level: ERROR+ engine: POSTGRES