Skip to content

Commit febccc1

Browse files
docs: add risk center tuts (#584)
* tuts add risk center * refactor
1 parent 8092f3d commit febccc1

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
---
2+
title: Risk Center Best Practice
3+
author: Cayden
4+
updated_at: 2025/04/08 16:15
5+
tags: Tutorial
6+
integrations: General
7+
level: Beginner
8+
estimated_time: '30 mins'
9+
description: This tutorial shows you how to configure risk rules in Bytebase to manage changes effectively.
10+
---
11+
12+
Database changes are high-stakes operations that can affect data integrity, performance, and business continuity. As teams scale, manually assessing risks becomes impractical.
13+
14+
Bytebase simplifies this with automated risk assessment, allowing you to define risk conditions and enforce security policies. In this tutorial, we'll show you how to configure risk rules in Bytebase to manage changes effectively.
15+
16+
## Bytebase Risk Identification
17+
18+
The risk assessment feature Bytebase provides, enables developers to automatically identify the risk level of every database change by defining various risk conditions and associating them with different security policies.
19+
20+
Bytebase allows risk conditions to be customized for different database operations, including **DDL**, **DML**, **data export**, and **query role requests**. The specific risk conditions include:
21+
22+
- **environment_id:** The environment in which the database resides (e.g., Test, Production).
23+
- **project_id:** The project to which the target database belongs.
24+
- **database_name:** The specific database name.
25+
- **table_name:** The specific table name.
26+
- **table_rows:** The total number of rows in a table, estimated from database statistics.
27+
- **db_engine:** The database engine type (e.g., MySQL, PostgreSQL).
28+
- **affected_rows:** The number of rows impacted by an SQL statement, estimated using database statistics and execution plans.
29+
- **sql_type:** The classification of SQL statements, including:
30+
31+
- **DML:** DELETE, INSERT, UPDATE
32+
- **DDL:** DROP, CREATE, ALTER, RENAME, TRUNCATE (applied to tables, views, indexes, and other database objects)
33+
34+
- **sql_statement:** Specific characteristics of the SQL statement, such as containing certain keywords.
35+
36+
Users can customize risk rules by combining these conditions based on their development standards and business requirements, assigning each rule a **high**, **medium**, or **low** risk level. When a change request is created, Bytebase automatically scans the SQL and provides a risk assessment based on predefined rules. **If an SQL statement matches multiple risk rules, the highest applicable risk level will be used for the final assessment**.
37+
38+
## Best Practices for Configuring Risk Rules
39+
40+
### Building Core Rule Sets Based on Four Key Conditions
41+
42+
To effectively assess the risk level of database changes, four key risk conditions should be prioritized: **environment_id**, **affected_rows**, **table_rows**, and **sql_type**.
43+
44+
- **environment_id:**
45+
- Production environments should always be considered **high** risk.
46+
- Pre-production environments (e.g., UAT) can be classified as **moderate** risk.
47+
- Development and testing environments can be set to **low** risk.
48+
49+
_If it's a pipeline rollout, only the highest risk level will be applied._
50+
51+
- **affected_rows:** (Primarily for DML operations such as UPDATE and DELETE):
52+
- In production, any single modification affecting more than 1,000 rows should be considered **high** risk.
53+
54+
- **table_rows:** (Primarily for DDL operations):
55+
- If a table contains more than 10 million rows, any schema change should be considered **high** risk.
56+
57+
- **sql_type:** Separate Risk Rules for DDL and DML
58+
- **DML:** UPDATE and DELETE operations should be considered **high** risk.
59+
- **DDL:** The following operations should be considered **high** risk across all database objects:
60+
- DROP, ALTER, RENAME, TRUNCATE
61+
- CREATE INDEX
62+
63+
### Adding Additional Conditions Based on Business Requirements
64+
65+
In addition to the key risk conditions, you can incorporate more risk conditions based on specific business requirements, enabling more precise risk identification and control.
66+
67+
- **project_id**: Focus on critical projects, reducing unnecessary alerts for non-essential databases.
68+
- **database_name**: Restrict monitoring to critical databases that require stricter change controls.
69+
- **table_name**:
70+
- If statistical information is inaccurate, making row-based risk assessment unreliable, explicitly defining critical tables can enhance precision.
71+
- For highly sensitive tables where no modifications are allowed, explicitly listing them ensures they are strictly controlled.
72+
73+
### Risk Rule Examples
74+
75+
**High-Risk policy for DDL:**
76+
77+
- All backward compatibility breaking changes in production databases
78+
79+
```text
80+
environment_id == Prod
81+
and
82+
sql_type not in (CREATE_EXTENSION, CREATE_FUNCTION, CREATE_PLACEMENT_POLICY, CREATE_SCHEMA, CREATE_SEQUENCE, CREATE_TABLE, CREATE_TRIGGER, CREATE_TYPE, CREATE_VIEW)
83+
```
84+
85+
- All DDL operations in large tables in production databases
86+
87+
```text
88+
environment_id == Prod
89+
and
90+
table_rows > 10000000
91+
```
92+
93+
- All DDL operations in critical databases in production databases
94+
95+
```text
96+
environment_id == Prod
97+
and
98+
database_name in (prod_db1, prod_db2)
99+
```
100+
101+
- All DDL operations in critical tables in production databases
102+
103+
```text
104+
environment_id == Prod
105+
and
106+
table_name in (table1, table2)
107+
```
108+
109+
**High-Risk policy for DML:**
110+
111+
- All DELETE and UPDATE operations in production databases
112+
113+
```text
114+
environment_id == Prod
115+
and
116+
sql_type in (DELETE, UPDATE)
117+
```
118+
119+
- All DML operations affected more than 1000 rows in production databases
120+
121+
```text
122+
environment_id == Prod
123+
and
124+
affected_rows > 1000
125+
```
126+
127+
## Next Steps
128+
129+
Now you have configured the risk rules in Bytebase. Based on this, next step is to map risk rules to security policies like custom approval policies to enhance the security of your database changes.

0 commit comments

Comments
 (0)