Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: support classification in global rules (#7958)

ecmadaoaec3037d87dd
diff --git a/backend/api/v1/sql_service.go b/backend/api/v1/sql_service.go
index bd5efa4a4c..43df49a9f3 100644
--- a/backend/api/v1/sql_service.go
+++ b/backend/api/v1/sql_service.go
@@ -1588,13 +1588,13 @@ func evaluateMaskingLevelOfColumn(databaseMessage *store.DatabaseMessage, schema
columnClassificationLevel := getClassificationLevelOfColumn(column.Classification, dataClassificationConfig)
for _, maskingRule := range maskingRulePolicy.Rules {
maskingRuleAttributes := map[string]any{
- "environment_id": databaseMessage.EnvironmentID,
- "project_id": databaseMessage.ProjectID,
- "instance_id": databaseMessage.InstanceID,
- "database_name": databaseMessage.DatabaseName,
- "schema_name": schemaName,
- "table_name": tableName,
- "column_classification_level": columnClassificationLevel,
+ "environment_id": databaseMessage.EnvironmentID,
+ "project_id": databaseMessage.ProjectID,
+ "instance_id": databaseMessage.InstanceID,
+ "database_name": databaseMessage.DatabaseName,
+ "schema_name": schemaName,
+ "table_name": tableName,
+ "classification_level": columnClassificationLevel,
}
pass, err := evaluateMaskingRulePolicyCondition(maskingRule.Condition.Expression, maskingRuleAttributes)
if err != nil {
diff --git a/backend/api/v1/sql_service_test.go b/backend/api/v1/sql_service_test.go
index 07185b75cc..8f8d2841ad 100644
--- a/backend/api/v1/sql_service_test.go
+++ b/backend/api/v1/sql_service_test.go
@@ -321,7 +321,7 @@ func TestEvalMaskingLevelOfColumn(t *testing.T) {
Rules: []*storepb.MaskingRulePolicy_MaskingRule{
{
// Classification hit.
- Condition: &expr.Expr{Expression: `(table_name == "no_table") || (column_classification_level == "S2")`},
+ Condition: &expr.Expr{Expression: `(table_name == "no_table") || (classification_level == "S2")`},
MaskingLevel: storepb.MaskingLevel_FULL,
},
},
@@ -345,7 +345,7 @@ func TestEvalMaskingLevelOfColumn(t *testing.T) {
Rules: []*storepb.MaskingRulePolicy_MaskingRule{
{
// Classification hit.
- Condition: &expr.Expr{Expression: `(table_name == "no_table") || (column_classification_level == "S2")`},
+ Condition: &expr.Expr{Expression: `(table_name == "no_table") || (classification_level == "S2")`},
MaskingLevel: storepb.MaskingLevel_FULL,
},
},
@@ -378,7 +378,7 @@ func TestEvalMaskingLevelOfColumn(t *testing.T) {
Rules: []*storepb.MaskingRulePolicy_MaskingRule{
{
// Classification hit.
- Condition: &expr.Expr{Expression: `(table_name == "no_table") || (column_classification_level == "S2")`},
+ Condition: &expr.Expr{Expression: `(table_name == "no_table") || (classification_level == "S2")`},
MaskingLevel: storepb.MaskingLevel_PARTIAL,
},
},
diff --git a/backend/common/convert.go b/backend/common/convert.go
index 13d52293ba..20125498b9 100644
--- a/backend/common/convert.go
+++ b/backend/common/convert.go
@@ -55,7 +55,7 @@ var MaskingRulePolicyCELAttributes = []cel.EnvOption{
cel.Variable("database_name", cel.StringType),
cel.Variable("schema_name", cel.StringType),
cel.Variable("table_name", cel.StringType),
- cel.Variable("column_classification_level", cel.StringType),
+ cel.Variable("classification_level", cel.StringType),
cel.ParserExpressionSizeLimit(celLimit),
}
diff --git a/frontend/src/components/SchemaTemplate/ClassificationLevelBadge.vue b/frontend/src/components/SchemaTemplate/ClassificationLevelBadge.vue
index 2a7433199f..2654becf8b 100644
--- a/frontend/src/components/SchemaTemplate/ClassificationLevelBadge.vue
+++ b/frontend/src/components/SchemaTemplate/ClassificationLevelBadge.vue
@@ -1,11 +1,5 @@
<template>
- <span
- v-if="level"
- :class="[
- 'px-1 py-0.5 rounded text-xs',
- bgColorList[Number(level.id) - 1] ?? 'bg-gray-200',
- ]"
- >
+ <span v-if="level" :class="['px-1 py-0.5 rounded text-xs', levelColor]">
{{ level.title }}
</span>
</template>
@@ -27,6 +21,13 @@ const bgColorList = [
"bg-red-500",
];
+const levelColor = computed(() => {
+ const index = (props.classificationConfig?.levels ?? []).findIndex(
+ (level) => level.id === props.levelId
+ );
+ return bgColorList[index] ?? "bg-gray-200";
+});
+
const level = computed(() => {
return (props.classificationConfig?.levels ?? []).find(
(level) => level.id === props.levelId
diff --git a/frontend/src/components/SensitiveData/GlobalMaskingRulesView.vue b/frontend/src/components/SensitiveData/GlobalMaskingRulesView.vue
index 5d2d8a6ad0..1d1a44eab2 100644
--- a/frontend/src/components/SensitiveData/GlobalMaskingRulesView.vue
+++ b/frontend/src/components/SensitiveData/GlobalMaskingRulesView.vue
@@ -118,6 +118,8 @@
:disabled="state.processing"
:masking-rule="item.rule"
:is-create="item.mode === 'CREATE'"
+ :factor-list="factorList"
+ :factor-options-map="factorOptionsMap"
@cancel="onCancel(item.rule.id, item.mode)"
@confirm="(rule: MaskingRulePolicy_MaskingRule) => onConfirm(rule)"
/>
@@ -128,10 +130,12 @@
<script lang="ts" setup>
import { NCheckbox, NPopconfirm } from "naive-ui";
+import type { SelectOption } from "naive-ui";
import { v4 as uuidv4 } from "uuid";
import { computed, reactive, nextTick, onMounted } from "vue";
import { useI18n } from "vue-i18n";
import BBBadge, { type BBBadgeStyle } from "@/bbkit/BBBadge.vue";
+import { Factor } from "@/plugins/cel";
import {
featureToRef,
pushNotification,
@@ -146,6 +150,12 @@ import {
MaskingRulePolicy_MaskingRule,
} from "@/types/proto/v1/org_policy_service";
import { arraySwap, hasWorkspacePermissionV1 } from "@/utils";
+import {
+ getClassificationLevelOptions,
+ getEnvironmentIdOptions,
+ getInstanceIdOptions,
+ getProjectIdOptions,
+} from "./components/utils";
type MaskingRuleMode = "CREATE" | "EDIT";
@@ -367,4 +377,43 @@ const onPolicyUpsert = async () => {
updateMask: ["payload"],
});
};
+
+const factorList = computed((): Factor[] => {
+ const list = [
+ "environment_id", // using `environment.resource_id`
+ "project_id", // using `project.resource_id`
+ "instance_id", // using `instance.resource_id`
+ "database_name",
+ "table_name",
+ ];
+
+ const classificationOptions = getClassificationLevelOptions();
+ if (classificationOptions.length > 0) {
+ list.push("classification_level");
+ }
+
+ return list;
+});
+
+const factorOptionsMap = computed((): Map<Factor, SelectOption[]> => {
+ return factorList.value.reduce((map, factor) => {
+ let options: SelectOption[] = [];
+ switch (factor) {
+ case "environment_id":
+ options = getEnvironmentIdOptions();
+ break;
+ case "instance_id":
+ options = getInstanceIdOptions();
+ break;
+ case "project_id":
+ options = getProjectIdOptions();
+ break;
+ case "classification_level":
+ options = getClassificationLevelOptions();
+ break;
+ }
+ map.set(factor, options);
+ return map;
+ }, new Map<Factor, SelectOption[]>());
+});
</script>
diff --git a/frontend/src/components/SensitiveData/components/MaskingRuleConfig.vue b/frontend/src/components/SensitiveData/components/MaskingRuleConfig.vue
index 1e57eb1884..dbeecdb7cd 100644
--- a/frontend/src/components/SensitiveData/components/MaskingRuleConfig.vue
+++ b/frontend/src/components/SensitiveData/components/MaskingRuleConfig.vue
@@ -10,7 +10,7 @@
:allow-admin="!readonly"
:factor-list="factorList"
:factor-support-dropdown="factorSupportDropdown"
- :factor-options-map="getFactorOptionsMap()"
+ :factor-options-map="factorOptionsMap"
:factor-operator-override-map="factorOperatorOverrideMap"
@update="state.dirty = true"
/>
@@ -54,7 +54,7 @@ import { NSelect, SelectOption } from "naive-ui";
import { computed, ref, onMounted, nextTick } from "vue";
import { useI18n } from "vue-i18n";
import ExprEditor from "@/components/ExprEditor";
-import type { ConditionGroupExpr } from "@/plugins/cel";
+import type { ConditionGroupExpr, Factor } from "@/plugins/cel";
import {
resolveCELExpr,
wrapAsGroup,
@@ -72,17 +72,14 @@ import {
convertCELStringToParsedExpr,
convertParsedExprToCELString,
} from "@/utils";
-import {
- factorList,
- getFactorOptionsMap,
- factorSupportDropdown,
- factorOperatorOverrideMap,
-} from "./utils";
+import { factorSupportDropdown, factorOperatorOverrideMap } from "./utils";
const props = defineProps<{
isCreate?: boolean;
readonly: boolean;
disabled: boolean;
+ factorList: Factor[];
+ factorOptionsMap: Map<Factor, SelectOption[]>;
maskingRule: MaskingRulePolicy_MaskingRule;
}>();
diff --git a/frontend/src/components/SensitiveData/components/utils.ts b/frontend/src/components/SensitiveData/components/utils.ts
index 233e7eb78c..746e52fb1f 100644
--- a/frontend/src/components/SensitiveData/components/utils.ts
+++ b/frontend/src/components/SensitiveData/components/utils.ts
@@ -10,6 +10,7 @@ import {
useEnvironmentV1Store,
useInstanceV1List,
useProjectV1ListByCurrentUser,
+ useSettingV1Store,
} from "@/store";
import {
extractEnvironmentResourceName,
@@ -17,15 +18,26 @@ import {
extractProjectResourceName,
} from "@/utils";
-export const factorList: Factor[] = [
- "environment_id", // using `environment.resource_id`
- "project_id", // using `project.resource_id`
- "instance_id", // using `instance.resource_id`
- "database_name",
- "table_name",
-];
+export const getClassificationLevelOptions = () => {
+ const settingStore = useSettingV1Store();
+ const setting = settingStore.getSettingByName(
+ "bb.workspace.data-classification"
+ );
+ if (!setting) {
+ return [];
+ }
+ const config = setting.value?.dataClassificationSettingValue?.configs ?? [];
+ if (config.length === 0) {
+ return [];
+ }
+
+ return config[0].levels.map<SelectOption>((level) => ({
+ label: level.title,
+ value: level.id,
+ }));
+};
-const getEnvironmentIdOptions = () => {
+export const getEnvironmentIdOptions = () => {
const environmentList = useEnvironmentV1Store().getEnvironmentList();
return environmentList.map<SelectOption>((env) => {
return {
@@ -35,7 +47,7 @@ const getEnvironmentIdOptions = () => {
});
};
-const getInstanceIdOptions = () => {
+export const getInstanceIdOptions = () => {
const { instanceList } = useInstanceV1List(false);
return instanceList.value.map<SelectOption>((ins) => {
return {
@@ -45,7 +57,7 @@ const getInstanceIdOptions = () => {
});
};
-const getProjectIdOptions = () => {
+export const getProjectIdOptions = () => {
const { projectList } = useProjectV1ListByCurrentUser();
return projectList.value.map<SelectOption>((proj) => ({
label: proj.title,
@@ -53,29 +65,11 @@ const getProjectIdOptions = () => {
}));
};
-export const getFactorOptionsMap = () => {
- return factorList.reduce((map, factor) => {
- let options: SelectOption[] = [];
- switch (factor) {
- case "environment_id":
- options = getEnvironmentIdOptions();
- break;
- case "instance_id":
- options = getInstanceIdOptions();
- break;
- case "project_id":
- options = getProjectIdOptions();
- break;
- }
- map.set(factor, options);
- return map;
- }, new Map<Factor, SelectOption[]>());
-};
-
export const factorSupportDropdown: Factor[] = [
"environment_id",
"instance_id",
"project_id",
+ "classification_level",
];
export const factorOperatorOverrideMap = new Map<Factor, Operator[]>([
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 0754eca6c3..8554c9dcc8 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -2941,7 +2941,8 @@
"sql_type": "SQL type",
"expiration_days": "Expiration days",
"export_rows": "Export rows",
- "table_name": "Table name"
+ "table_name": "Table name",
+ "classification_level": "Classification level"
}
}
}
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 7e716f6763..0275b3e577 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -2939,7 +2939,8 @@
"sql_type": "Tipo SQL",
"expiration_days": "Días de caducidad",
"export_rows": "Exportar filas",
- "table_name": "Nombre de la tabla"
+ "table_name": "Nombre de la tabla",
+ "classification_level": "Nivel de clasificación"
}
}
}
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 63e4ed16f7..1956039203 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -2934,7 +2934,8 @@
"sql_type": "SQL 类型",
"expiration_days": "过期天数",
"export_rows": "导出行数",
- "table_name": "表名称"
+ "table_name": "表名称",
+ "classification_level": "数据分级"
}
}
}
diff --git a/frontend/src/plugins/cel/types/factor.ts b/frontend/src/plugins/cel/types/factor.ts
index 381dc9c15c..f8160ccb7b 100644
--- a/frontend/src/plugins/cel/types/factor.ts
+++ b/frontend/src/plugins/cel/types/factor.ts
@@ -39,6 +39,8 @@ export const StringFactorList = [
// Masking
"resource.column_name",
"resource.schema_name",
+ // Masking rule
+ "classification_level",
] as const;
export type StringFactor = typeof StringFactorList[number];
diff --git a/frontend/src/plugins/cel/types/operator.ts b/frontend/src/plugins/cel/types/operator.ts
index 903404c2e1..9ee8247bcb 100644
--- a/frontend/src/plugins/cel/types/operator.ts
+++ b/frontend/src/plugins/cel/types/operator.ts
@@ -80,6 +80,7 @@ const OperatorList: Record<Factor, Operator[]> = {
...CollectionOperatorList,
...StringOperatorList,
]),
+ classification_level: uniq([...EqualityOperatorList]),
// Database group related fields.
"resource.environment_name": uniq(["_==_"]),
diff --git a/frontend/src/types/setting.ts b/frontend/src/types/setting.ts
index ca6021e599..f93accde44 100644
--- a/frontend/src/types/setting.ts
+++ b/frontend/src/types/setting.ts
@@ -8,6 +8,8 @@ export type SettingName =
| "bb.plugin.openai.key"
| "bb.plugin.openai.endpoint"
| "bb.enterprise.trial"
- | "bb.workspace.schema-template";
+ | "bb.workspace.schema-template"
+ | "bb.workspace.data-classification"
+ | "bb.workspace.semantic-category";
export const refreshTokenDurationInHours = 7 * 24;