Skip to content

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

chore: update sensitive data layout (#7761)

ecmadaobd36c4a08835
diff --git a/frontend/src/components/FeatureGuard/FeatureAttentionForInstanceLicense.vue b/frontend/src/components/FeatureGuard/FeatureAttentionForInstanceLicense.vue
index a2d71d8022..11313f93f3 100644
--- a/frontend/src/components/FeatureGuard/FeatureAttentionForInstanceLicense.vue
+++ b/frontend/src/components/FeatureGuard/FeatureAttentionForInstanceLicense.vue
@@ -33,7 +33,7 @@ interface LocalState {
const props = defineProps<{
style?: BBAttentionStyle;
feature: FeatureType;
- customClass: string;
+ customClass?: string;
}>();
const state = reactive<LocalState>({
diff --git a/frontend/src/components/SensitiveData/SensitiveColumnList.vue b/frontend/src/components/SensitiveData/SensitiveColumnList.vue
new file mode 100644
index 0000000000..662253d155
--- /dev/null
+++ b/frontend/src/components/SensitiveData/SensitiveColumnList.vue
@@ -0,0 +1,292 @@
+<template>
+ <div class="w-full mt-4 space-y-4">
+ <EnvironmentTabFilter
+ :environment="state.environment"
+ :include-all="true"
+ @update:environment="state.environment = $event"
+ />
+
+ <div class="textinfolabel">
+ {{ $t("settings.sensitive-data.description") }}
+ </div>
+
+ <BBGrid
+ v-if="hasSensitiveDataFeature"
+ :column-list="COLUMN_LIST"
+ :data-source="filteredColumnList"
+ class="border"
+ @click-row="clickRow"
+ >
+ <template #item="{ item }: { item: SensitiveColumn }">
+ <div class="bb-grid-cell">
+ {{ getMaskingLevelText(item.maskData.maskingLevel) }}
+ </div>
+ <div class="bb-grid-cell">
+ {{ item.maskData.column }}
+ </div>
+ <div class="bb-grid-cell">
+ {{
+ item.maskData.schema
+ ? `${item.maskData.schema}.${item.maskData.table}`
+ : item.maskData.table
+ }}
+ </div>
+ <div class="bb-grid-cell">
+ <DatabaseV1Name :database="item.database" :link="false" />
+ </div>
+ <div class="bb-grid-cell gap-x-1">
+ <InstanceV1Name
+ :instance="item.database.instanceEntity"
+ :link="false"
+ />
+ </div>
+ <div class="bb-grid-cell">
+ <EnvironmentV1Name
+ :environment="item.database.effectiveEnvironmentEntity"
+ :link="false"
+ />
+ </div>
+ <div class="bb-grid-cell">
+ <ProjectV1Name :project="item.database.projectEntity" :link="false" />
+ </div>
+ <div class="bb-grid-cell justify-center !px-2">
+ <NPopconfirm @positive-click="removeSensitiveColumn(item)">
+ <template #trigger>
+ <button
+ :disabled="!allowAdmin"
+ class="w-5 h-5 p-0.5 bg-white hover:bg-control-bg-hover rounded cursor-pointer disabled:cursor-not-allowed disabled:hover:bg-white disabled:text-gray-400"
+ @click.stop=""
+ >
+ <heroicons-outline:trash />
+ </button>
+ </template>
+
+ <div class="whitespace-nowrap">
+ {{ $t("settings.sensitive-data.remove-sensitive-column-tips") }}
+ </div>
+ </NPopconfirm>
+ </div>
+ </template>
+ </BBGrid>
+
+ <template v-else>
+ <BBGrid :column-list="COLUMN_LIST" :data-source="[]" class="border" />
+ <div class="w-full h-full flex flex-col items-center justify-center">
+ <img
+ src="../../assets/illustration/no-data.webp"
+ class="max-h-[30vh]"
+ />
+ </div>
+ </template>
+ </div>
+
+ <FeatureModal
+ feature="bb.feature.sensitive-data"
+ :open="state.showFeatureModal"
+ @cancel="state.showFeatureModal = false"
+ />
+</template>
+
+<script lang="ts" setup>
+import { uniq } from "lodash-es";
+import { NPopconfirm } from "naive-ui";
+import { computed, reactive, watch } from "vue";
+import { useI18n } from "vue-i18n";
+import { useRouter } from "vue-router";
+import { BBGrid, type BBGridColumn } from "@/bbkit";
+import {
+ DatabaseV1Name,
+ EnvironmentV1Name,
+ InstanceV1Name,
+ ProjectV1Name,
+} from "@/components/v2";
+import { featureToRef, useCurrentUserV1, useDatabaseV1Store } from "@/store";
+import {
+ usePolicyListByResourceTypeAndPolicyType,
+ usePolicyV1Store,
+} from "@/store/modules/v1/policy";
+import { ComposedDatabase, UNKNOWN_ENVIRONMENT_NAME } from "@/types";
+import { MaskingLevel, maskingLevelToJSON } from "@/types/proto/v1/common";
+import {
+ PolicyType,
+ MaskData,
+ PolicyResourceType,
+} from "@/types/proto/v1/org_policy_service";
+import { databaseV1Slug, hasWorkspacePermissionV1 } from "@/utils";
+
+type SensitiveColumn = {
+ database: ComposedDatabase;
+ maskData: MaskData;
+};
+
+interface LocalState {
+ environment: string;
+ showFeatureModal: boolean;
+ isLoading: boolean;
+ sensitiveColumnList: SensitiveColumn[];
+}
+
+const { t } = useI18n();
+const router = useRouter();
+const state = reactive<LocalState>({
+ showFeatureModal: false,
+ isLoading: false,
+ sensitiveColumnList: [],
+ environment: UNKNOWN_ENVIRONMENT_NAME,
+});
+const databaseStore = useDatabaseV1Store();
+const hasSensitiveDataFeature = featureToRef("bb.feature.sensitive-data");
+
+const currentUserV1 = useCurrentUserV1();
+const allowAdmin = computed(() => {
+ return hasWorkspacePermissionV1(
+ "bb.permission.workspace.manage-sensitive-data",
+ currentUserV1.value.userRole
+ );
+});
+
+const policyList = usePolicyListByResourceTypeAndPolicyType({
+ resourceType: PolicyResourceType.DATABASE,
+ policyType: PolicyType.MASKING,
+ showDeleted: false,
+});
+
+const updateList = async () => {
+ state.isLoading = true;
+ const distinctDatabaseIdList = uniq(
+ policyList.value.map((policy) => policy.resourceUid)
+ );
+ // Fetch or get all needed databases
+ await Promise.all(
+ distinctDatabaseIdList.map((databaseId) =>
+ databaseStore.getOrFetchDatabaseByUID(databaseId)
+ )
+ );
+
+ const sensitiveColumnList: SensitiveColumn[] = [];
+ for (let i = 0; i < policyList.value.length; i++) {
+ const policy = policyList.value[i];
+ if (!policy.maskingPolicy) {
+ continue;
+ }
+
+ const databaseId = policy.resourceUid;
+ const database = await databaseStore.getOrFetchDatabaseByUID(databaseId);
+
+ for (const maskData of policy.maskingPolicy.maskData) {
+ sensitiveColumnList.push({ database, maskData });
+ }
+ }
+ state.sensitiveColumnList = sensitiveColumnList;
+ state.isLoading = false;
+};
+
+watch(policyList, updateList, { immediate: true });
+
+const removeSensitiveColumn = (sensitiveColumn: SensitiveColumn) => {
+ if (!hasSensitiveDataFeature.value) {
+ state.showFeatureModal = true;
+ return;
+ }
+
+ const { table, column } = sensitiveColumn.maskData;
+ const policy = policyList.value.find(
+ (policy) => policy.resourceUid == sensitiveColumn.database.uid
+ );
+ if (!policy) return;
+ const maskData = policy.maskingPolicy?.maskData;
+ if (!maskData) return;
+
+ const index = maskData.findIndex(
+ (sensitiveData) =>
+ sensitiveData.table === table && sensitiveData.column === column
+ );
+ if (index >= 0) {
+ // mutate the list and the item directly
+ // so we don't need to re-fetch the whole list.
+ maskData.splice(index, 1);
+
+ usePolicyV1Store().updatePolicy(["payload"], {
+ name: policy.name,
+ type: PolicyType.MASKING,
+ resourceType: PolicyResourceType.DATABASE,
+ maskingPolicy: {
+ maskData,
+ },
+ });
+ }
+ updateList();
+};
+
+const COLUMN_LIST = computed((): BBGridColumn[] => [
+ {
+ title: t("settings.sensitive-data.masking-level.self"),
+ width: "minmax(auto, 1fr)",
+ },
+ {
+ title: t("database.column"),
+ width: "minmax(auto, 1fr)",
+ },
+ {
+ title: t("common.table"),
+ width: "minmax(auto, 1fr)",
+ },
+ {
+ title: t("common.database"),
+ width: "minmax(auto, 1fr)",
+ },
+ {
+ title: t("common.instance"),
+ width: "minmax(auto, 1fr)",
+ },
+ {
+ title: t("common.environment"),
+ width: "minmax(auto, 1fr)",
+ },
+ {
+ title: t("common.project"),
+ width: "minmax(auto, 1fr)",
+ },
+ {
+ title: t("common.operation"),
+ width: "minmax(auto, 6rem)",
+ class: "justify-center !px-2",
+ },
+]);
+
+const clickRow = (
+ item: SensitiveColumn,
+ section: number,
+ row: number,
+ e: MouseEvent
+) => {
+ let url = `/db/${databaseV1Slug(item.database)}?table=${item.maskData.table}`;
+ if (item.maskData.schema != "") {
+ url += `&schema=${item.maskData.schema}`;
+ }
+ if (e.ctrlKey || e.metaKey) {
+ window.open(url, "_blank");
+ } else {
+ router.push(url);
+ }
+};
+
+const filteredColumnList = computed(() => {
+ return state.sensitiveColumnList.filter((column) => {
+ if (state.environment === UNKNOWN_ENVIRONMENT_NAME) {
+ return true;
+ }
+ return (
+ column.database.effectiveEnvironmentEntity.name === state.environment
+ );
+ });
+});
+
+const getMaskingLevelText = (maskingLevel: MaskingLevel) => {
+ let level = maskingLevelToJSON(maskingLevel);
+ if (maskingLevel === MaskingLevel.MASKING_LEVEL_UNSPECIFIED) {
+ level = maskingLevelToJSON(MaskingLevel.FULL);
+ }
+ return t(`settings.sensitive-data.masking-level.${level.toLowerCase()}`);
+};
+</script>
diff --git a/frontend/src/components/SensitiveData/index.ts b/frontend/src/components/SensitiveData/index.ts
new file mode 100644
index 0000000000..e85770a4ad
--- /dev/null
+++ b/frontend/src/components/SensitiveData/index.ts
@@ -0,0 +1,3 @@
+import SensitiveColumnList from "./SensitiveColumnList.vue";
+
+export { SensitiveColumnList };
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 888d6ec8a0..9aeeacfcba 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -596,7 +596,18 @@
},
"sensitive-data": {
"description": "The query result of the following columns is displayed as \"******\". \nYou can mark more columns as sensitive data on the table details page.",
- "remove-sensitive-column-tips": "Expose this column?"
+ "remove-sensitive-column-tips": "Expose this column?",
+ "sensitive-column-list": "Sensitive Column List",
+ "global-masking-rule": "Global Masking Rule",
+ "data-feature": "Data Feature",
+ "add-rule": "Add rule",
+ "masking-level": {
+ "self": "Masking Level",
+ "selet-level": "Select level",
+ "none": "None",
+ "partial": "Partial",
+ "full": "Full"
+ }
},
"access-control": {
"description": "Configure approval flow to control data query and export. {link}",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 4354f98248..3ffe4254ed 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -594,7 +594,18 @@
},
"sensitive-data": {
"description": "El resultado de la consulta de las siguientes columnas se muestra como \"******\". \nPuede marcar más columnas como datos sensibles en la página de detalles de la tabla.",
- "remove-sensitive-column-tips": "¿Exponer esta columna?"
+ "remove-sensitive-column-tips": "¿Exponer esta columna?",
+ "sensitive-column-list": "Lista de columnas confidenciales",
+ "global-masking-rule": "Regla de enmascaramiento global",
+ "data-feature": "Característica de datos",
+ "add-rule": "Agregar regla",
+ "masking-level": {
+ "self": "Nivel de enmascaramiento",
+ "selet-level": "Selecciona el nivel",
+ "none": "Ninguna",
+ "partial": "Parcial",
+ "full": "Llena"
+ }
},
"access-control": {
"description": "Configura un flujo de aprobación para controlar la consulta y exportación de datos. {link}",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 3a3a2b3acb..3f446ba038 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -593,7 +593,17 @@
},
"sensitive-data": {
"description": "以下列的查询结果将会被显示为 \"******\"。在表详情页,您可以将多个列标记为敏感数据。",
- "remove-sensitive-column-tips": "不再对此列数据脱敏?"
+ "remove-sensitive-column-tips": "不再对此列数据脱敏?",
+ "sensitive-column-list": "敏感数据列表",
+ "global-masking-rule": "全局脱敏规则",
+ "data-feature": "数据特征",
+ "add-rule": "添加规则",
+ "masking-level": {
+ "self": "脱敏程度",
+ "none": "明文",
+ "partial": "半脱敏",
+ "full": "全脱敏"
+ }
},
"access-control": {
"description": "配置审批流来控制数据的查询和导出。{link}",
diff --git a/frontend/src/views/SettingWorkspaceSensitiveData.vue b/frontend/src/views/SettingWorkspaceSensitiveData.vue
index e4dbc2317e..d66bdf7094 100644
--- a/frontend/src/views/SettingWorkspaceSensitiveData.vue
+++ b/frontend/src/views/SettingWorkspaceSensitiveData.vue
@@ -6,254 +6,65 @@
/>
<FeatureAttention v-else feature="bb.feature.sensitive-data" />
- <div class="textinfolabel">
- {{ $t("settings.sensitive-data.description") }}
- </div>
-
- <BBGrid
- v-if="hasSensitiveDataFeature"
- :column-list="COLUMN_LIST"
- :data-source="state.sensitiveColumnList"
- class="border"
- @click-row="clickRow"
+ <BBTab
+ v-if="isDev()"
+ :tab-item-list="tabItemList"
+ :selected-index="state.selectedIndex"
+ reorder-model="NEVER"
+ @select-index="(index: number) => state.selectedIndex = index"
>
- <template #item="{ item }: { item: SensitiveColumn }">
- <div class="bb-grid-cell">
- {{ item.column }}
- </div>
- <div class="bb-grid-cell">
- {{ item.schema ? `${item.schema}.${item.table}` : item.table }}
- </div>
- <div class="bb-grid-cell">
- <DatabaseV1Name :database="item.database" :link="false" />
- </div>
- <div class="bb-grid-cell gap-x-1">
- <InstanceV1Name
- :instance="item.database.instanceEntity"
- :link="false"
- />
- </div>
- <div class="bb-grid-cell">
- <EnvironmentV1Name
- :environment="item.database.effectiveEnvironmentEntity"
- :link="false"
- />
- </div>
- <div class="bb-grid-cell">
- <ProjectV1Name :project="item.database.projectEntity" :link="false" />
- </div>
- <div class="bb-grid-cell justify-center !px-2">
- <NPopconfirm @positive-click="removeSensitiveColumn(item)">
- <template #trigger>
- <button
- :disabled="!allowAdmin"
- class="w-5 h-5 p-0.5 bg-white hover:bg-control-bg-hover rounded cursor-pointer disabled:cursor-not-allowed disabled:hover:bg-white disabled:text-gray-400"
- @click.stop=""
- >
- <heroicons-outline:trash />
- </button>
- </template>
-
- <div class="whitespace-nowrap">
- {{ $t("settings.sensitive-data.remove-sensitive-column-tips") }}
- </div>
- </NPopconfirm>
- </div>
- </template>
- </BBGrid>
-
- <template v-else>
- <BBGrid :column-list="COLUMN_LIST" :data-source="[]" class="border" />
- <div class="w-full h-full flex flex-col items-center justify-center">
- <img src="../assets/illustration/no-data.webp" class="max-h-[30vh]" />
+ <div class="mt-5">
+ <BBTabPanel :active="state.selectedIndex === 0">
+ <SensitiveColumnList />
+ </BBTabPanel>
</div>
- </template>
+ </BBTab>
+ <SensitiveColumnList v-else />
</div>
-
- <FeatureModal
- feature="bb.feature.sensitive-data"
- :open="state.showFeatureModal"
- @cancel="state.showFeatureModal = false"
- />
</template>
<script lang="ts" setup>
-import { uniq } from "lodash-es";
-import { NPopconfirm } from "naive-ui";
-import { computed, reactive, watch } from "vue";
+import { computed, reactive, onMounted } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
-import { BBGrid, type BBGridColumn } from "@/bbkit";
-import {
- DatabaseV1Name,
- EnvironmentV1Name,
- InstanceV1Name,
- ProjectV1Name,
-} from "@/components/v2";
-import { featureToRef, useCurrentUserV1, useDatabaseV1Store } from "@/store";
-import {
- usePolicyListByResourceTypeAndPolicyType,
- usePolicyV1Store,
-} from "@/store/modules/v1/policy";
-import { ComposedDatabase } from "@/types";
-import {
- PolicyType,
- Policy,
- PolicyResourceType,
-} from "@/types/proto/v1/org_policy_service";
-import { databaseV1Slug, hasWorkspacePermissionV1 } from "@/utils";
+import type { BBTabItem } from "@/bbkit/types";
+import { SensitiveColumnList } from "@/components/SensitiveData";
+import { featureToRef } from "@/store";
+import { isDev } from "@/utils";
-type SensitiveColumn = {
- database: ComposedDatabase;
- policy: Policy;
- schema: string;
- table: string;
- column: string;
-};
interface LocalState {
- showFeatureModal: boolean;
- isLoading: boolean;
- sensitiveColumnList: SensitiveColumn[];
+ selectedIndex: number;
}
const { t } = useI18n();
-const router = useRouter();
const state = reactive<LocalState>({
- showFeatureModal: false,
- isLoading: false,
- sensitiveColumnList: [],
+ selectedIndex: 0,
});
-const databaseStore = useDatabaseV1Store();
const hasSensitiveDataFeature = featureToRef("bb.feature.sensitive-data");
+const router = useRouter();
-const currentUserV1 = useCurrentUserV1();
-const allowAdmin = computed(() => {
- return hasWorkspacePermissionV1(
- "bb.permission.workspace.manage-sensitive-data",
- currentUserV1.value.userRole
- );
-});
-
-const policyList = usePolicyListByResourceTypeAndPolicyType({
- resourceType: PolicyResourceType.DATABASE,
- policyType: PolicyType.MASKING,
- showDeleted: false,
+const tabItemList = computed((): BBTabItem[] => {
+ return [
+ {
+ title: t("settings.sensitive-data.sensitive-column-list"),
+ id: "sensitive-column-list",
+ },
+ {
+ title: t("settings.sensitive-data.global-masking-rule"),
+ id: "global-masking-rule",
+ },
+ {
+ title: t("settings.sensitive-data.data-feature"),
+ id: "data-feature",
+ },
+ ];
});
-const updateList = async () => {
- state.isLoading = true;
- const distinctDatabaseIdList = uniq(
- policyList.value.map((policy) => policy.resourceUid)
- );
- // Fetch or get all needed databases
- await Promise.all(
- distinctDatabaseIdList.map((databaseId) =>
- databaseStore.getOrFetchDatabaseByUID(databaseId)
- )
- );
-
- const sensitiveColumnList: SensitiveColumn[] = [];
- for (let i = 0; i < policyList.value.length; i++) {
- const policy = policyList.value[i];
- if (!policy.maskingPolicy) {
- continue;
- }
-
- const databaseId = policy.resourceUid;
- const database = await databaseStore.getOrFetchDatabaseByUID(databaseId);
-
- for (const sensitiveData of policy.maskingPolicy.maskData) {
- const { schema, table, column } = sensitiveData;
- sensitiveColumnList.push({ database, policy, schema, table, column });
- }
- }
- state.sensitiveColumnList = sensitiveColumnList;
- state.isLoading = false;
-};
-
-watch(policyList, updateList, { immediate: true });
-
-const removeSensitiveColumn = (sensitiveColumn: SensitiveColumn) => {
- if (!hasSensitiveDataFeature.value) {
- state.showFeatureModal = true;
- return;
- }
-
- const { table, column } = sensitiveColumn;
- const policy = policyList.value.find(
- (policy) => policy.resourceUid == sensitiveColumn.database.uid
- );
- if (!policy) return;
- const maskData = policy.maskingPolicy?.maskData;
- if (!maskData) return;
-
- const index = maskData.findIndex(
- (sensitiveData) =>
- sensitiveData.table === table && sensitiveData.column === column
- );
+onMounted(() => {
+ const hash = router.currentRoute.value.hash.slice(1);
+ const index = tabItemList.value.findIndex((tab) => tab.id === hash);
if (index >= 0) {
- // mutate the list and the item directly
- // so we don't need to re-fetch the whole list.
- maskData.splice(index, 1);
-
- usePolicyV1Store().updatePolicy(["payload"], {
- name: policy.name,
- type: PolicyType.MASKING,
- resourceType: PolicyResourceType.DATABASE,
- maskingPolicy: {
- maskData,
- },
- });
- }
- updateList();
-};
-
-const COLUMN_LIST = computed((): BBGridColumn[] => [
- {
- title: t("database.column"),
- width: "minmax(auto, 1fr)",
- },
- {
- title: t("common.table"),
- width: "minmax(auto, 1fr)",
- },
- {
- title: t("common.database"),
- width: "minmax(auto, 1fr)",
- },
- {
- title: t("common.instance"),
- width: "minmax(auto, 1fr)",
- },
- {
- title: t("common.environment"),
- width: "minmax(auto, 1fr)",
- },
- {
- title: t("common.project"),
- width: "minmax(auto, 1fr)",
- },
- {
- title: t("common.operation"),
- width: "minmax(auto, 6rem)",
- class: "justify-center !px-2",
- },
-]);
-
-const clickRow = (
- item: SensitiveColumn,
- section: number,
- row: number,
- e: MouseEvent
-) => {
- let url = `/db/${databaseV1Slug(item.database)}?table=${item.table}`;
- if (item.schema != "") {
- url += `&schema=${item.schema}`;
- }
- if (e.ctrlKey || e.metaKey) {
- window.open(url, "_blank");
- } else {
- router.push(url);
+ state.selectedIndex = index;
}
-};
+});
</script>