Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: add REQUEST_ACCESS approval source type for ACCESS_GRANT issues (#19341)
rebelicec3f1439a9da5
diff --git a/backend/api/mcp/gen/openapi.yaml b/backend/api/mcp/gen/openapi.yamlindex 30d07a29a8..49fbe75c2c 100644--- a/backend/api/mcp/gen/openapi.yaml+++ b/backend/api/mcp/gen/openapi.yaml@@ -18864,6 +18864,7 @@ components:When source is CREATE_DATABASE, support: resource.environment_id, resource.project_id, resource.db_engine, resource.database_nameWhen source is EXPORT_DATA, support: resource.environment_id, resource.project_id, resource.db_engine, resource.database_name, resource.schema_name, resource.table_nameWhen source is REQUEST_ROLE, support: resource.project_id, request.expiration_days, request.role+ When source is REQUEST_ACCESS, support: resource.environment_id, resource.project_id, request.unmaskFor examples:resource.environment_id == "prod" && statement.affected_rows >= 100@@ -18883,6 +18884,7 @@ components:- CREATE_DATABASE- EXPORT_DATA- REQUEST_ROLE+ - REQUEST_ACCESSbytebase.v1.WorkspaceProfileSetting:type: objectproperties:diff --git a/backend/common/cel.go b/backend/common/cel.goindex 87cc936fe9..ec12612ca0 100644--- a/backend/common/cel.go+++ b/backend/common/cel.go@@ -33,6 +33,7 @@ var ApprovalFactors = []cel.EnvOption{// Request scopecel.Variable(CELAttributeRequestExpirationDays, cel.IntType),cel.Variable(CELAttributeRequestRole, cel.StringType),+ cel.Variable(CELAttributeRequestUnmask, cel.BoolType),// Risk scopecel.Variable(CELAttributeRiskLevel, cel.StringType),// Size limitdiff --git a/backend/common/cel_attributes.go b/backend/common/cel_attributes.goindex d35f690b01..9d18645b1d 100644--- a/backend/common/cel_attributes.go+++ b/backend/common/cel_attributes.go@@ -45,6 +45,8 @@ const (CELAttributeRequestExpirationDays = "request.expiration_days"// CELAttributeRequestRole is the requested role.CELAttributeRequestRole = "request.role"+ // CELAttributeRequestUnmask indicates whether the request includes unmask permission.+ CELAttributeRequestUnmask = "request.unmask"// CELAttributeRequestTime is the timestamp of the request.CELAttributeRequestTime = "request.time")diff --git a/backend/generated-go/store/setting.pb.go b/backend/generated-go/store/setting.pb.goindex 105ad853c3..fb04ce59b7 100644--- a/backend/generated-go/store/setting.pb.go+++ b/backend/generated-go/store/setting.pb.go@@ -204,6 +204,7 @@ const (WorkspaceApprovalSetting_Rule_CREATE_DATABASE WorkspaceApprovalSetting_Rule_Source = 2WorkspaceApprovalSetting_Rule_EXPORT_DATA WorkspaceApprovalSetting_Rule_Source = 3WorkspaceApprovalSetting_Rule_REQUEST_ROLE WorkspaceApprovalSetting_Rule_Source = 4+ WorkspaceApprovalSetting_Rule_REQUEST_ACCESS WorkspaceApprovalSetting_Rule_Source = 5)// Enum value maps for WorkspaceApprovalSetting_Rule_Source.@@ -214,6 +215,7 @@ var (2: "CREATE_DATABASE",3: "EXPORT_DATA",4: "REQUEST_ROLE",+ 5: "REQUEST_ACCESS",}WorkspaceApprovalSetting_Rule_Source_value = map[string]int32{"SOURCE_UNSPECIFIED": 0,@@ -221,6 +223,7 @@ var ("CREATE_DATABASE": 2,"EXPORT_DATA": 3,"REQUEST_ROLE": 4,+ "REQUEST_ACCESS": 5,})@@ -2462,19 +2465,20 @@ const file_store_setting_proto_rawDesc = "" +" DATABASE_CHANGE_MODE_UNSPECIFIED\x10\x00\x12\f\n" +"\bPIPELINE\x10\x01\x12\n" +"\n" +- "\x06EDITOR\x10\x02\"\x94\x03\n" ++ "\x06EDITOR\x10\x02\"\xa9\x03\n" +"\x18WorkspaceApprovalSetting\x12C\n" +- "\x05rules\x18\x01 \x03(\v2-.bytebase.store.WorkspaceApprovalSetting.RuleR\x05rules\x1a\xb2\x02\n" ++ "\x05rules\x18\x01 \x03(\v2-.bytebase.store.WorkspaceApprovalSetting.RuleR\x05rules\x1a\xc7\x02\n" +"\x04Rule\x12<\n" +"\btemplate\x18\x01 \x01(\v2 .bytebase.store.ApprovalTemplateR\btemplate\x12/\n" +"\tcondition\x18\x02 \x01(\v2\x11.google.type.ExprR\tcondition\x12L\n" +- "\x06source\x18\x03 \x01(\x0e24.bytebase.store.WorkspaceApprovalSetting.Rule.SourceR\x06source\"m\n" ++ "\x06source\x18\x03 \x01(\x0e24.bytebase.store.WorkspaceApprovalSetting.Rule.SourceR\x06source\"\x81\x01\n" +"\x06Source\x12\x16\n" +"\x12SOURCE_UNSPECIFIED\x10\x00\x12\x13\n" +"\x0fCHANGE_DATABASE\x10\x01\x12\x13\n" +"\x0fCREATE_DATABASE\x10\x02\x12\x0f\n" +"\vEXPORT_DATA\x10\x03\x12\x10\n" +- "\fREQUEST_ROLE\x10\x04\"\x96\x06\n" ++ "\fREQUEST_ROLE\x10\x04\x12\x12\n" ++ "\x0eREQUEST_ACCESS\x10\x05\"\x96\x06\n" +"\x19DataClassificationSetting\x12\\\n" +"\aconfigs\x18\x01 \x03(\v2B.bytebase.store.DataClassificationSetting.DataClassificationConfigR\aconfigs\x1a\x9a\x05\n" +"\x18DataClassificationConfig\x12\x0e\n" +diff --git a/backend/generated-go/v1/setting_service.pb.go b/backend/generated-go/v1/setting_service.pb.goindex 860ee405d3..4d6dbc92dd 100644--- a/backend/generated-go/v1/setting_service.pb.go+++ b/backend/generated-go/v1/setting_service.pb.go@@ -202,6 +202,7 @@ const (WorkspaceApprovalSetting_Rule_CREATE_DATABASE WorkspaceApprovalSetting_Rule_Source = 2WorkspaceApprovalSetting_Rule_EXPORT_DATA WorkspaceApprovalSetting_Rule_Source = 3WorkspaceApprovalSetting_Rule_REQUEST_ROLE WorkspaceApprovalSetting_Rule_Source = 4+ WorkspaceApprovalSetting_Rule_REQUEST_ACCESS WorkspaceApprovalSetting_Rule_Source = 5)// Enum value maps for WorkspaceApprovalSetting_Rule_Source.@@ -212,6 +213,7 @@ var (2: "CREATE_DATABASE",3: "EXPORT_DATA",4: "REQUEST_ROLE",+ 5: "REQUEST_ACCESS",}WorkspaceApprovalSetting_Rule_Source_value = map[string]int32{"SOURCE_UNSPECIFIED": 0,@@ -219,6 +221,7 @@ var ("CREATE_DATABASE": 2,"EXPORT_DATA": 3,"REQUEST_ROLE": 4,+ "REQUEST_ACCESS": 5,})@@ -2136,6 +2139,7 @@ type WorkspaceApprovalSetting_Rule struct {// When source is CREATE_DATABASE, support: resource.environment_id, resource.project_id, resource.db_engine, resource.database_name// When source is EXPORT_DATA, support: resource.environment_id, resource.project_id, resource.db_engine, resource.database_name, resource.schema_name, resource.table_name// When source is REQUEST_ROLE, support: resource.project_id, request.expiration_days, request.role+ // When source is REQUEST_ACCESS, support: resource.environment_id, resource.project_id, request.unmask//// For examples:// resource.environment_id == "prod" && statement.affected_rows >= 100@@ -2951,19 +2955,20 @@ const file_v1_setting_service_proto_rawDesc = "" +"\x17ALERT_LEVEL_UNSPECIFIED\x10\x00\x12\b\n" +"\x04INFO\x10\x01\x12\v\n" +"\aWARNING\x10\x02\x12\f\n" +- "\bCRITICAL\x10\x03\"\x8b\x03\n" ++ "\bCRITICAL\x10\x03\"\xa0\x03\n" +"\x18WorkspaceApprovalSetting\x12@\n" +- "\x05rules\x18\x01 \x03(\v2*.bytebase.v1.WorkspaceApprovalSetting.RuleR\x05rules\x1a\xac\x02\n" ++ "\x05rules\x18\x01 \x03(\v2*.bytebase.v1.WorkspaceApprovalSetting.RuleR\x05rules\x1a\xc1\x02\n" +"\x04Rule\x129\n" +"\btemplate\x18\x01 \x01(\v2\x1d.bytebase.v1.ApprovalTemplateR\btemplate\x12/\n" +"\tcondition\x18\x02 \x01(\v2\x11.google.type.ExprR\tcondition\x12I\n" +- "\x06source\x18\x03 \x01(\x0e21.bytebase.v1.WorkspaceApprovalSetting.Rule.SourceR\x06source\"m\n" ++ "\x06source\x18\x03 \x01(\x0e21.bytebase.v1.WorkspaceApprovalSetting.Rule.SourceR\x06source\"\x81\x01\n" +"\x06Source\x12\x16\n" +"\x12SOURCE_UNSPECIFIED\x10\x00\x12\x13\n" +"\x0fCHANGE_DATABASE\x10\x01\x12\x13\n" +"\x0fCREATE_DATABASE\x10\x02\x12\x0f\n" +"\vEXPORT_DATA\x10\x03\x12\x10\n" +- "\fREQUEST_ROLE\x10\x04\"\x8a\x06\n" ++ "\fREQUEST_ROLE\x10\x04\x12\x12\n" ++ "\x0eREQUEST_ACCESS\x10\x05\"\x8a\x06\n" +"\x19DataClassificationSetting\x12Y\n" +"\aconfigs\x18\x01 \x03(\v2?.bytebase.v1.DataClassificationSetting.DataClassificationConfigR\aconfigs\x1a\x91\x05\n" +"\x18DataClassificationConfig\x12\x0e\n" +diff --git a/backend/runner/approval/runner.go b/backend/runner/approval/runner.goindex 0b188e4b95..25882ea728 100644--- a/backend/runner/approval/runner.go+++ b/backend/runner/approval/runner.go@@ -377,8 +377,7 @@ func buildCELVariablesForIssue(ctx context.Context, stores *store.Store, issue *case storepb.Issue_DATABASE_EXPORT:return buildCELVariablesForDataExport(ctx, stores, issue)case storepb.Issue_ACCESS_GRANT:- // TODO: approval flow for the ACCESS_GRANT issue- return nil, true, nil+ return buildCELVariablesForAccessGrant(ctx, stores, issue)default:return nil, false, errors.Errorf("unknown issue type %v", issue.Type)}@@ -734,6 +733,67 @@ func buildCELVariablesForGrantRequest(ctx context.Context, stores *store.Store,return celVarsList, true, nil}+// buildCELVariablesForAccessGrant builds CEL variables for ACCESS_GRANT issues.+func buildCELVariablesForAccessGrant(ctx context.Context, stores *store.Store, issue *store.IssueMessage) ([]map[string]any, bool, error) {+ payload := issue.Payload+ if payload.AccessGrantId == "" {+ return nil, false, errors.New("access grant id not found in issue payload")+ }++ accessGrantID := payload.AccessGrantId+ accessGrant, err := stores.GetAccessGrant(ctx, &store.FindAccessGrantMessage{ID: &accessGrantID})+ if err != nil {+ return nil, false, errors.Wrapf(err, "failed to get access grant %s", accessGrantID)+ }+ if accessGrant == nil {+ return nil, false, errors.Errorf("access grant %s not found", accessGrantID)+ }++ baseVars := map[string]any{+ common.CELAttributeResourceProjectID: issue.ProjectID,+ common.CELAttributeRequestUnmask: accessGrant.Payload.Unmask,+ }++ targets := accessGrant.Payload.Targets+ if len(targets) == 0 {+ return []map[string]any{baseVars}, true, nil+ }++ var celVarsList []map[string]any+ for _, target := range targets {+ instanceID, databaseName, err := common.GetInstanceDatabaseID(target)+ if err != nil {+ return nil, false, errors.Wrapf(err, "failed to parse target %q", target)+ }++ databases, err := stores.ListDatabases(ctx, &store.FindDatabaseMessage{+ InstanceID: &instanceID,+ DatabaseName: &databaseName,+ })+ if err != nil {+ return nil, false, errors.Wrapf(err, "failed to get database %q", target)+ }+ if len(databases) == 0 {+ continue+ }++ database := databases[0]+ celVars := maps.Clone(baseVars)+ if database.EffectiveEnvironmentID != nil {+ celVars[common.CELAttributeResourceEnvironmentID] = *database.EffectiveEnvironmentID+ } else {+ celVars[common.CELAttributeResourceEnvironmentID] = ""+ }+ celVarsList = append(celVarsList, celVars)+ }++ if len(celVarsList) == 0 {+ celVarsList = append(celVarsList, baseVars)+ }++ return celVarsList, true, nil+}+// getDatabasesForGrantRequest fetches database messages for the given database identifiers.// Used exclusively by grant request approval flow to retrieve database information.// Returns a deduplicated list of databases.@@ -806,8 +866,7 @@ func getApprovalSourceFromIssue(ctx context.Context, stores *store.Store, issuecase storepb.Issue_DATABASE_EXPORT:return storepb.WorkspaceApprovalSetting_Rule_EXPORT_DATA, nilcase storepb.Issue_ACCESS_GRANT:- // TODO: the approval source type for access request- return storepb.WorkspaceApprovalSetting_Rule_SOURCE_UNSPECIFIED, nil+ return storepb.WorkspaceApprovalSetting_Rule_REQUEST_ACCESS, nildefault:return storepb.WorkspaceApprovalSetting_Rule_SOURCE_UNSPECIFIED, errors.Errorf("unknown issue type %v", issue.Type)}diff --git a/proto/gen/grpc-doc/openapi.yaml b/proto/gen/grpc-doc/openapi.yamlindex cc67566b70..0579c88e03 100644--- a/proto/gen/grpc-doc/openapi.yaml+++ b/proto/gen/grpc-doc/openapi.yaml@@ -28325,6 +28325,7 @@ components:When source is CREATE_DATABASE, support: resource.environment_id, resource.project_id, resource.db_engine, resource.database_nameWhen source is EXPORT_DATA, support: resource.environment_id, resource.project_id, resource.db_engine, resource.database_name, resource.schema_name, resource.table_nameWhen source is REQUEST_ROLE, support: resource.project_id, request.expiration_days, request.role+ When source is REQUEST_ACCESS, support: resource.environment_id, resource.project_id, request.unmaskFor examples:resource.environment_id == "prod" && statement.affected_rows >= 100@@ -28344,6 +28345,7 @@ components:- CREATE_DATABASE- EXPORT_DATA- REQUEST_ROLE+ - REQUEST_ACCESSbytebase.v1.WorkspaceProfileSetting:type: objectproperties:diff --git a/proto/gen/grpc-doc/store/README.md b/proto/gen/grpc-doc/store/README.mdindex 8111725b99..bcc3c7f71a 100644--- a/proto/gen/grpc-doc/store/README.md+++ b/proto/gen/grpc-doc/store/README.md@@ -4579,6 +4579,7 @@ The severity level for SQL review rules.| CREATE_DATABASE | 2 | || EXPORT_DATA | 3 | || REQUEST_ROLE | 4 | |+| REQUEST_ACCESS | 5 | |diff --git a/proto/gen/grpc-doc/store/index.html b/proto/gen/grpc-doc/store/index.htmlindex 2c826c7e74..bb870350f2 100644--- a/proto/gen/grpc-doc/store/index.html+++ b/proto/gen/grpc-doc/store/index.html@@ -12635,6 +12635,12 @@ The default value is 100MB, we will use the default value if the setting not exi<td><p></p></td></tr>+ <tr>+ <td>REQUEST_ACCESS</td>+ <td>5</td>+ <td><p></p></td>+ </tr>+</tbody></table>diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.mdindex f250a2bf5c..b809bb7261 100644--- a/proto/gen/grpc-doc/v1/README.md+++ b/proto/gen/grpc-doc/v1/README.md@@ -2336,7 +2336,7 @@ The `source` field filters which rules apply. The `condition` field then evaluatAll supported variables: statement.affected_rows: affected row count in the DDL/DML, support "==", "!=", "<", "<=", ">", ">=" operations. statement.table_rows: table row count number, support "==", "!=", "<", "<=", ">", ">=" operations. resource.environment_id: the environment resource id, support "==", "!=", "in [xx]", "!(in [xx])" operations. resource.project_id: the project resource id, support "==", "!=", "in [xx]", "!(in [xx])", "contains()", "matches()", "startsWith()", "endsWith()" operations. resource.db_engine: the database engine type, support "==", "!=", "in [xx]", "!(in [xx])" operations. Check the Engine enum for values. statement.sql_type: the SQL type, support "==", "!=", "in [xx]", "!(in [xx])" operations. resource.database_name: the database name, support "==", "!=", "in [xx]", "!(in [xx])", "contains()", "matches()", "startsWith()", "endsWith()" operations. resource.schema_name: the schema name, support "==", "!=", "in [xx]", "!(in [xx])", "contains()", "matches()", "startsWith()", "endsWith()" operations. resource.table_name: the table name, support "==", "!=", "in [xx]", "!(in [xx])", "contains()", "matches()", "startsWith()", "endsWith()" operations. statement.text: the SQL statement, support "contains()", "matches()", "startsWith()", "endsWith()" operations. request.expiration_days: the role expiration days for the request, support "==", "!=", "<", "<=", ">", ">=" operations. request.role: the request role full name, support "==", "!=", "in [xx]", "!(in [xx])", "contains()", "matches()", "startsWith()", "endsWith()" operations.-When source is CHANGE_DATABASE, support: statement.*, resource.* (excluding request.*) When source is CREATE_DATABASE, support: resource.environment_id, resource.project_id, resource.db_engine, resource.database_name When source is EXPORT_DATA, support: resource.environment_id, resource.project_id, resource.db_engine, resource.database_name, resource.schema_name, resource.table_name When source is REQUEST_ROLE, support: resource.project_id, request.expiration_days, request.role+When source is CHANGE_DATABASE, support: statement.*, resource.* (excluding request.*) When source is CREATE_DATABASE, support: resource.environment_id, resource.project_id, resource.db_engine, resource.database_name When source is EXPORT_DATA, support: resource.environment_id, resource.project_id, resource.db_engine, resource.database_name, resource.schema_name, resource.table_name When source is REQUEST_ROLE, support: resource.project_id, request.expiration_days, request.role When source is REQUEST_ACCESS, support: resource.environment_id, resource.project_id, request.unmaskFor examples: resource.environment_id == "prod" && statement.affected_rows >= 100 resource.table_name.matches("sensitive_.*") && resource.db_engine == "MYSQL" || source | [WorkspaceApprovalSetting.Rule.Source](#bytebase-v1-WorkspaceApprovalSetting-Rule-Source) | | |@@ -2489,6 +2489,7 @@ We support three levels of AlertLevel: INFO, WARNING, and ERROR.| CREATE_DATABASE | 2 | || EXPORT_DATA | 3 | || REQUEST_ROLE | 4 | |+| REQUEST_ACCESS | 5 | |diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.htmlindex 44eccde7e3..f0f190837e 100644--- a/proto/gen/grpc-doc/v1/index.html+++ b/proto/gen/grpc-doc/v1/index.html@@ -7115,6 +7115,7 @@ When source is CHANGE_DATABASE, support: statement.*, resource.* (excluding requWhen source is CREATE_DATABASE, support: resource.environment_id, resource.project_id, resource.db_engine, resource.database_nameWhen source is EXPORT_DATA, support: resource.environment_id, resource.project_id, resource.db_engine, resource.database_name, resource.schema_name, resource.table_nameWhen source is REQUEST_ROLE, support: resource.project_id, request.expiration_days, request.role+When source is REQUEST_ACCESS, support: resource.environment_id, resource.project_id, request.unmaskFor examples:resource.environment_id == "prod" && statement.affected_rows >= 100@@ -7602,6 +7603,12 @@ Default to this mode.</p></td><td><p></p></td></tr>+ <tr>+ <td>REQUEST_ACCESS</td>+ <td>5</td>+ <td><p></p></td>+ </tr>+</tbody></table>diff --git a/proto/store/store/setting.proto b/proto/store/store/setting.protoindex eac1c29e6d..e609379a8e 100644--- a/proto/store/store/setting.proto+++ b/proto/store/store/setting.proto@@ -155,6 +155,7 @@ message WorkspaceApprovalSetting {CREATE_DATABASE = 2;EXPORT_DATA = 3;REQUEST_ROLE = 4;+ REQUEST_ACCESS = 5;}}repeated Rule rules = 1;diff --git a/proto/v1/v1/setting_service.proto b/proto/v1/v1/setting_service.protoindex ac168686ae..b63268a686 100644--- a/proto/v1/v1/setting_service.proto+++ b/proto/v1/v1/setting_service.proto@@ -299,6 +299,7 @@ message WorkspaceApprovalSetting {// When source is CREATE_DATABASE, support: resource.environment_id, resource.project_id, resource.db_engine, resource.database_name// When source is EXPORT_DATA, support: resource.environment_id, resource.project_id, resource.db_engine, resource.database_name, resource.schema_name, resource.table_name// When source is REQUEST_ROLE, support: resource.project_id, request.expiration_days, request.role+ // When source is REQUEST_ACCESS, support: resource.environment_id, resource.project_id, request.unmask//// For examples:// resource.environment_id == "prod" && statement.affected_rows >= 100@@ -311,6 +312,7 @@ message WorkspaceApprovalSetting {CREATE_DATABASE = 2;EXPORT_DATA = 3;REQUEST_ROLE = 4;+ REQUEST_ACCESS = 5;}}repeated Rule rules = 1;