Skip to content

Commit 05ca1f8

Browse files
authored
chore: update access control policy & sql review policy (#47)
* feat: support policy data source * chore: support CRUD policy resource * chore: support config sql review rules * chore: update docs * chore: update version * chore: update docs * chore: update docs * chore: update docs * chore: optimize * chore: update * chore: update version * chore: add tests * chore: update access control policy & sql review policy
1 parent f66e7c5 commit 05ca1f8

File tree

13 files changed

+229
-101
lines changed

13 files changed

+229
-101
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.7-alpha.6
1+
0.0.7-alpha.7

api/common.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,23 @@ const (
99
// Deleted is the state for an removed row.
1010
Deleted State = "DELETED"
1111
)
12+
13+
// EngineType is the type of the instance engine.
14+
type EngineType string
15+
16+
const (
17+
// EngineTypeMySQL is the database type for MYSQL.
18+
EngineTypeMySQL EngineType = "MYSQL"
19+
// EngineTypePostgres is the database type for POSTGRES.
20+
EngineTypePostgres EngineType = "POSTGRES"
21+
// EngineTypeTiDB is the database type for TiDB.
22+
EngineTypeTiDB EngineType = "TIDB"
23+
// EngineTypeSnowflake is the database type for SNOWFLAKE.
24+
EngineTypeSnowflake EngineType = "SNOWFLAKE"
25+
// EngineTypeClickHouse is the database type for CLICKHOUSE.
26+
EngineTypeClickHouse EngineType = "CLICKHOUSE"
27+
// EngineTypeMongoDB is the database type for MongoDB.
28+
EngineTypeMongoDB EngineType = "MONGODB"
29+
// EngineTypeSQLite is the database type for SQLite.
30+
EngineTypeSQLite EngineType = "SQLITE"
31+
)

api/instance.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
11
package api
22

3-
// EngineType is the type of the instance engine.
4-
type EngineType string
5-
6-
const (
7-
// EngineTypeMySQL is the database type for MYSQL.
8-
EngineTypeMySQL EngineType = "MYSQL"
9-
// EngineTypePostgres is the database type for POSTGRES.
10-
EngineTypePostgres EngineType = "POSTGRES"
11-
// EngineTypeTiDB is the database type for TiDB.
12-
EngineTypeTiDB EngineType = "TIDB"
13-
// EngineTypeSnowflake is the database type for SNOWFLAKE.
14-
EngineTypeSnowflake EngineType = "SNOWFLAKE"
15-
// EngineTypeClickHouse is the database type for CLICKHOUSE.
16-
EngineTypeClickHouse EngineType = "CLICKHOUSE"
17-
// EngineTypeMongoDB is the database type for MongoDB.
18-
EngineTypeMongoDB EngineType = "MONGODB"
19-
// EngineTypeSQLite is the database type for SQLite.
20-
EngineTypeSQLite EngineType = "SQLITE"
21-
)
22-
233
// InstanceMessage is the API message for an instance.
244
type InstanceMessage struct {
255
UID string `json:"uid"`

api/policy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ type PolicyMessage struct {
128128
type PolicyPatchMessage struct {
129129
InheritFromParent *bool `json:"inheritFromParent"`
130130
Type PolicyType `json:"type"`
131+
Enforce *bool `json:"enforce"`
131132

132133
// The policy payload
133134
DeploymentApprovalPolicy *DeploymentApprovalPolicy `json:"deploymentApprovalPolicy"`

api/sql_review.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,5 +156,6 @@ type NumberTypeRulePayload struct {
156156
type SQLReviewRule struct {
157157
Type SQLReviewRuleType `json:"type"`
158158
Level SQLReviewRuleLevel `json:"level"`
159+
Engine EngineType `json:"engine"`
159160
Payload string `json:"payload"`
160161
}

docs/resources/policy.md

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ Access Control Policy is the policy configuration for database access control. I
163163
Must set the `access_control_policy` if the policy type if `ACCESS_CONTROL`. It contains following attributes:
164164

165165
- `disallow_rules` (List of Object) The object contains following attribute:
166-
- `full_database` (Boolean) will apply to the full database.
166+
- `all_databases` (Boolean) will apply to all databases.
167167

168168
For example:
169169

@@ -183,7 +183,7 @@ resource "bytebase_policy" "access_control" {
183183
184184
access_control_policy {
185185
disallow_rules {
186-
full_database = true
186+
all_databases = true
187187
}
188188
}
189189
}
@@ -194,12 +194,6 @@ resource "bytebase_policy" "access_control" {
194194
environment = bytebase_environment.prod.resource_id
195195
instance = "<instance resource id for the database>"
196196
database = "employee"
197-
198-
access_control_policy {
199-
disallow_rules {
200-
full_database = true
201-
}
202-
}
203197
}
204198
```
205199

@@ -219,6 +213,10 @@ The rule should a object contains:
219213
- `ERROR`
220214
- `WARNING`
221215
- `DISABLED`
216+
- `engine` (String) The database engine for the rule. Should be one of:
217+
- `MYSQL`
218+
- `POSTGRES`
219+
- `TIDB`
222220
- `payload` (Object) The payload for SQL review rule.
223221

224222
Please check the doc for details: https://www.bytebase.com/docs/sql-review/review-rules/supported-rules
@@ -233,27 +231,31 @@ resource "bytebase_policy" "sql_review" {
233231
sql_review_policy {
234232
title = "SQL Review Policy for Test environment"
235233
rules {
236-
type = "statement.select.no-select-all"
237-
level = "ERROR"
234+
type = "statement.select.no-select-all"
235+
level = "ERROR"
236+
engine = "MYSQL"
238237
}
239238
rules {
240-
type = "naming.table"
241-
level = "ERROR"
239+
type = "naming.table"
240+
level = "ERROR"
241+
engine = "POSTGRES"
242242
payload {
243243
max_length = 99
244244
format = "^[a-z]+$"
245245
}
246246
}
247247
rules {
248-
type = "column.required"
249-
level = "WARNING"
248+
type = "column.required"
249+
level = "WARNING"
250+
engine = "TIDB"
250251
payload {
251252
list = ["id", "created_ts", "updated_ts"]
252253
}
253254
}
254255
rules {
255-
type = "column.auto-increment-initial-value"
256-
level = "DISABLED"
256+
type = "column.auto-increment-initial-value"
257+
level = "DISABLED"
258+
engine = "MYSQL"
257259
payload {
258260
number = 1
259261
}
@@ -288,8 +290,9 @@ resource "bytebase_policy" "sql_review" {
288290
sql_review_policy {
289291
title = "SQL Review Policy for Test environment"
290292
rules {
291-
type = "naming.table"
292-
level = "ERROR"
293+
type = "naming.table"
294+
level = "ERROR"
295+
engine = "MYSQL"
293296
payload {
294297
max_length = 99
295298
format = "^[a-z]+$"
@@ -316,8 +319,9 @@ resource "bytebase_policy" "sql_review" {
316319
sql_review_policy {
317320
title = "SQL Review Policy for Test environment"
318321
rules {
319-
type = "column.comment"
320-
level = "WARNING"
322+
type = "column.comment"
323+
level = "WARNING"
324+
engine = "MYSQL"
321325
payload {
322326
max_length = 99
323327
required = true
@@ -350,8 +354,9 @@ resource "bytebase_policy" "sql_review" {
350354
sql_review_policy {
351355
title = "SQL Review Policy for Test environment"
352356
rules {
353-
type = "column.auto-increment-initial-value"
354-
level = "WARNING"
357+
type = "column.auto-increment-initial-value"
358+
level = "WARNING"
359+
engine = "MYSQL"
355360
payload {
356361
number = 1
357362
}
@@ -382,8 +387,9 @@ resource "bytebase_policy" "sql_review" {
382387
sql_review_policy {
383388
title = "SQL Review Policy for Test environment"
384389
rules {
385-
type = "column.required"
386-
level = "WARNING"
390+
type = "column.required"
391+
level = "WARNING"
392+
engine = "MYSQL"
387393
payload {
388394
list = ["id", "created_ts", "updated_ts"]
389395
}

examples/environments/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
terraform {
33
required_providers {
44
bytebase = {
5-
version = "0.0.7-alpha.6"
5+
version = "0.0.7-alpha.7"
66
# For local development, please use "terraform.local/bytebase/bytebase" instead
77
source = "registry.terraform.io/bytebase/bytebase"
88
}

examples/instances/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
terraform {
33
required_providers {
44
bytebase = {
5-
version = "0.0.7-alpha.6"
5+
version = "0.0.7-alpha.7"
66
# For local development, please use "terraform.local/bytebase/bytebase" instead
77
source = "registry.terraform.io/bytebase/bytebase"
88
}

examples/policies/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
terraform {
33
required_providers {
44
bytebase = {
5-
version = "0.0.7-alpha.6"
5+
version = "0.0.7-alpha.7"
66
# For local development, please use "terraform.local/bytebase/bytebase" instead
77
source = "registry.terraform.io/bytebase/bytebase"
88
}

examples/roles/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
terraform {
22
required_providers {
33
bytebase = {
4-
version = "0.0.7-alpha.6"
4+
version = "0.0.7-alpha.7"
55
# For local development, please use "terraform.local/bytebase/bytebase" instead
66
source = "registry.terraform.io/bytebase/bytebase"
77
}

0 commit comments

Comments
 (0)