Skip to content

Commit e65eb58

Browse files
d-bytebaseclaude
andauthored
chore: update CEL attribute names for Bytebase 3.11 compatibility (#153)
Update CEL expressions to use the new namespaced attribute format introduced in Bytebase 3.11. This migration aligns with the backend changes in migration 3.11/0004##migrate_cel_attribute_names.sql. Changes: - Risk policies: Update environment_id → resource.environment_id and affected_rows → statement.affected_rows - Masking policies: Add resource. prefix to environment_id, instance_id, and column_name attributes - IAM policies: Update CEL generation to use resource.schema_name and resource.table_name instead of resource.schema and resource.table - IAM policy parsing: Update to correctly parse expressions with new attribute names Files updated: - examples/setup/data_masking.tf - examples/setup/risk.tf - tutorials/4-2-risk.tf - tutorials/8-3-global-data-masking.tf - provider/resource_iam_policy.go - provider/data_source_iam_policy.go 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent a5a9103 commit e65eb58

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

examples/setup/data_masking.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ resource "bytebase_policy" "global_masking_policy" {
158158

159159
global_masking_policy {
160160
rules {
161-
condition = "environment_id in [\"test\"]"
161+
condition = "resource.environment_id in [\"test\"]"
162162
id = "69df1d15-abe5-4bc9-be38-f2a4bef3f7e0"
163163
semantic_type = "bb.default-partial"
164164
title = "Partial masking for test environment"
165165
}
166166
rules {
167-
condition = "instance_id in [\"prod-sample-instance\"]"
167+
condition = "resource.instance_id in [\"prod-sample-instance\"]"
168168
id = "90adb734-0808-4c9f-b281-1f76f7a1a29a"
169169
semantic_type = "bb.default"
170170
title = "Default masking for prod instance"

examples/setup/risk.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ resource "bytebase_risk" "risk" {
33
source = "DML"
44
level = 300
55
active = true
6-
condition = "environment_id == \"prod\" && affected_rows >= 100"
6+
condition = "resource.environment_id == \"prod\" && statement.affected_rows >= 100"
77
}

provider/data_source_iam_policy.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,15 @@ func flattenIAMPolicy(p *v1pb.IamPolicy) ([]interface{}, error) {
184184
`"`,
185185
)
186186
}
187-
if strings.HasPrefix(expression, `resource.schema == "`) {
187+
if strings.HasPrefix(expression, `resource.schema_name == "`) {
188188
rawCondition["schema"] = strings.TrimSuffix(
189-
strings.TrimPrefix(expression, `resource.schema == "`),
189+
strings.TrimPrefix(expression, `resource.schema_name == "`),
190190
`"`,
191191
)
192192
}
193-
if strings.HasPrefix(expression, `resource.table in [`) {
193+
if strings.HasPrefix(expression, `resource.table_name in [`) {
194194
tableStr := strings.TrimSuffix(
195-
strings.TrimPrefix(expression, `resource.table in [`),
195+
strings.TrimPrefix(expression, `resource.table_name in [`),
196196
`]`,
197197
)
198198
rawTableList := []interface{}{}

provider/resource_iam_policy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,14 @@ func convertToV1Condition(rawSchema interface{}) (*expr.Expr, error) {
134134
expressions = append(expressions, fmt.Sprintf(`resource.database == "%s"`, database))
135135
}
136136
if schema, ok := rawCondition["schema"].(string); ok {
137-
expressions = append(expressions, fmt.Sprintf(`resource.schema == "%s"`, schema))
137+
expressions = append(expressions, fmt.Sprintf(`resource.schema_name == "%s"`, schema))
138138
}
139139
if tables, ok := rawCondition["tables"].(*schema.Set); ok && tables.Len() > 0 {
140140
tableList := []string{}
141141
for _, table := range tables.List() {
142142
tableList = append(tableList, fmt.Sprintf(`"%s"`, table.(string)))
143143
}
144-
expressions = append(expressions, fmt.Sprintf(`resource.table in [%s]`, strings.Join(tableList, ",")))
144+
expressions = append(expressions, fmt.Sprintf(`resource.table_name in [%s]`, strings.Join(tableList, ",")))
145145
}
146146
if rowLimit, ok := rawCondition["row_limit"].(int); ok && rowLimit > 0 {
147147
expressions = append(expressions, fmt.Sprintf(`request.row_limit <= %d`, rowLimit))

tutorials/4-2-risk.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ resource "bytebase_risk" "dml_moderate" {
33
source = "DML"
44
level = 200
55
active = true
6-
condition = "environment_id == \"prod\" && affected_rows >= 100"
6+
condition = "resource.environment_id == \"prod\" && statement.affected_rows >= 100"
77
}
88

99
resource "bytebase_risk" "ddl_high" {
1010
title = "DDL High Risk"
1111
source = "DDL"
1212
level = 300
1313
active = true
14-
condition = "environment_id == \"prod\""
14+
condition = "resource.environment_id == \"prod\""
1515
}

tutorials/8-3-global-data-masking.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ resource "bytebase_policy" "global_masking_policy" {
1212
global_masking_policy {
1313

1414
rules {
15-
condition = "column_name == \"birth_date\""
15+
condition = "resource.column_name == \"birth_date\""
1616
id = "birth-date-mask"
1717
semantic_type = "date-year-mask"
1818
title = "Mask Birth Date Year"
1919
}
2020

2121
rules {
22-
condition = "column_name == \"last_name\""
22+
condition = "resource.column_name == \"last_name\""
2323
id = "last-name-first-letter-only"
2424
semantic_type = "name-first-letter-only"
2525
title = "Last Name Only Show First Letter"

0 commit comments

Comments
 (0)