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: move redshift out of guard (#5530)
h3n4lb08af0f6a4d8
diff --git a/backend/plugin/db/redshift/redshift.go b/backend/plugin/db/redshift/redshift.goindex 55d9bbe1ce..06f1d5191c 100644--- a/backend/plugin/db/redshift/redshift.go+++ b/backend/plugin/db/redshift/redshift.go@@ -260,7 +260,7 @@ func (driver *Driver) Execute(ctx context.Context, statement string, createDatabstmt = strings.ReplaceAll(stmt, "EXECUTE FUNCTION", "EXECUTE PROCEDURE")}// Use superuser privilege to run privileged statements.- stmt = fmt.Sprintf("SET LOCAL ROLE NONE;%sSET LOCAL ROLE '%s';", stmt, owner)+ stmt = fmt.Sprintf("SET SESSION AUTHORIZATION NONE;%sSET SESSION AUTHORIZATION '%s';", stmt, owner)remainingStmts = append(remainingStmts, stmt)} else if isNonTransactionStatement(stmt) {nonTransactionStmts = append(nonTransactionStmts, stmt)@@ -282,7 +282,7 @@ func (driver *Driver) Execute(ctx context.Context, statement string, createDatabdefer tx.Rollback()// Set the current transaction role to the database owner so that the owner of created database will be the same as the database owner.- if _, err := tx.ExecContext(ctx, fmt.Sprintf("SET LOCAL ROLE '%s'", owner)); err != nil {+ if _, err := tx.ExecContext(ctx, fmt.Sprintf("SET SESSION AUTHORIZATION '%s'", owner)); err != nil {return 0, err}@@ -290,6 +290,11 @@ func (driver *Driver) Execute(ctx context.Context, statement string, createDatabif err != nil {return 0, err}+ // Restore the current transaction role to the current user.+ if _, err := tx.ExecContext(ctx, "SET SESSION AUTHORIZATION DEFAULT"); err != nil {+ log.Warn("Failed to restore the current transaction role to the current user", zap.Error(err))+ }+if err := tx.Commit(); err != nil {return 0, err}diff --git a/backend/server/issue.go b/backend/server/issue.goindex 5b5e27dda0..ab71a23a9a 100644--- a/backend/server/issue.go+++ b/backend/server/issue.go@@ -1304,24 +1304,19 @@ func getCreateDatabaseStatement(dbType db.Type, createDatabaseContext api.Createcase db.Oracle:return fmt.Sprintf("CREATE DATABASE %s;", databaseName), nilcase db.Redshift:+ options := make(map[string]string)if adminDatasourceUser != "" && createDatabaseContext.Owner != adminDatasourceUser {- stmt = fmt.Sprintf("GRANT \"%s\" TO \"%s\";\n", createDatabaseContext.Owner, adminDatasourceUser)+ options["OWNER"] = fmt.Sprintf("%q", createDatabaseContext.Owner)}- if createDatabaseContext.Collation == "" {- stmt = fmt.Sprintf("%sCREATE DATABASE \"%s\" ENCODING '%s';", stmt, databaseName, createDatabaseContext.CharacterSet)- } else {- stmt = fmt.Sprintf("%sCREATE DATABASE \"%s\" ENCODING '%s' LC_COLLATE '%s';", stmt, databaseName, createDatabaseContext.CharacterSet, createDatabaseContext.Collation)+ stmt := fmt.Sprintf("CREATE DATABASE \"%s\"", databaseName)+ if len(options) > 0 {+ list := make([]string, 0, len(options))+ for k, v := range options {+ list = append(list, fmt.Sprintf("%s=%s", k, v))+ }+ stmt = fmt.Sprintf("%s WITH\n\t%s", stmt, strings.Join(list, "\n\t"))}- // Set the database owner.- // We didn't use CREATE DATABASE WITH OWNER because RDS requires the current role to be a member of the database owner.- // However, people can still use ALTER DATABASE to change the owner afterwards.- // Error string below:- // query: CREATE DATABASE h1 WITH OWNER hello;- // ERROR: must be member of role "hello"- //- // For tenant project, the schema for the newly created database will belong to the same owner.- // TODO(d): alter schema "public" owner to the database owner.- return fmt.Sprintf("%s\nALTER DATABASE \"%s\" OWNER TO \"%s\";", stmt, databaseName, createDatabaseContext.Owner), nil+ return fmt.Sprintf("%s;", stmt), nil}return "", errors.Errorf("unsupported database type %s", dbType)}diff --git a/frontend/src/components/CreateDatabasePrepForm.vue b/frontend/src/components/CreateDatabasePrepForm.vueindex aed421b13e..9d86e8f055 100644--- a/frontend/src/components/CreateDatabasePrepForm.vue+++ b/frontend/src/components/CreateDatabasePrepForm.vue@@ -452,7 +452,8 @@ export default defineComponent({return (instance.engine !== "MONGODB" &&instance.engine !== "CLICKHOUSE" &&- instance.engine !== "SNOWFLAKE"+ instance.engine !== "SNOWFLAKE" &&+ instance.engine !== "REDSHIFT");});