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: standardize CEL attribute naming with constants (#17663)
Danny Xuf7d76c3d026f
diff --git a/backend/api/v1/release_service_check.go b/backend/api/v1/release_service_check.goindex f034d84d05..4ecb075adc 100644--- a/backend/api/v1/release_service_check.go+++ b/backend/api/v1/release_service_check.go@@ -241,17 +241,17 @@ loop:checkResult.AffectedRows = summaryReport.AffectedRowsresp.AffectedRows += summaryReport.AffectedRows- commonArgs := map[string]any{- "resource.environment_id": "",- "resource.project_id": database.ProjectID,- "resource.instance_id": instance.ResourceID,- "resource.database_name": database.DatabaseName,- // convert to string type otherwise cel-go will complain that storepb.Engine is not string type.- "resource.db_engine": engine.String(),- "statement.text": statement,- }+ environmentID := ""if database.EffectiveEnvironmentID != nil {- commonArgs["resource.environment_id"] = *database.EffectiveEnvironmentID+ environmentID = *database.EffectiveEnvironmentID+ }+ commonArgs := map[string]any{+ common.CELAttributeResourceEnvironmentID: environmentID,+ common.CELAttributeResourceProjectID: database.ProjectID,+ common.CELAttributeResourceInstanceID: instance.ResourceID,+ common.CELAttributeResourceDatabaseName: database.DatabaseName,+ common.CELAttributeResourceDBEngine: engine.String(),+ common.CELAttributeStatementText: statement,}riskLevel, err := CalculateRiskLevelWithOptionalSummaryReport(ctx, risks, commonArgs, getRiskSourceFromChangeType(changeType), summaryReport)if err != nil {diff --git a/backend/api/v1/risk_service_calculator.go b/backend/api/v1/risk_service_calculator.goindex ff667aec8d..442ae634fa 100644--- a/backend/api/v1/risk_service_calculator.go+++ b/backend/api/v1/risk_service_calculator.go@@ -83,8 +83,8 @@ func CalculateRiskLevelWithOptionalSummaryReport(}}}- args["statement.affected_rows"] = summaryReport.AffectedRows- args["statement.table_rows"] = tableRows+ args[common.CELAttributeStatementAffectedRows] = summaryReport.AffectedRows+ args[common.CELAttributeStatementTableRows] = tableRowsvar tableNames []stringfor _, db := range summaryReport.GetChangedResources().GetDatabases() {for _, schema := range db.GetSchemas() {@@ -94,9 +94,9 @@ func CalculateRiskLevelWithOptionalSummaryReport(}}for _, statementType := range summaryReport.StatementTypes {- args["statement.sql_type"] = statementType+ args[common.CELAttributeStatementSQLType] = statementTypefor _, tableName := range tableNames {- args["resource.table_name"] = tableName+ args[common.CELAttributeResourceTableName] = tableNameout, _, err := prg.Eval(args)if err != nil {return 0, errors.Wrap(err, "failed to eval expression")diff --git a/backend/api/v1/sql_service.go b/backend/api/v1/sql_service.goindex ba22a6e32f..b0fc26279e 100644--- a/backend/api/v1/sql_service.go+++ b/backend/api/v1/sql_service.go@@ -1429,11 +1429,11 @@ func (s *SQLService) accessCheck(if span.Type == parserbase.Select {for column := range span.SourceColumns {attributes := map[string]any{- "request.time": time.Now(),- "request.row_limit": limit,- "resource.database": common.FormatDatabase(instance.ResourceID, column.Database),- "resource.schema_name": column.Schema,- "resource.table_name": column.Table,+ common.CELAttributeRequestTime: time.Now(),+ common.CELAttributeRequestRowLimit: limit,+ common.CELAttributeResourceDatabase: common.FormatDatabase(instance.ResourceID, column.Database),+ common.CELAttributeResourceSchemaName: column.Schema,+ common.CELAttributeResourceTableName: column.Table,}databaseMessage, err := s.store.GetDatabaseV2(ctx, &store.FindDatabaseMessage{@@ -1470,11 +1470,11 @@ func (s *SQLService) accessCheck(return connect.NewError(connect.CodeInternal, errors.Errorf("failed to check access control for database: %q, error %v", column.Database, err))}if !ok {- resource := attributes["resource.database"]- if schema, ok := attributes["resource.schema_name"]; ok && schema != "" {+ resource := attributes[common.CELAttributeResourceDatabase]+ if schema, ok := attributes[common.CELAttributeResourceSchemaName]; ok && schema != "" {resource = fmt.Sprintf("%s/schemas/%s", resource, schema)}- if table, ok := attributes["resource.table_name"]; ok && table != "" {+ if table, ok := attributes[common.CELAttributeResourceTableName]; ok && table != "" {resource = fmt.Sprintf("%s/tables/%s", resource, table)}return connect.NewError(diff --git a/backend/common/cel.go b/backend/common/cel.goindex e02815afc0..3af5178270 100644--- a/backend/common/cel.go+++ b/backend/common/cel.go@@ -16,72 +16,72 @@ const celLimit = 1024 * 1024// RiskFactors are the variables when evaluating the risk level.var RiskFactors = []cel.EnvOption{- cel.Variable("resource.environment_id", cel.StringType),- cel.Variable("resource.project_id", cel.StringType),- cel.Variable("resource.instance_id", cel.StringType),- cel.Variable("resource.db_engine", cel.StringType),+ cel.Variable(CELAttributeResourceEnvironmentID, cel.StringType),+ cel.Variable(CELAttributeResourceProjectID, cel.StringType),+ cel.Variable(CELAttributeResourceInstanceID, cel.StringType),+ cel.Variable(CELAttributeResourceDBEngine, cel.StringType),- cel.Variable("resource.database_name", cel.StringType),- cel.Variable("resource.schema_name", cel.StringType),- cel.Variable("resource.table_name", cel.StringType),+ cel.Variable(CELAttributeResourceDatabaseName, cel.StringType),+ cel.Variable(CELAttributeResourceSchemaName, cel.StringType),+ cel.Variable(CELAttributeResourceTableName, cel.StringType),- cel.Variable("statement.affected_rows", cel.IntType),- cel.Variable("statement.table_rows", cel.IntType),- cel.Variable("statement.sql_type", cel.StringType),- cel.Variable("statement.text", cel.StringType),+ cel.Variable(CELAttributeStatementAffectedRows, cel.IntType),+ cel.Variable(CELAttributeStatementTableRows, cel.IntType),+ cel.Variable(CELAttributeStatementSQLType, cel.StringType),+ cel.Variable(CELAttributeStatementText, cel.StringType),- cel.Variable("request.expiration_days", cel.IntType),- cel.Variable("request.role", cel.StringType),+ cel.Variable(CELAttributeRequestExpirationDays, cel.IntType),+ cel.Variable(CELAttributeRequestRole, cel.StringType),}// ApprovalFactors are the variables when finding the approval template.var ApprovalFactors = []cel.EnvOption{- cel.Variable("level", cel.IntType),- cel.Variable("source", cel.StringType),+ cel.Variable(CELAttributeLevel, cel.IntType),+ cel.Variable(CELAttributeSource, cel.StringType),cel.ParserExpressionSizeLimit(celLimit),}// IAMPolicyConditionCELAttributes are the variables when evaluating IAM policy condition.var IAMPolicyConditionCELAttributes = []cel.EnvOption{- cel.Variable("resource.environment_id", cel.StringType),- cel.Variable("resource.database", cel.StringType),- cel.Variable("resource.schema_name", cel.StringType),- cel.Variable("resource.table_name", cel.StringType),- cel.Variable("request.row_limit", cel.IntType),- cel.Variable("request.time", cel.TimestampType),+ cel.Variable(CELAttributeResourceEnvironmentID, cel.StringType),+ cel.Variable(CELAttributeResourceDatabase, cel.StringType),+ cel.Variable(CELAttributeResourceSchemaName, cel.StringType),+ cel.Variable(CELAttributeResourceTableName, cel.StringType),+ cel.Variable(CELAttributeRequestRowLimit, cel.IntType),+ cel.Variable(CELAttributeRequestTime, cel.TimestampType),cel.ParserExpressionSizeLimit(celLimit),}// MaskingRulePolicyCELAttributes are the variables when evaluating masking rule.var MaskingRulePolicyCELAttributes = []cel.EnvOption{- cel.Variable("resource.environment_id", cel.StringType),- cel.Variable("resource.project_id", cel.StringType),- cel.Variable("resource.instance_id", cel.StringType),- cel.Variable("resource.database_name", cel.StringType),- cel.Variable("resource.schema_name", cel.StringType),- cel.Variable("resource.table_name", cel.StringType),- cel.Variable("resource.column_name", cel.StringType),- cel.Variable("resource.classification_level", cel.StringType),+ cel.Variable(CELAttributeResourceEnvironmentID, cel.StringType),+ cel.Variable(CELAttributeResourceProjectID, cel.StringType),+ cel.Variable(CELAttributeResourceInstanceID, cel.StringType),+ cel.Variable(CELAttributeResourceDatabaseName, cel.StringType),+ cel.Variable(CELAttributeResourceSchemaName, cel.StringType),+ cel.Variable(CELAttributeResourceTableName, cel.StringType),+ cel.Variable(CELAttributeResourceColumnName, cel.StringType),+ cel.Variable(CELAttributeResourceClassificationLevel, cel.StringType),cel.ParserExpressionSizeLimit(celLimit),}// MaskingExceptionPolicyCELAttributes are the variables when evaluating masking exception.var MaskingExceptionPolicyCELAttributes = []cel.EnvOption{- cel.Variable("resource.instance_id", cel.StringType),- cel.Variable("resource.database_name", cel.StringType),- cel.Variable("resource.table_name", cel.StringType),- cel.Variable("resource.schema_name", cel.StringType),- cel.Variable("resource.column_name", cel.StringType),- cel.Variable("request.time", cel.TimestampType),+ cel.Variable(CELAttributeResourceInstanceID, cel.StringType),+ cel.Variable(CELAttributeResourceDatabaseName, cel.StringType),+ cel.Variable(CELAttributeResourceTableName, cel.StringType),+ cel.Variable(CELAttributeResourceSchemaName, cel.StringType),+ cel.Variable(CELAttributeResourceColumnName, cel.StringType),+ cel.Variable(CELAttributeRequestTime, cel.TimestampType),cel.ParserExpressionSizeLimit(celLimit),}// DatabaseGroupCELAttributes are the variables when evaluating database group conditions.var DatabaseGroupCELAttributes = []cel.EnvOption{- cel.Variable("resource.environment_id", cel.StringType),- cel.Variable("resource.instance_id", cel.StringType),- cel.Variable("resource.database_name", cel.StringType),- cel.Variable("resource.database_labels", cel.MapType(cel.StringType, cel.StringType)),+ cel.Variable(CELAttributeResourceEnvironmentID, cel.StringType),+ cel.Variable(CELAttributeResourceInstanceID, cel.StringType),+ cel.Variable(CELAttributeResourceDatabaseName, cel.StringType),+ cel.Variable(CELAttributeResourceDatabaseLabels, cel.MapType(cel.StringType, cel.StringType)),cel.ParserExpressionSizeLimit(celLimit),}@@ -230,10 +230,10 @@ func findField(callExpr *exprproto.Expr_Call, factors *QueryExportFactors) {if len(callExpr.Args) == 2 {idExpr := callExpr.Args[0].GetIdentExpr()if idExpr != nil {- if idExpr.Name == "resource.database" && callExpr.Function == "_==_" {+ if idExpr.Name == CELAttributeResourceDatabase && callExpr.Function == "_==_" {factors.Databases = append(factors.Databases, callExpr.Args[1].GetConstExpr().GetStringValue())}- if idExpr.Name == "resource.database" && callExpr.Function == "@in" {+ if idExpr.Name == CELAttributeResourceDatabase && callExpr.Function == "@in" {list := callExpr.Args[1].GetListExpr()for _, element := range list.Elements {factors.Databases = append(factors.Databases, element.GetConstExpr().GetStringValue())@@ -250,7 +250,7 @@ func findField(callExpr *exprproto.Expr_Call, factors *QueryExportFactors) {func EvalBindingCondition(expr string, requestTime time.Time) (bool, error) {input := map[string]any{- "request.time": requestTime,+ CELAttributeRequestTime: requestTime,}return doEvalBindingCondition(expr, input)}diff --git a/backend/common/cel_attributes.go b/backend/common/cel_attributes.gonew file mode 100644index 0000000000..48c5ce251e--- /dev/null+++ b/backend/common/cel_attributes.go@@ -0,0 +1,60 @@+//nolint:revive+package common++// CEL attribute names for resource scope.+const (+ // CELAttributeResourceEnvironmentID is the environment ID of the resource.+ CELAttributeResourceEnvironmentID = "resource.environment_id"+ // CELAttributeResourceProjectID is the project ID of the resource.+ CELAttributeResourceProjectID = "resource.project_id"+ // CELAttributeResourceInstanceID is the instance ID of the resource.+ CELAttributeResourceInstanceID = "resource.instance_id"+ // CELAttributeResourceDatabaseName is the database name of the resource.+ CELAttributeResourceDatabaseName = "resource.database_name"+ // CELAttributeResourceSchemaName is the schema name of the resource.+ CELAttributeResourceSchemaName = "resource.schema_name"+ // CELAttributeResourceTableName is the table name of the resource.+ CELAttributeResourceTableName = "resource.table_name"+ // CELAttributeResourceColumnName is the column name of the resource.+ CELAttributeResourceColumnName = "resource.column_name"+ // CELAttributeResourceDBEngine is the database engine of the resource.+ CELAttributeResourceDBEngine = "resource.db_engine"+ // CELAttributeResourceDatabase is the full database name of the resource (used in IAM policy conditions).+ CELAttributeResourceDatabase = "resource.database"+ // CELAttributeResourceClassificationLevel is the classification level of the resource.+ CELAttributeResourceClassificationLevel = "resource.classification_level"+ // CELAttributeResourceDatabaseLabels is the database labels of the resource.+ CELAttributeResourceDatabaseLabels = "resource.database_labels"+)++// CEL attribute names for statement scope.+const (+ // CELAttributeStatementAffectedRows is the number of affected rows by the statement.+ CELAttributeStatementAffectedRows = "statement.affected_rows"+ // CELAttributeStatementTableRows is the total number of rows in the table.+ CELAttributeStatementTableRows = "statement.table_rows"+ // CELAttributeStatementSQLType is the SQL statement type (e.g., SELECT, INSERT, UPDATE, DELETE).+ CELAttributeStatementSQLType = "statement.sql_type"+ // CELAttributeStatementText is the full text of the SQL statement.+ CELAttributeStatementText = "statement.text"+)++// CEL attribute names for request scope.+const (+ // CELAttributeRequestExpirationDays is the number of days until the request expires.+ CELAttributeRequestExpirationDays = "request.expiration_days"+ // CELAttributeRequestRole is the requested role.+ CELAttributeRequestRole = "request.role"+ // CELAttributeRequestRowLimit is the maximum number of rows requested.+ CELAttributeRequestRowLimit = "request.row_limit"+ // CELAttributeRequestTime is the timestamp of the request.+ CELAttributeRequestTime = "request.time"+)++// CEL attribute names for approval scope (deprecated, kept for backward compatibility).+const (+ // CELAttributeLevel is the risk level (deprecated).+ CELAttributeLevel = "level"+ // CELAttributeSource is the risk source (deprecated).+ CELAttributeSource = "source"+)diff --git a/backend/runner/approval/runner.go b/backend/runner/approval/runner.goindex 9dc8cf1782..80d106e7d3 100644--- a/backend/runner/approval/runner.go+++ b/backend/runner/approval/runner.go@@ -586,15 +586,16 @@ func (r *Runner) getDatabaseDataExportIssueRisk(ctx context.Context, issue *storif err != nil {return 0, err}- args := map[string]any{- "resource.environment_id": "",- "resource.project_id": issue.Project.ResourceID,- "resource.instance_id": instance.ResourceID,- "resource.database_name": databaseName,- "resource.db_engine": instance.Metadata.GetEngine().String(),- }+ envID := ""if environmentID != nil {- args["resource.environment_id"] = *environmentID+ envID = *environmentID+ }+ args := map[string]any{+ common.CELAttributeResourceEnvironmentID: envID,+ common.CELAttributeResourceProjectID: issue.Project.ResourceID,+ common.CELAttributeResourceInstanceID: instance.ResourceID,+ common.CELAttributeResourceDatabaseName: databaseName,+ common.CELAttributeResourceDBEngine: instance.Metadata.GetEngine().String(),}vars, err := e.PartialVars(args)@@ -680,9 +681,9 @@ func (r *Runner) getGrantRequestIssueRisk(ctx context.Context, issue *store.Issu}args := map[string]any{- "resource.project_id": issue.Project.ResourceID,- "request.expiration_days": expirationDays,- "request.role": payload.GrantRequest.Role,+ common.CELAttributeResourceProjectID: issue.Project.ResourceID,+ common.CELAttributeRequestExpirationDays: expirationDays,+ common.CELAttributeRequestRole: payload.GrantRequest.Role,}if len(factors.Databases) == 0 {environments, err := r.store.GetEnvironmentSetting(ctx)@@ -690,7 +691,7 @@ func (r *Runner) getGrantRequestIssueRisk(ctx context.Context, issue *store.Issureturn 0, store.RiskSourceUnknown, false, err}for _, environment := range environments.GetEnvironments() {- args["resource.environment_id"] = environment.Id+ args[common.CELAttributeResourceEnvironmentID] = environment.Idvars, err := e.PartialVars(args)if err != nil {return 0, store.RiskSourceUnknown, false, err@@ -707,9 +708,9 @@ func (r *Runner) getGrantRequestIssueRisk(ctx context.Context, issue *store.Issufor _, database := range databaseMap {if database.EffectiveEnvironmentID != nil {- args["resource.environment_id"] = *database.EffectiveEnvironmentID+ args[common.CELAttributeResourceEnvironmentID] = *database.EffectiveEnvironmentID} else {- args["resource.environment_id"] = ""+ args[common.CELAttributeResourceEnvironmentID] = ""}vars, err := e.PartialVars(args)if err != nil {diff --git a/frontend/src/components/CustomApproval/Settings/components/RiskCenter/RiskDialog/template.ts b/frontend/src/components/CustomApproval/Settings/components/RiskCenter/RiskDialog/template.tsindex 89558e21d2..24e0077cf7 100644--- a/frontend/src/components/CustomApproval/Settings/components/RiskCenter/RiskDialog/template.ts+++ b/frontend/src/components/CustomApproval/Settings/components/RiskCenter/RiskDialog/template.ts@@ -6,6 +6,12 @@ import { t, te } from "@/plugins/i18n";import { useEnvironmentV1List } from "@/store";import { PresetRiskLevel, PresetRoleType } from "@/types";import { Risk_Source } from "@/types/proto-es/v1/risk_service_pb";+import {+ CEL_ATTRIBUTE_RESOURCE_ENVIRONMENT_ID,+ CEL_ATTRIBUTE_REQUEST_ROLE,+ CEL_ATTRIBUTE_STATEMENT_AFFECTED_ROWS,+ CEL_ATTRIBUTE_STATEMENT_SQL_TYPE,+} from "@/utils/cel-attributes";/*The risk for the production environment is considered to be high.@@ -44,7 +50,7 @@ export const useRuleTemplates = () => {expr: wrapAsGroup({type: ExprType.Condition,operator: "_==_",- args: ["request.role", PresetRoleType.PROJECT_OWNER],+ args: [CEL_ATTRIBUTE_REQUEST_ROLE, PresetRoleType.PROJECT_OWNER],}),level: PresetRiskLevel.HIGH,source: Risk_Source.REQUEST_ROLE,@@ -58,7 +64,7 @@ export const useRuleTemplates = () => {expr: wrapAsGroup({type: ExprType.Condition,operator: "_==_",- args: ["resource.environment_id", prod.value.id],+ args: [CEL_ATTRIBUTE_RESOURCE_ENVIRONMENT_ID, prod.value.id],}),level: PresetRiskLevel.HIGH,source: Risk_Source.SOURCE_UNSPECIFIED,@@ -74,17 +80,17 @@ export const useRuleTemplates = () => {{type: ExprType.Condition,operator: "_==_",- args: ["resource.environment_id", prod.value.id],+ args: [CEL_ATTRIBUTE_RESOURCE_ENVIRONMENT_ID, prod.value.id],},{type: ExprType.Condition,operator: "_>_",- args: ["statement.affected_rows", 10000],+ args: [CEL_ATTRIBUTE_STATEMENT_AFFECTED_ROWS, 10000],},{type: ExprType.Condition,operator: "@in",- args: ["statement.sql_type", ["UPDATE", "DELETE"]],+ args: [CEL_ATTRIBUTE_STATEMENT_SQL_TYPE, ["UPDATE", "DELETE"]],},],}),@@ -99,7 +105,7 @@ export const useRuleTemplates = () => {expr: wrapAsGroup({type: ExprType.Condition,operator: "_==_",- args: ["resource.environment_id", prod.value.id],+ args: [CEL_ATTRIBUTE_RESOURCE_ENVIRONMENT_ID, prod.value.id],}),level: PresetRiskLevel.MODERATE,source: Risk_Source.CREATE_DATABASE,@@ -114,7 +120,7 @@ export const useRuleTemplates = () => {expr: wrapAsGroup({type: ExprType.Condition,operator: "_==_",- args: ["resource.environment_id", dev.value.id],+ args: [CEL_ATTRIBUTE_RESOURCE_ENVIRONMENT_ID, dev.value.id],}),level: PresetRiskLevel.LOW,source: Risk_Source.SOURCE_UNSPECIFIED,diff --git a/frontend/src/plugins/cel/types/factor.ts b/frontend/src/plugins/cel/types/factor.tsindex f7dc8bba8a..72c276d9b7 100644--- a/frontend/src/plugins/cel/types/factor.ts+++ b/frontend/src/plugins/cel/types/factor.ts@@ -1,47 +1,73 @@+import {+ CEL_ATTRIBUTE_STATEMENT_AFFECTED_ROWS,+ CEL_ATTRIBUTE_STATEMENT_TABLE_ROWS,+ CEL_ATTRIBUTE_LEVEL,+ CEL_ATTRIBUTE_REQUEST_ROW_LIMIT,+ CEL_ATTRIBUTE_REQUEST_EXPIRATION_DAYS,+ CEL_ATTRIBUTE_SOURCE,+ CEL_ATTRIBUTE_RESOURCE_ENVIRONMENT_ID,+ CEL_ATTRIBUTE_RESOURCE_PROJECT_ID,+ CEL_ATTRIBUTE_RESOURCE_DATABASE_NAME,+ CEL_ATTRIBUTE_RESOURCE_SCHEMA_NAME,+ CEL_ATTRIBUTE_RESOURCE_TABLE_NAME,+ CEL_ATTRIBUTE_RESOURCE_INSTANCE_ID,+ CEL_ATTRIBUTE_RESOURCE_DB_ENGINE,+ CEL_ATTRIBUTE_STATEMENT_SQL_TYPE,+ CEL_ATTRIBUTE_STATEMENT_TEXT,+ CEL_ATTRIBUTE_REQUEST_ROLE,+ CEL_ATTRIBUTE_RESOURCE_DATABASE,+ CEL_ATTRIBUTE_RESOURCE_COLUMN_NAME,+ CEL_ATTRIBUTE_RESOURCE_CLASSIFICATION_LEVEL,+ CEL_ATTRIBUTE_REQUEST_TIME,+} from "@/utils/cel-attributes";+export const NumberFactorList = [// Risk related factors- "statement.affected_rows",- "statement.table_rows",- "level",+ CEL_ATTRIBUTE_STATEMENT_AFFECTED_ROWS,+ CEL_ATTRIBUTE_STATEMENT_TABLE_ROWS,+ CEL_ATTRIBUTE_LEVEL,// Grant request issue related factors- "request.row_limit",+ CEL_ATTRIBUTE_REQUEST_ROW_LIMIT,// Request query/export factors- "request.expiration_days",+ CEL_ATTRIBUTE_REQUEST_EXPIRATION_DAYS,] as const;export type NumberFactor = (typeof NumberFactorList)[number];export const StringFactorList = [// Risk related factors- "source",- "resource.environment_id",- "resource.project_id",- "resource.database_name",- "resource.schema_name",- "resource.table_name",- "resource.instance_id",- "resource.db_engine",- "statement.sql_type",- "statement.text",- "request.role",+ CEL_ATTRIBUTE_SOURCE,+ CEL_ATTRIBUTE_RESOURCE_ENVIRONMENT_ID,+ CEL_ATTRIBUTE_RESOURCE_PROJECT_ID,+ CEL_ATTRIBUTE_RESOURCE_DATABASE_NAME,+ CEL_ATTRIBUTE_RESOURCE_SCHEMA_NAME,+ CEL_ATTRIBUTE_RESOURCE_TABLE_NAME,+ CEL_ATTRIBUTE_RESOURCE_INSTANCE_ID,+ CEL_ATTRIBUTE_RESOURCE_DB_ENGINE,+ CEL_ATTRIBUTE_STATEMENT_SQL_TYPE,+ CEL_ATTRIBUTE_STATEMENT_TEXT,+ CEL_ATTRIBUTE_REQUEST_ROLE,// Grant request issue related factors- "resource.database",- "resource.schema_name",- "resource.table_name",+ CEL_ATTRIBUTE_RESOURCE_DATABASE,+ CEL_ATTRIBUTE_RESOURCE_SCHEMA_NAME,+ CEL_ATTRIBUTE_RESOURCE_TABLE_NAME,// Masking- "resource.column_name",+ CEL_ATTRIBUTE_RESOURCE_COLUMN_NAME,// Masking rule- "resource.classification_level",+ CEL_ATTRIBUTE_RESOURCE_CLASSIFICATION_LEVEL,] as const;export type StringFactor = (typeof StringFactorList)[number];-export const TimestampFactorList = ["request.time"] as const;+export const TimestampFactorList = [CEL_ATTRIBUTE_REQUEST_TIME] as const;export type TimestampFactor = (typeof TimestampFactorList)[number];-export const HighLevelFactorList = ["level", "source"] as const;+export const HighLevelFactorList = [+ CEL_ATTRIBUTE_LEVEL,+ CEL_ATTRIBUTE_SOURCE,+] as const;export type HighLevelFactor = (typeof HighLevelFactorList)[number];export type Factor =diff --git a/frontend/src/utils/cel-attributes.ts b/frontend/src/utils/cel-attributes.tsnew file mode 100644index 0000000000..2a30efb293--- /dev/null+++ b/frontend/src/utils/cel-attributes.ts@@ -0,0 +1,30 @@+// CEL attribute names for resource scope.+export const CEL_ATTRIBUTE_RESOURCE_ENVIRONMENT_ID = "resource.environment_id";+export const CEL_ATTRIBUTE_RESOURCE_PROJECT_ID = "resource.project_id";+export const CEL_ATTRIBUTE_RESOURCE_INSTANCE_ID = "resource.instance_id";+export const CEL_ATTRIBUTE_RESOURCE_DATABASE_NAME = "resource.database_name";+export const CEL_ATTRIBUTE_RESOURCE_SCHEMA_NAME = "resource.schema_name";+export const CEL_ATTRIBUTE_RESOURCE_TABLE_NAME = "resource.table_name";+export const CEL_ATTRIBUTE_RESOURCE_COLUMN_NAME = "resource.column_name";+export const CEL_ATTRIBUTE_RESOURCE_DB_ENGINE = "resource.db_engine";+export const CEL_ATTRIBUTE_RESOURCE_DATABASE = "resource.database";+export const CEL_ATTRIBUTE_RESOURCE_CLASSIFICATION_LEVEL =+ "resource.classification_level";+export const CEL_ATTRIBUTE_RESOURCE_DATABASE_LABELS =+ "resource.database_labels";++// CEL attribute names for statement scope.+export const CEL_ATTRIBUTE_STATEMENT_AFFECTED_ROWS = "statement.affected_rows";+export const CEL_ATTRIBUTE_STATEMENT_TABLE_ROWS = "statement.table_rows";+export const CEL_ATTRIBUTE_STATEMENT_SQL_TYPE = "statement.sql_type";+export const CEL_ATTRIBUTE_STATEMENT_TEXT = "statement.text";++// CEL attribute names for request scope.+export const CEL_ATTRIBUTE_REQUEST_EXPIRATION_DAYS = "request.expiration_days";+export const CEL_ATTRIBUTE_REQUEST_ROLE = "request.role";+export const CEL_ATTRIBUTE_REQUEST_ROW_LIMIT = "request.row_limit";+export const CEL_ATTRIBUTE_REQUEST_TIME = "request.time";++// CEL attribute names for approval scope (deprecated, kept for backward compatibility).+export const CEL_ATTRIBUTE_LEVEL = "level";+export const CEL_ATTRIBUTE_SOURCE = "source";diff --git a/frontend/src/utils/issue/cel.ts b/frontend/src/utils/issue/cel.tsindex c49b57a9a4..b2bc55771b 100644--- a/frontend/src/utils/issue/cel.ts+++ b/frontend/src/utils/issue/cel.ts@@ -16,6 +16,16 @@ import {displayRoleTitle,extractDatabaseResourceName,} from "@/utils";+import {+ CEL_ATTRIBUTE_REQUEST_TIME,+ CEL_ATTRIBUTE_REQUEST_ROW_LIMIT,+ CEL_ATTRIBUTE_RESOURCE_DATABASE,+ CEL_ATTRIBUTE_RESOURCE_SCHEMA_NAME,+ CEL_ATTRIBUTE_RESOURCE_TABLE_NAME,+ CEL_ATTRIBUTE_RESOURCE_COLUMN_NAME,+ CEL_ATTRIBUTE_RESOURCE_INSTANCE_ID,+ CEL_ATTRIBUTE_RESOURCE_DATABASE_NAME,+} from "@/utils/cel-attributes";interface DatabaseLevelCondition {database: string[];@@ -207,11 +217,11 @@ export const stringifyConditionExpression = ({}if (expirationTimestampInMS) {expression.push(- `request.time < timestamp("${dayjs(expirationTimestampInMS).toISOString()}")`+ `${CEL_ATTRIBUTE_REQUEST_TIME} < timestamp("${dayjs(expirationTimestampInMS).toISOString()}")`);}if (rowLimit) {- expression.push(`request.row_limit <= ${rowLimit}`);+ expression.push(`${CEL_ATTRIBUTE_REQUEST_ROW_LIMIT} <= ${rowLimit}`);}return expression.join(" && ");};@@ -230,17 +240,17 @@ const convertToCELString = (| TableLevelCondition): string {if ("table" in condition) {- return `resource.database == "${+ return `${CEL_ATTRIBUTE_RESOURCE_DATABASE} == "${condition.database- }" && resource.schema == "${+ }" && ${CEL_ATTRIBUTE_RESOURCE_SCHEMA_NAME} == "${condition.schema- }" && resource.table in ${JSON.stringify(condition.table)}`;+ }" && ${CEL_ATTRIBUTE_RESOURCE_TABLE_NAME} in ${JSON.stringify(condition.table)}`;} else if ("schema" in condition) {- return `resource.database == "${+ return `${CEL_ATTRIBUTE_RESOURCE_DATABASE} == "${condition.database- }" && resource.schema in ${JSON.stringify(condition.schema)}`;+ }" && ${CEL_ATTRIBUTE_RESOURCE_SCHEMA_NAME} in ${JSON.stringify(condition.schema)}`;} else {- return `resource.database in ${JSON.stringify(condition.database)}`;+ return `${CEL_ATTRIBUTE_RESOURCE_DATABASE} in ${JSON.stringify(condition.database)}`;}}@@ -313,7 +323,7 @@ export const convertFromExpr = (expr: Expr): ConditionExpression => {const [property, values] = expr.args;if (typeof property === "string" && Array.isArray(values)) {switch (property) {- case "resource.database": {+ case CEL_ATTRIBUTE_RESOURCE_DATABASE: {for (const value of values) {const databaseResource: DatabaseResource = {databaseFullName: value as string,@@ -322,7 +332,7 @@ export const convertFromExpr = (expr: Expr): ConditionExpression => {}break;}- case "resource.schema_name": {+ case CEL_ATTRIBUTE_RESOURCE_SCHEMA_NAME: {const databaseResource =conditionExpression.databaseResources?.pop();if (databaseResource) {@@ -334,7 +344,7 @@ export const convertFromExpr = (expr: Expr): ConditionExpression => {}break;}- case "resource.table_name": {+ case CEL_ATTRIBUTE_RESOURCE_TABLE_NAME: {const databaseResource =conditionExpression.databaseResources?.pop();if (databaseResource) {@@ -346,7 +356,7 @@ export const convertFromExpr = (expr: Expr): ConditionExpression => {}break;}- case "resource.column_name": {+ case CEL_ATTRIBUTE_RESOURCE_COLUMN_NAME: {const databaseResource =conditionExpression.databaseResources?.pop();if (databaseResource) {@@ -373,9 +383,9 @@ export const convertFromExpr = (expr: Expr): ConditionExpression => {};}switch (left) {- case "resource.instance_id":- case "resource.database_name":- case "resource.database": {+ case CEL_ATTRIBUTE_RESOURCE_INSTANCE_ID:+ case CEL_ATTRIBUTE_RESOURCE_DATABASE_NAME:+ case CEL_ATTRIBUTE_RESOURCE_DATABASE: {// should parse for next database.if (databaseResource.databaseFullName !== "") {conditionExpression.databaseResources?.push({@@ -388,33 +398,33 @@ export const convertFromExpr = (expr: Expr): ConditionExpression => {}}switch (left) {- case "resource.instance_id": {+ case CEL_ATTRIBUTE_RESOURCE_INSTANCE_ID: {databaseResource.instanceResourceId = right;if (databaseResource.databaseResourceId) {databaseResource.databaseFullName = `${instanceNamePrefix}${databaseResource.instanceResourceId}/${databaseNamePrefix}${databaseResource.databaseResourceId}`;}break;}- case "resource.database_name": {+ case CEL_ATTRIBUTE_RESOURCE_DATABASE_NAME: {databaseResource.databaseResourceId = right;if (databaseResource.instanceResourceId) {databaseResource.databaseFullName = `${instanceNamePrefix}${databaseResource.instanceResourceId}/${databaseNamePrefix}${databaseResource.databaseResourceId}`;}break;}- case "resource.database": {+ case CEL_ATTRIBUTE_RESOURCE_DATABASE: {databaseResource.databaseFullName = right;break;}- case "resource.schema_name": {+ case CEL_ATTRIBUTE_RESOURCE_SCHEMA_NAME: {databaseResource.schema = right;break;}- case "resource.table_name": {+ case CEL_ATTRIBUTE_RESOURCE_TABLE_NAME: {databaseResource.table = right;break;}- case "resource.column_name": {+ case CEL_ATTRIBUTE_RESOURCE_COLUMN_NAME: {if (right) {databaseResource.columns = [right];}@@ -424,20 +434,23 @@ export const convertFromExpr = (expr: Expr): ConditionExpression => {conditionExpression.databaseResources?.push(databaseResource);} else if (typeof right === "number") {// Deprecated. Use _<=_ instead.- if (left === "request.row_limit") {+ if (left === CEL_ATTRIBUTE_REQUEST_ROW_LIMIT) {conditionExpression.rowLimit = right;}}}} else if (expr.operator === "_<_") {const [left, right] = expr.args;- if (left === "request.time") {+ if (left === CEL_ATTRIBUTE_REQUEST_TIME) {conditionExpression.expiredTime = (right as Date).toISOString();}} else if (expr.operator === "_<=_") {const [left, right] = expr.args;- if (left === "request.row_limit" && typeof right === "number") {- if (left === "request.row_limit") {+ if (+ left === CEL_ATTRIBUTE_REQUEST_ROW_LIMIT &&+ typeof right === "number"+ ) {+ if (left === CEL_ATTRIBUTE_REQUEST_ROW_LIMIT) {conditionExpression.rowLimit = right;}}