Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: support masking algorithms (#9079)
ecmadaobb1b1f500aae
diff --git a/frontend/src/components/FeatureGuard/FeatureAttentionForInstanceLicense.vue b/frontend/src/components/FeatureGuard/FeatureAttentionForInstanceLicense.vueindex 28e5506793..5cfd3d407e 100644--- a/frontend/src/components/FeatureGuard/FeatureAttentionForInstanceLicense.vue+++ b/frontend/src/components/FeatureGuard/FeatureAttentionForInstanceLicense.vue@@ -1,6 +1,7 @@<template><BBAttentionv-if="+ existInstanceWithoutLicense &&instanceLimitFeature.has(feature) &&subscriptionV1Store.currentPlan !== PlanType.FREE"@@ -26,7 +27,11 @@<script lang="ts" setup>import { reactive, computed } from "vue";import { BBAttentionStyle } from "@/bbkit";-import { useSubscriptionV1Store, useCurrentUserV1 } from "@/store";+import {+ useSubscriptionV1Store,+ useCurrentUserV1,+ useInstanceV1List,+} from "@/store";import { FeatureType, instanceLimitFeature } from "@/types";import { PlanType } from "@/types/proto/v1/subscription_service";import { hasWorkspacePermissionV1 } from "@/utils";@@ -48,6 +53,7 @@ const state = reactive<LocalState>({const subscriptionV1Store = useSubscriptionV1Store();const featureKey = props.feature.split(".").join("-");const currentUserV1 = useCurrentUserV1();+const { instanceList } = useInstanceV1List(false /* !showDeleted */);const onClick = () => {state.showInstanceAssignmentDrawer = true;@@ -59,4 +65,8 @@ const canManageSubscription = computed((): boolean => {currentUserV1.value.userRole);});++const existInstanceWithoutLicense = computed(() => {+ return instanceList.value.some((ins) => !ins.activation);+});</script>diff --git a/frontend/src/components/SensitiveData/MaskingAlgorithmsView.vue b/frontend/src/components/SensitiveData/MaskingAlgorithmsView.vuenew file mode 100644index 0000000000..0d3b33f347--- /dev/null+++ b/frontend/src/components/SensitiveData/MaskingAlgorithmsView.vue@@ -0,0 +1,68 @@+<template>+ <div class="w-full mt-4 space-y-4">+ <div class="flex items-center justify-end">+ <NButton+ type="primary"+ :disabled="!hasPermission || !hasSensitiveDataFeature"+ @click="state.showCreateDrawer = true"+ >+ {{ $t("settings.sensitive-data.algorithms.add") }}+ </NButton>+ </div>+ <div class="space-y-5 divide-y-2 pb-10 divide-gray-100">+ <MaskingAlgorithmsTable+ :readonly="!hasPermission || !hasSensitiveDataFeature"+ :row-clickable="false"+ @on-edit="onEdit"+ />+ </div>+ </div>+ <MaskingAlgorithmsCreateDrawer+ :show="state.showCreateDrawer"+ :algorithm="state.pendingEditData"+ :readonly="!hasPermission || !hasSensitiveDataFeature"+ @dismiss="onDrawerDismiss"+ />+</template>++<script lang="ts" setup>+import { NButton } from "naive-ui";+import { v4 as uuidv4 } from "uuid";+import { computed, reactive } from "vue";+import { featureToRef, useCurrentUserV1 } from "@/store";+import { MaskingAlgorithmSetting_Algorithm } from "@/types/proto/v1/setting_service";+import { hasWorkspacePermissionV1 } from "@/utils";++interface LocalState {+ showCreateDrawer: boolean;+ pendingEditData: MaskingAlgorithmSetting_Algorithm;+}++const state = reactive<LocalState>({+ showCreateDrawer: false,+ pendingEditData: MaskingAlgorithmSetting_Algorithm.fromPartial({+ id: uuidv4(),+ }),+});++const currentUserV1 = useCurrentUserV1();+const hasPermission = computed(() => {+ return hasWorkspacePermissionV1(+ "bb.permission.workspace.manage-sensitive-data",+ currentUserV1.value.userRole+ );+});+const hasSensitiveDataFeature = featureToRef("bb.feature.sensitive-data");++const onDrawerDismiss = () => {+ state.showCreateDrawer = false;+ state.pendingEditData = MaskingAlgorithmSetting_Algorithm.fromPartial({+ id: uuidv4(),+ });+};++const onEdit = (data: MaskingAlgorithmSetting_Algorithm) => {+ state.pendingEditData = data;+ state.showCreateDrawer = true;+};+</script>diff --git a/frontend/src/components/SensitiveData/SemanticTypesView.vue b/frontend/src/components/SensitiveData/SemanticTypesView.vueindex 9a61dfe941..cc85e4c57d 100644--- a/frontend/src/components/SensitiveData/SemanticTypesView.vue+++ b/frontend/src/components/SensitiveData/SemanticTypesView.vue@@ -23,7 +23,6 @@</template><script lang="ts" setup>import { NButton } from "naive-ui";-import type { SelectOption } from "naive-ui";import { v4 as uuidv4 } from "uuid";import { computed, reactive, onMounted } from "vue";import { useI18n } from "vue-i18n";@@ -60,16 +59,6 @@ const hasPermission = computed(() => {});const hasSensitiveDataFeature = featureToRef("bb.feature.sensitive-data");-const algorithmList = computed((): SelectOption[] => {- return (- settingStore.getSettingByName("bb.workspace.masking-algorithm")?.value- ?.maskingAlgorithmSettingValue?.algorithms ?? []- ).map((algorithm) => ({- label: algorithm.title,- value: algorithm.id,- }));-});-onMounted(async () => {const semanticTypeSetting = await settingStore.getOrFetchSettingByName("bb.workspace.semantic-types",@@ -87,15 +76,13 @@ onMounted(async () => {});const onAdd = () => {- const defaultAlgorithm =- algorithmList.value.length > 0 ? algorithmList.value[0].value : "";state.semanticItemList.push({mode: "CREATE",dirty: false,item: SemanticTypeSetting_SemanticType.fromJSON({id: uuidv4(),- fullMaskAlgorithmId: defaultAlgorithm,- partialMaskAlgorithmId: defaultAlgorithm,+ fullMaskAlgorithmId: "",+ partialMaskAlgorithmId: "",}),});};diff --git a/frontend/src/components/SensitiveData/components/MaskingAlgorithmsCreateDrawer.vue b/frontend/src/components/SensitiveData/components/MaskingAlgorithmsCreateDrawer.vuenew file mode 100644index 0000000000..2fbbcc2995--- /dev/null+++ b/frontend/src/components/SensitiveData/components/MaskingAlgorithmsCreateDrawer.vue@@ -0,0 +1,499 @@+<template>+ <Drawer :show="show" @close="$emit('dismiss')">+ <DrawerContent :title="$t('settings.sensitive-data.algorithms.add')">+ <div+ class="w-[40rem] max-w-[calc(100vw-5rem)] space-y-6 divide-y divide-block-border"+ >+ <div class="space-y-6">+ <div class="sm:col-span-2 sm:col-start-1">+ <label for="title" class="textlabel">+ {{ $t("settings.sensitive-data.algorithms.table.title") }}+ <span class="text-red-600 mr-2">*</span>+ </label>+ <input+ v-model="state.title"+ required+ name="title"+ type="text"+ placeholder="algorithm title"+ class="textfield mt-1 w-full"+ :disabled="state.processing || readonly"+ />+ </div>+ <div class="sm:col-span-2 sm:col-start-1">+ <label for="description" class="textlabel">+ {{ $t("settings.sensitive-data.algorithms.table.description") }}+ </label>+ <input+ v-model="state.description"+ required+ name="title"+ type="text"+ placeholder="algorithm description"+ class="textfield mt-1 w-full"+ :disabled="state.processing || readonly"+ />+ </div>+ <div class="w-full mb-6 space-y-1">+ <label for="masking-type" class="textlabel">+ {{ $t("settings.sensitive-data.algorithms.table.masking-type") }}+ <span class="text-red-600 mr-2">*</span>+ </label>+ <div class="grid grid-cols-3 gap-2">+ <template v-for="(item, i) in maskingTypeList" :key="i">+ <div+ class="flex relative justify-start p-2 border rounded"+ :class="[+ state.maskingType === item.id &&+ 'font-medium bg-control-bg-hover',+ readonly+ ? 'cursor-not-allowed'+ : 'cursor-pointer hover:bg-control-bg-hover',+ ]"+ @click.capture="onMaskingTypeChange(item.id)"+ >+ <div class="flex flex-row justify-start items-center">+ <input+ type="radio"+ class="btn mr-2"+ :checked="state.maskingType === item.id"+ :disabled="state.processing || readonly"+ />+ <p class="text-center text-sm">+ {{ item.title }}+ </p>+ </div>+ </div>+ </template>+ </div>+ </div>+ </div>+ <div class="space-y-6 pt-6">+ <template v-if="state.maskingType === 'full-mask'">+ <div class="sm:col-span-2 sm:col-start-1">+ <label for="substitution" class="textlabel">+ {{+ $t(+ "settings.sensitive-data.algorithms.full-mask.substitution"+ )+ }}+ <span class="text-red-600 mr-2">*</span>+ </label>+ <p class="textinfolabel">+ {{+ $t(+ "settings.sensitive-data.algorithms.full-mask.substitution-label"+ )+ }}+ </p>+ <input+ v-model="state.fullMask.substitution"+ required+ name="title"+ type="text"+ placeholder="substitution"+ class="textfield mt-2 w-full"+ :disabled="state.processing || readonly"+ />+ </div>+ </template>+ <template v-if="state.maskingType === 'range-mask'">+ <div+ v-for="(slice, i) in state.rangeMask.slices"+ :key="i"+ class="flex space-x-2 items-center"+ >+ <div class="flex-none flex flex-col">+ <label for="slice-start" class="textlabel">+ {{+ $t(+ "settings.sensitive-data.algorithms.range-mask.slice-start"+ )+ }}+ <span class="text-red-600 mr-2">*</span>+ </label>+ <input+ :value="slice.start"+ required+ name="slice-start"+ type="number"+ min="0"+ placeholder="slice start"+ class="textfield mt-1 w-20"+ :disabled="state.processing || readonly"+ @input="(e: any) => onSliceStartChange(i, Number(e.target.value))"+ />+ </div>+ <div class="flex-none flex flex-col">+ <label for="slice-end" class="textlabel">+ {{+ $t(+ "settings.sensitive-data.algorithms.range-mask.slice-end"+ )+ }}+ <span class="text-red-600 mr-2">*</span>+ </label>+ <input+ :value="slice.end"+ required+ name="slice-end"+ type="number"+ min="1"+ placeholder="slice end"+ class="textfield mt-1 w-20"+ :disabled="state.processing || readonly"+ @input="(e: any) => onSliceEndChange(i, Number(e.target.value))"+ />+ </div>+ <div class="flex-1 flex flex-col">+ <label for="substitution" class="textlabel">+ {{+ $t(+ "settings.sensitive-data.algorithms.range-mask.substitution"+ )+ }}+ <span class="text-red-600 mr-2">*</span>+ </label>+ <input+ v-model="slice.substitution"+ required+ name="substitution"+ type="text"+ placeholder="substitution"+ class="textfield mt-1 w-full"+ :disabled="state.processing || readonly"+ />+ </div>+ <div class="mt-5">+ <button+ class="p-1 hover:bg-gray-300 rounded cursor-pointer disabled:cursor-not-allowed disabled:hover:bg-white disabled:text-gray-400"+ :disabled="state.processing || readonly"+ @click.stop="removeSlice(i)"+ >+ <heroicons-outline:trash class="w-4 h-4" />+ </button>+ </div>+ </div>+ <NButton+ class="ml-auto"+ :disabled="state.processing || readonly"+ @click.prevent="addSlice"+ >+ {{ $t("common.add") }}+ </NButton>+ </template>+ <template v-if="state.maskingType === 'md5-mask'">+ <div class="sm:col-span-2 sm:col-start-1">+ <label for="salt" class="textlabel">+ {{ $t("settings.sensitive-data.algorithms.md5-mask.salt") }}+ <span class="text-red-600 mr-2">*</span>+ </label>+ <p class="textinfolabel">+ {{+ $t("settings.sensitive-data.algorithms.md5-mask.salt-label")+ }}+ </p>+ <input+ v-model="state.md5Mask.salt"+ required+ name="title"+ type="text"+ placeholder="salt"+ class="textfield mt-2 w-full"+ :disabled="state.processing || readonly"+ />+ </div>+ </template>+ </div>+ </div>+ <template #footer>+ <div class="w-full flex justify-between items-center">+ <div class="w-full flex justify-end items-center gap-x-3">+ <NButton @click.prevent="$emit('dismiss')">+ {{ $t("common.cancel") }}+ </NButton>+ <NTooltip :disabled="!errorMessage">+ <template #trigger>+ <NButton+ v-if="!readonly"+ :disabled="isSubmitDisabled"+ type="primary"+ @click.prevent="onUpsert"+ >+ {{ $t("common.confirm") }}+ </NButton>+ </template>+ {{ errorMessage }}+ </NTooltip>+ </div>+ </div>+ </template>+ </DrawerContent>+ </Drawer>+</template>+<script setup lang="ts">+import { cloneDeep } from "lodash-es";+import { computed, watch, reactive } from "vue";+import { useI18n } from "vue-i18n";+import { Drawer, DrawerContent } from "@/components/v2";+import { pushNotification, useSettingV1Store } from "@/store";+import {+ MaskingAlgorithmSetting_Algorithm,+ MaskingAlgorithmSetting_Algorithm_FullMask,+ MaskingAlgorithmSetting_Algorithm_RangeMask,+ MaskingAlgorithmSetting_Algorithm_MD5Mask,+ MaskingAlgorithmSetting_Algorithm_RangeMask_Slice,+} from "@/types/proto/v1/setting_service";+import { MaskingType, getMaskingType } from "./utils";++interface MaskingTypeItem {+ id: MaskingType;+ title: string;+}++interface LocalState {+ processing: boolean;+ maskingType: MaskingType;+ title: string;+ description: string;+ fullMask: MaskingAlgorithmSetting_Algorithm_FullMask;+ rangeMask: MaskingAlgorithmSetting_Algorithm_RangeMask;+ md5Mask: MaskingAlgorithmSetting_Algorithm_MD5Mask;+}++const props = defineProps<{+ show: boolean;+ readonly: boolean;+ algorithm: MaskingAlgorithmSetting_Algorithm;+}>();++const emit = defineEmits<{+ (event: "dismiss"): void;+}>();++const defaultRangeMask = computed(() =>+ MaskingAlgorithmSetting_Algorithm_RangeMask.fromPartial({+ slices: [+ MaskingAlgorithmSetting_Algorithm_RangeMask_Slice.fromPartial({+ start: 0,+ end: 1,+ }),+ ],+ })+);++const state = reactive<LocalState>({+ processing: false,+ maskingType: "full-mask",+ title: "",+ description: "",+ fullMask: MaskingAlgorithmSetting_Algorithm_FullMask.fromPartial({}),+ rangeMask: cloneDeep(defaultRangeMask.value),+ md5Mask: MaskingAlgorithmSetting_Algorithm_MD5Mask.fromPartial({}),+});+const { t } = useI18n();+const settingStore = useSettingV1Store();++const maskingTypeList = computed((): MaskingTypeItem[] => [+ {+ id: "full-mask",+ title: t("settings.sensitive-data.algorithms.full-mask.self"),+ },+ {+ id: "range-mask",+ title: t("settings.sensitive-data.algorithms.range-mask.self"),+ },+ {+ id: "md5-mask",+ title: t("settings.sensitive-data.algorithms.md5-mask.self"),+ },+]);++const algorithmList = computed((): MaskingAlgorithmSetting_Algorithm[] => {+ return (+ settingStore.getSettingByName("bb.workspace.masking-algorithm")?.value+ ?.maskingAlgorithmSettingValue?.algorithms ?? []+ );+});++watch(+ () => props.algorithm,+ (algorithm) => {+ state.title = algorithm.title;+ state.description = algorithm.description;+ state.maskingType = getMaskingType(algorithm) ?? "full-mask";+ state.fullMask =+ algorithm.fullMask ??+ MaskingAlgorithmSetting_Algorithm_FullMask.fromPartial({});+ state.rangeMask = algorithm.rangeMask ?? cloneDeep(defaultRangeMask.value);+ state.md5Mask =+ algorithm.md5Mask ??+ MaskingAlgorithmSetting_Algorithm_MD5Mask.fromPartial({});+ }+);++const maskingAlgorithm = computed((): MaskingAlgorithmSetting_Algorithm => {+ const result = MaskingAlgorithmSetting_Algorithm.fromPartial({+ id: props.algorithm.id,+ title: state.title,+ description: state.description,+ category: state.maskingType === "md5-mask" ? "HASH" : "MASK",+ });++ switch (state.maskingType) {+ case "full-mask":+ result.fullMask = state.fullMask;+ break;+ case "range-mask":+ result.rangeMask = state.rangeMask;+ break;+ case "md5-mask":+ result.md5Mask = state.md5Mask;+ break;+ }++ return result;+});++const errorMessage = computed(() => {+ if (!state.title) {+ return "Title is required";+ }++ switch (state.maskingType) {+ case "full-mask":+ if (!state.fullMask.substitution) {+ return "Substitution is required";+ }+ return "";+ case "md5-mask":+ if (!state.md5Mask.salt) {+ return "Salt is required";+ }+ return "";+ case "range-mask":+ if (state.rangeMask.slices.length === 0) {+ return "Slices is required";+ }+ for (const slice of state.rangeMask.slices) {+ if (!slice.substitution) {+ return "Slice substitution is required";+ }+ if (+ Number.isNaN(slice.start) ||+ Number.isNaN(slice.end) ||+ slice.start < 0 ||+ slice.end <= 0+ ) {+ return "Slice start or end is not valid number";+ }+ if (slice.start >= slice.end) {+ return "The slice end must smaller than the start";+ }+ }+ }+ return "";+});++const isSubmitDisabled = computed(() => {+ if (props.readonly || state.processing) {+ return true;+ }++ if (!state.title) {+ return true;+ }++ return !!errorMessage.value;+});++const onUpsert = async () => {+ state.processing = true;++ const index = algorithmList.value.findIndex(+ (item) => item.id === props.algorithm.id+ );+ const newList = [...algorithmList.value];+ if (index < 0) {+ newList.push(maskingAlgorithm.value);+ } else {+ newList[index] = maskingAlgorithm.value;+ }++ try {+ await settingStore.upsertSetting({+ name: "bb.workspace.masking-algorithm",+ value: {+ maskingAlgorithmSettingValue: {+ algorithms: newList,+ },+ },+ });++ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: t("common.updated"),+ });++ emit("dismiss");+ } finally {+ state.processing = false;+ }+};++const onMaskingTypeChange = (maskingType: MaskingType) => {+ if (state.processing || props.readonly) {+ return;+ }+ switch (maskingType) {+ case "full-mask":+ state.fullMask = MaskingAlgorithmSetting_Algorithm_FullMask.fromPartial(+ {}+ );+ break;+ case "range-mask":+ state.rangeMask = cloneDeep(defaultRangeMask.value);+ break;+ case "md5-mask":+ state.md5Mask = MaskingAlgorithmSetting_Algorithm_MD5Mask.fromPartial({});+ break;+ }+ state.maskingType = maskingType;+};++const addSlice = () => {+ state.rangeMask.slices.push(+ MaskingAlgorithmSetting_Algorithm_RangeMask_Slice.fromPartial({+ start: 0,+ end: 1,+ })+ );+};++const removeSlice = (i: number) => {+ state.rangeMask.slices.splice(i, 1);+};++const onSliceStartChange = (index: number, val: number) => {+ if (Number.isNaN(val)) {+ return;+ }+ const slice = state.rangeMask.slices[index];+ slice.start = Math.max(0, val);+ if (slice.end <= slice.start) {+ slice.end = slice.start + 1;+ }+};++const onSliceEndChange = (index: number, val: number) => {+ if (Number.isNaN(val)) {+ return;+ }+ const slice = state.rangeMask.slices[index];+ slice.end = Math.max(1, val);+ if (slice.start >= slice.end) {+ slice.start = slice.end - 1;+ }+};+</script>diff --git a/frontend/src/components/SensitiveData/components/MaskingAlgorithmsTable.vue b/frontend/src/components/SensitiveData/components/MaskingAlgorithmsTable.vuenew file mode 100644index 0000000000..cf4bdc10f6--- /dev/null+++ b/frontend/src/components/SensitiveData/components/MaskingAlgorithmsTable.vue@@ -0,0 +1,167 @@+<template>+ <BBTable+ ref="tableRef"+ :column-list="tableHeaderList"+ :data-source="algorithmList"+ :show-header="true"+ :custom-header="true"+ :left-bordered="true"+ :right-bordered="true"+ :top-bordered="true"+ :bottom-bordered="true"+ :compact-section="true"+ :row-clickable="rowClickable"+ @click-row="(section: number, index: number, _) => $emit('on-select', algorithmList[index].id)"+ >+ <template #header>+ <BBTableHeaderCell+ v-for="header in tableHeaderList"+ :key="header.title"+ :title="header.title"+ />+ </template>+ <template+ #body="{+ rowData,+ row,+ }: {+ rowData: MaskingAlgorithmSetting_Algorithm,+ row: number,+ }"+ >+ <BBTableCell class="bb-grid-cell">+ <h3>+ {{ rowData.title }}+ </h3>+ </BBTableCell>+ <BBTableCell class="bb-grid-cell">+ <h3>+ {{ rowData.description }}+ </h3>+ </BBTableCell>+ <BBTableCell class="bb-grid-cell">+ <h3>+ {{ getAlgorithmMaskingType(rowData) }}+ </h3>+ </BBTableCell>+ <BBTableCell class="bb-grid-cell w-6">+ <div class="flex justify-end items-center space-x-2">+ <button+ class="p-1 hover:bg-gray-300 rounded cursor-pointer disabled:cursor-not-allowed disabled:hover:bg-white disabled:text-gray-400"+ @click.stop="$emit('on-edit', rowData)"+ >+ <heroicons-outline:pencil class="w-4 h-4" />+ </button>++ <NPopconfirm v-if="!readonly" @positive-click="onRemove(row)">+ <template #trigger>+ <button+ class="p-1 hover:bg-gray-300 rounded cursor-pointer disabled:cursor-not-allowed disabled:hover:bg-white disabled:text-gray-400"+ @click.stop=""+ >+ <heroicons-outline:trash class="w-4 h-4" />+ </button>+ </template>++ <div class="whitespace-nowrap">+ {{ $t("settings.sensitive-data.algorithms.table.delete") }}+ </div>+ </NPopconfirm>+ </div>+ </BBTableCell>+ </template>+ </BBTable>+</template>++<script lang="ts" setup>+import { NPopconfirm } from "naive-ui";+import { computed, onMounted } from "vue";+import { useI18n } from "vue-i18n";+import type { BBTableColumn } from "@/bbkit/types";+import { useSettingV1Store, pushNotification } from "@/store";+import { MaskingAlgorithmSetting_Algorithm } from "@/types/proto/v1/setting_service";+import { getMaskingType } from "./utils";++defineProps<{+ readonly: boolean;+ rowClickable: boolean;+}>();++defineEmits<{+ (event: "on-select", id: string): void;+ (event: "on-edit", item: MaskingAlgorithmSetting_Algorithm): void;+}>();++const { t } = useI18n();+const settingStore = useSettingV1Store();++onMounted(async () => {+ await settingStore.getOrFetchSettingByName(+ "bb.workspace.masking-algorithm",+ true+ );+});++const tableHeaderList = computed(() => {+ const list: BBTableColumn[] = [+ {+ title: t("settings.sensitive-data.algorithms.table.title"),+ },+ {+ title: t("settings.sensitive-data.algorithms.table.description"),+ },+ {+ title: t("settings.sensitive-data.algorithms.table.masking-type"),+ },+ {+ // operations+ title: "",+ },+ ];+ return list;+});++const algorithmList = computed((): MaskingAlgorithmSetting_Algorithm[] => {+ return (+ settingStore.getSettingByName("bb.workspace.masking-algorithm")?.value+ ?.maskingAlgorithmSettingValue?.algorithms ?? []+ );+});++const getAlgorithmMaskingType = (+ algorithm: MaskingAlgorithmSetting_Algorithm+) => {+ const maskingType = getMaskingType(algorithm);+ if (maskingType) {+ return t(`settings.sensitive-data.algorithms.${maskingType}.self`);+ }++ return algorithm.category;+};++const onRemove = async (index: number) => {+ const item = algorithmList.value[index];+ if (!item) {+ return;+ }+ const newList = [+ ...algorithmList.value.slice(0, index),+ ...algorithmList.value.slice(index + 1),+ ];++ await settingStore.upsertSetting({+ name: "bb.workspace.masking-algorithm",+ value: {+ maskingAlgorithmSettingValue: {+ algorithms: newList,+ },+ },+ });++ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: t("common.deleted"),+ });+};+</script>diff --git a/frontend/src/components/SensitiveData/components/SemanticTypesDrawer.vue b/frontend/src/components/SensitiveData/components/SemanticTypesDrawer.vueindex 83e5ea9f5a..9141c3e4c9 100644--- a/frontend/src/components/SensitiveData/components/SemanticTypesDrawer.vue+++ b/frontend/src/components/SensitiveData/components/SemanticTypesDrawer.vue@@ -9,16 +9,16 @@@on-select="onApply($event)"/></div>- </DrawerContent>- <template #footer>- <div class="w-full flex justify-between items-center">- <div class="w-full flex justify-end items-center gap-x-3">- <NButton @click.prevent="$emit('dismiss')">- {{ $t("common.cancel") }}- </NButton>+ <template #footer>+ <div class="w-full flex justify-between items-center">+ <div class="w-full flex justify-end items-center gap-x-3">+ <NButton @click.prevent="$emit('dismiss')">+ {{ $t("common.cancel") }}+ </NButton>+ </div></div>- </div>- </template>+ </template>+ </DrawerContent></Drawer></template>diff --git a/frontend/src/components/SensitiveData/components/SemanticTypesTable.vue b/frontend/src/components/SensitiveData/components/SemanticTypesTable.vueindex 151297b954..e2df17bfa6 100644--- a/frontend/src/components/SensitiveData/components/SemanticTypesTable.vue+++ b/frontend/src/components/SensitiveData/components/SemanticTypesTable.vue@@ -53,29 +53,39 @@</BBTableCell><BBTableCell class="bb-grid-cell"><h3 v-if="rowData.mode === 'NORMAL'">- {{ getAlgorithmById(rowData.item.fullMaskAlgorithmId)?.label }}+ {{+ getAlgorithmById(rowData.item.fullMaskAlgorithmId)?.label ??+ $t("settings.sensitive-data.algorithms.default")+ }}</h3><NSelectv-else:value="rowData.item.fullMaskAlgorithmId"+ clearable:options="algorithmList":consistent-menu-width="false":placeholder="$t('custom-approval.risk-rule.condition.select-value')"size="small"+ :fallback-option="(_: string) => ({ label: $t('settings.sensitive-data.algorithms.default'), value: '' })"style="min-width: 7rem; width: auto; overflow-x: hidden"@update:value="(val: string) => onInput(row, (data) => data.item.fullMaskAlgorithmId = val)"/></BBTableCell><BBTableCell class="bb-grid-cell"><h3 v-if="rowData.mode === 'NORMAL'">- {{ getAlgorithmById(rowData.item.partialMaskAlgorithmId)?.label }}+ {{+ getAlgorithmById(rowData.item.partialMaskAlgorithmId)?.label ??+ $t("settings.sensitive-data.algorithms.default")+ }}</h3><NSelectv-else:value="rowData.item.partialMaskAlgorithmId"+ clearable:options="algorithmList":consistent-menu-width="false":placeholder="$t('custom-approval.risk-rule.condition.select-value')"+ :fallback-option="(_: string) => ({ label: $t('settings.sensitive-data.algorithms.default'), value: '' })"size="small"style="min-width: 7rem; width: auto; overflow-x: hidden"@update:value="(val: string) => onInput(row, (data) => data.item.partialMaskAlgorithmId = val)"@@ -216,11 +226,7 @@ const getAlgorithmById = (algorithmId: string) => {};const isConfirmDisabled = (data: SemanticItem): boolean => {- if (- !data.item.title ||- !data.item.fullMaskAlgorithmId ||- !data.item.partialMaskAlgorithmId- ) {+ if (!data.item.title) {return true;}if (data.mode === "EDIT" && !data.dirty) {diff --git a/frontend/src/components/SensitiveData/components/utils.ts b/frontend/src/components/SensitiveData/components/utils.tsindex 6ac2d3cab6..577fc251cf 100644--- a/frontend/src/components/SensitiveData/components/utils.ts+++ b/frontend/src/components/SensitiveData/components/utils.ts@@ -13,6 +13,7 @@ import {useSettingV1Store,} from "@/store";import { DEFAULT_PROJECT_V1_NAME } from "@/types";+import { MaskingAlgorithmSetting_Algorithm } from "@/types/proto/v1/setting_service";import {extractEnvironmentResourceName,extractInstanceResourceName,@@ -83,3 +84,24 @@ export const factorSupportDropdown: Factor[] = [export const factorOperatorOverrideMap = new Map<Factor, Operator[]>([["project_id", uniq([...EqualityOperatorList, ...CollectionOperatorList])],]);++export type MaskingType = "full-mask" | "range-mask" | "md5-mask";++export const getMaskingType = (+ algorithm: MaskingAlgorithmSetting_Algorithm+): MaskingType | undefined => {+ switch (algorithm.category) {+ case "HASH":+ return "md5-mask";+ case "MASK":+ if (algorithm.fullMask) {+ return "full-mask";+ } else if (algorithm.rangeMask) {+ return "range-mask";+ }+ break;+ default:+ return;+ }+ return;+};diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex e21edbce36..30f54ef230 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -647,7 +647,7 @@"sensitive-data": {"description": "Following columns are explicitly assigned masking levels and take predence over the global masking rule.","remove-sensitive-column-tips": "Expose this column?",- "sensitive-column-list": "Explict masked column list",+ "sensitive-column-list": "Explict Masked Column List","global-masking-rule": "Global Masking Rule","grant-access": "Grant Access","never-expires": "Never expires",@@ -681,8 +681,34 @@},"algorithms": {"self": "Masking Algorithm",+ "add": "Add algorithm","default": "Default",- "default-desc": "Use *** as data mask"+ "default-desc": "Use *** as data mask",+ "table": {+ "title": "Title",+ "description": "Description",+ "masking-type": "Masking type",+ "delete": "Delete this algorithm?"+ },+ "full-mask": {+ "self": "Full mask",+ "substitution": "Substitution",+ "substitution-label": "Substitution is the string used to replace the original value, the max length of the string is 16 bytes."+ },+ "range-mask": {+ "self": "Range mask",+ "slice-start": "Slice start",+ "slice-start-label": "Slice start is the start index of the original value, start from 0 and should be less than stop.",+ "slice-end": "Slice end",+ "slice-end-label": "Slice stop is the stop index of the original value, should be less than the length of the original value.",+ "substitution": "Substitution",+ "substitution-label": "Substitution is the string used to replace the original value from start to end."+ },+ "md5-mask": {+ "self": "MD5 mask",+ "salt": "Salt",+ "salt-label": "Salt is the salt value to generate a different hash that with the word alone."+ }},"masking-level": {"self": "Masking Level",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 4ec0f1eef0..7bf25e4669 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -680,8 +680,34 @@},"algorithms": {"self": "Algoritmo de enmascaramiento",+ "add": "Agregar algoritmo","default": "Por defecto",- "default-desc": "Utilice *** como máscara de datos"+ "default-desc": "Utilice *** como máscara de datos",+ "table": {+ "title": "Título",+ "description": "Descripción",+ "masking-type": "Tipo de enmascaramiento",+ "delete": "¿Eliminar este algoritmo?"+ },+ "full-mask": {+ "self": "Máscara completa",+ "substitution": "Sustitución",+ "substitution-label": "La sustitución es la cadena utilizada para reemplazar el valor original, la longitud máxima de la cadena es 16 bytes."+ },+ "range-mask": {+ "self": "Máscara de rango",+ "slice-start": "Inicio de corte",+ "slice-start-label": "El inicio del segmento es el índice de inicio del valor original, comienza desde 0 y debe ser menor que detener.",+ "slice-end": "Fin del corte",+ "slice-end-label": "La parada de segmento es el índice de parada del valor original y debe ser menor que la longitud del valor original.",+ "substitution": "Sustitución",+ "substitution-label": "La sustitución es la cadena utilizada para reemplazar el valor original de principio a fin."+ },+ "md5-mask": {+ "self": "Máscara MD5",+ "salt": "Sal",+ "salt-label": "La sal es el valor de la sal para generar un hash diferente al de la palabra sola."+ }},"masking-level": {"self": "Nivel de enmascaramiento",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex a8acbd0aab..98abf896bc 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -679,8 +679,34 @@},"algorithms": {"self": "脱敏算法",+ "add": "添加算法","default": "默认",- "default-desc": "使用 *** 为数据遮挡"+ "default-desc": "使用 *** 为数据遮挡",+ "table": {+ "title": "名称",+ "description": "描述",+ "masking-type": "算法类型",+ "delete": "删除该算法?"+ },+ "full-mask": {+ "self": "全遮掩",+ "substitution": "遮掩字符串",+ "substitution-label": "遮掩字符串是用来替换原始值的字符串,最大长度不能超过16字节。"+ },+ "range-mask": {+ "self": "范围遮掩",+ "slice-start": "起始位置",+ "slice-start-label": "起始位置是原始值的起始索引,从 0 开始且小于结束位置。",+ "slice-end": "结束位置",+ "slice-end-label": "结束位置是原始值的停止索引,应小于原始值的长度。",+ "substitution": "遮掩字符串",+ "substitution-label": "遮掩字符串是用来替换从起始位置到结束位置的字符串。"+ },+ "md5-mask": {+ "self": "MD5 哈希",+ "salt": "盐值",+ "salt-label": "盐值用于计算生成哈希值。"+ }},"masking-level": {"self": "脱敏程度",diff --git a/frontend/src/types/proto/v1/setting_service.ts b/frontend/src/types/proto/v1/setting_service.tsindex 4090f8a940..dcd9814bc8 100644--- a/frontend/src/types/proto/v1/setting_service.ts+++ b/frontend/src/types/proto/v1/setting_service.ts@@ -483,10 +483,10 @@ export interface MaskingAlgorithmSetting_Algorithm {/** description is the description for masking algorithm. */description: string;/**- * Category is the category for masking algorithm. Currently, it accepts 2 categories only: MASKING and HASHING.+ * Category is the category for masking algorithm. Currently, it accepts 2 categories only: MASK and HASH.* The range of accepted Payload is decided by the category.- * Mask: FullMask, RangeMask- * Hash: MD5Mask+ * MASK: FullMask, RangeMask+ * HASH: MD5Mask*/category: string;fullMask?: MaskingAlgorithmSetting_Algorithm_FullMask | undefined;@@ -515,7 +515,7 @@ export interface MaskingAlgorithmSetting_Algorithm_RangeMask_Slice {start: number;/** stop is the stop index of the original value, should be less than the length of the original value. */end: number;- /** OriginalValue[start:end) would be replaced with replace_with. */+ /** substitution is the string used to replace the OriginalValue[start:end). */substitution: string;}diff --git a/frontend/src/views/SettingWorkspaceSensitiveData.vue b/frontend/src/views/SettingWorkspaceSensitiveData.vueindex d83bf172d4..75542970aa 100644--- a/frontend/src/views/SettingWorkspaceSensitiveData.vue+++ b/frontend/src/views/SettingWorkspaceSensitiveData.vue@@ -25,6 +25,13 @@><SemanticTypesView /></NTabPane>+ <NTabPane+ v-if="isDev()"+ name="masking-algorithms"+ :tab="$t('settings.sensitive-data.algorithms.self')"+ >+ <MaskingAlgorithmsView />+ </NTabPane></NTabs></div></template>@@ -41,11 +48,18 @@ import {import { featureToRef } from "@/store";import { isDev } from "@/utils";+const dataMaskingTabList = [+ "sensitive-column-list",+ "global-masking-rule",+ "semantic-types",+ "masking-algorithms",+] as const;+type DataMaskingTab = typeof dataMaskingTabList[number];+const isDataMaskingTab = (tab: any): tab is DataMaskingTab =>+ dataMaskingTabList.includes(tab);+interface LocalState {- selectedTab:- | "sensitive-column-list"- | "global-masking-rule"- | "semantic-types";+ selectedTab: DataMaskingTab;}const state = reactive<LocalState>({@@ -58,16 +72,11 @@ const route = useRoute();watch(() => route.hash,(hash) => {- switch (hash) {- case "#semantic-types":- state.selectedTab = "semantic-types";- break;- case "#global-masking-rule":- state.selectedTab = "global-masking-rule";- break;- default:- state.selectedTab = "sensitive-column-list";- break;+ const tab = hash.slice(1);+ if (isDataMaskingTab(tab)) {+ state.selectedTab = tab;+ } else {+ state.selectedTab = "sensitive-column-list";}},{@@ -78,17 +87,7 @@ watch(watch(() => state.selectedTab,(tab) => {- switch (tab) {- case "global-masking-rule":- router.push({ hash: "#global-masking-rule" });- break;- case "semantic-types":- router.push({ hash: "#semantic-types" });- break;- default:- router.push({ hash: "" });- break;- }+ router.push({ hash: `#${tab}` });});</script>diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.mdindex a149548c0a..793d0f77ab 100644--- a/proto/gen/grpc-doc/v1/README.md+++ b/proto/gen/grpc-doc/v1/README.md@@ -9096,7 +9096,7 @@ When paginating, all other parameters provided to `ListSettings` must match the| id | [string](#string) | | id is the uuid for masking algorithm. || title | [string](#string) | | title is the title for masking algorithm. || description | [string](#string) | | description is the description for masking algorithm. |-| category | [string](#string) | | Category is the category for masking algorithm. Currently, it accepts 2 categories only: MASKING and HASHING. The range of accepted Payload is decided by the category. Mask: FullMask, RangeMask Hash: MD5Mask |+| category | [string](#string) | | Category is the category for masking algorithm. Currently, it accepts 2 categories only: MASK and HASH. The range of accepted Payload is decided by the category. MASK: FullMask, RangeMask HASH: MD5Mask || full_mask | [MaskingAlgorithmSetting.Algorithm.FullMask](#bytebase-v1-MaskingAlgorithmSetting-Algorithm-FullMask) | | || range_mask | [MaskingAlgorithmSetting.Algorithm.RangeMask](#bytebase-v1-MaskingAlgorithmSetting-Algorithm-RangeMask) | | || md5_mask | [MaskingAlgorithmSetting.Algorithm.MD5Mask](#bytebase-v1-MaskingAlgorithmSetting-Algorithm-MD5Mask) | | |@@ -9161,7 +9161,7 @@ When paginating, all other parameters provided to `ListSettings` must match the| ----- | ---- | ----- | ----------- || start | [int32](#int32) | | start is the start index of the original value, start from 0 and should be less than stop. || end | [int32](#int32) | | stop is the stop index of the original value, should be less than the length of the original value. |-| substitution | [string](#string) | | OriginalValue[start:end) would be replaced with replace_with. |+| substitution | [string](#string) | | substitution is the string used to replace the OriginalValue[start:end). |diff --git a/proto/generated-go/v1/setting_service.pb.go b/proto/generated-go/v1/setting_service.pb.goindex ec16329af7..17ba08ea28 100644--- a/proto/generated-go/v1/setting_service.pb.go+++ b/proto/generated-go/v1/setting_service.pb.go@@ -2321,10 +2321,10 @@ type MaskingAlgorithmSetting_Algorithm struct {Title string `protobuf:"bytes,2,opt,name=title,proto3" json:"title,omitempty"`// description is the description for masking algorithm.Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"`- // Category is the category for masking algorithm. Currently, it accepts 2 categories only: MASKING and HASHING.+ // Category is the category for masking algorithm. Currently, it accepts 2 categories only: MASK and HASH.// The range of accepted Payload is decided by the category.- // Mask: FullMask, RangeMask- // Hash: MD5Mask+ // MASK: FullMask, RangeMask+ // HASH: MD5MaskCategory string `protobuf:"bytes,4,opt,name=category,proto3" json:"category,omitempty"`// Types that are assignable to Mask://@@ -2599,7 +2599,7 @@ type MaskingAlgorithmSetting_Algorithm_RangeMask_Slice struct {Start int32 `protobuf:"varint,1,opt,name=start,proto3" json:"start,omitempty"`// stop is the stop index of the original value, should be less than the length of the original value.End int32 `protobuf:"varint,2,opt,name=end,proto3" json:"end,omitempty"`- // OriginalValue[start:end) would be replaced with replace_with.+ // substitution is the string used to replace the OriginalValue[start:end).Substitution string `protobuf:"bytes,3,opt,name=substitution,proto3" json:"substitution,omitempty"`}diff --git a/proto/v1/setting_service.proto b/proto/v1/setting_service.protoindex d1d1790422..c4b8119b40 100644--- a/proto/v1/setting_service.proto+++ b/proto/v1/setting_service.proto@@ -359,10 +359,10 @@ message MaskingAlgorithmSetting {// description is the description for masking algorithm.string description = 3;- // Category is the category for masking algorithm. Currently, it accepts 2 categories only: MASKING and HASHING.+ // Category is the category for masking algorithm. Currently, it accepts 2 categories only: MASK and HASH.// The range of accepted Payload is decided by the category.- // Mask: FullMask, RangeMask- // Hash: MD5Mask+ // MASK: FullMask, RangeMask+ // HASH: MD5Maskstring category = 4;message FullMask {@@ -377,7 +377,7 @@ message MaskingAlgorithmSetting {int32 start = 1;// stop is the stop index of the original value, should be less than the length of the original value.int32 end = 2;- // OriginalValue[start:end) would be replaced with replace_with.+ // substitution is the string used to replace the OriginalValue[start:end).string substitution = 3;}// We store it as a repeated field to face the fact that the original value may have multiple parts should be masked.