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: update global masking rules (#8170)
ecmadaoda89d0f341ed
diff --git a/frontend/src/components/ExprEditor/components/ValueInput.vue b/frontend/src/components/ExprEditor/components/ValueInput.vueindex 21bad28856..6ace57e00c 100644--- a/frontend/src/components/ExprEditor/components/ValueInput.vue+++ b/frontend/src/components/ExprEditor/components/ValueInput.vue@@ -138,13 +138,13 @@ const setArrayValue = (values: string[] | number[]) => {// clean up value type when factor and operator changedwatch(- [operator, () => props.expr.args[1]],- ([operator, value]) => {+ [factor, operator, () => props.expr.args[1]],+ ([factor, operator, value]) => {if (isEqualityOperator(operator)) {- if (isNumberFactor(factor.value) && !isNumber(value)) {+ if (isNumberFactor(factor) && !isNumber(value)) {setNumberValue(0);}- if (isStringFactor(factor.value) && typeof value !== "string") {+ if (isStringFactor(factor) && typeof value !== "string") {setStringValue("");}}@@ -162,16 +162,4 @@ watch(immediate: true,});-watch(- factor,- (factor) => {- if (isNumberFactor(factor)) {- setNumberValue(0);- }- if (isStringFactor(factor)) {- setStringValue("");- }- },- { immediate: true }-);</script>diff --git a/frontend/src/components/SensitiveData/GlobalMaskingRulesView.vue b/frontend/src/components/SensitiveData/GlobalMaskingRulesView.vueindex 4c85331319..2dd5885585 100644--- a/frontend/src/components/SensitiveData/GlobalMaskingRulesView.vue+++ b/frontend/src/components/SensitiveData/GlobalMaskingRulesView.vue@@ -57,51 +57,46 @@:key="item.rule.id"class="flex items-start space-x-5">- <div v-if="state.reorderRules" class="mt-4 flex flex-col">- <button @click="onReorder(item, -1)">- <heroicons-solid:arrow-circle-up- v-if="index !== 0"- class="w-6 h-6"- />- </button>- <button @click="onReorder(item, 1)">- <heroicons-solid:arrow-circle-down- v-if="index !== state.maskingRuleItemList.length - 1"- class="w-6 h-6"- />- </button>- </div>- <NPopconfirm v-else @positive-click="onRuleDelete(item)">- <template #trigger>- <button- class="mt-4 w-5 h-5 p-0.5 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" />+ <div v-if="item.mode === 'NORMAL' && hasPermission">+ <div v-if="state.reorderRules" class="mt-6 flex flex-col">+ <button @click="onReorder(item, -1)">+ <heroicons-solid:arrow-circle-up+ v-if="index !== 0"+ class="w-6 h-6"+ />+ </button>+ <button @click="onReorder(item, 1)">+ <heroicons-solid:arrow-circle-down+ v-if="index !== state.maskingRuleItemList.length - 1"+ class="w-6 h-6"+ /></button>- </template>- <div class="whitespace-nowrap">- {{ $t("settings.sensitive-data.global-rules.delete-rule-tip") }}</div>- </NPopconfirm>- <MaskingRuleConfig- :index="index + 1"- :readonly="!hasPermission || state.reorderRules"- :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)"- />+ <button v-else class="mt-7" @click="onEdit(index)">+ <heroicons-outline:pencil class="w-4 h-4" />+ </button>+ </div>+ <div :class="['w-full', item.mode === 'NORMAL' ? '' : 'ml-8']">+ <MaskingRuleConfig+ :key="`expr-${item.rule.id}`"+ :index="index + 1"+ :disabled="state.processing"+ :masking-rule="item.rule"+ :readonly="item.mode === 'NORMAL' || state.reorderRules"+ :factor-list="factorList"+ :factor-options-map="factorOptionsMap"+ :allow-delete="item.mode === 'EDIT'"+ @cancel="onCancel(index)"+ @delete="onRuleDelete(index)"+ @confirm="(rule: MaskingRulePolicy_MaskingRule) => onConfirm(rule)"+ />+ </div></div></div></div></template><script lang="ts" setup>-import { NPopconfirm } from "naive-ui";import type { SelectOption } from "naive-ui";import { v4 as uuidv4 } from "uuid";import { computed, reactive, nextTick, onMounted } from "vue";@@ -128,7 +123,7 @@ import {getProjectIdOptions,} from "./components/utils";-type MaskingRuleMode = "CREATE" | "EDIT";+type MaskingRuleMode = "NORMAL" | "EDIT" | "CREATE";interface MaskingRuleItem {mode: MaskingRuleMode;@@ -170,7 +165,7 @@ const updateList = async () => {state.maskingRuleItemList = (policy.maskingRulePolicy?.rules ?? []).map((rule) => {return {- mode: "EDIT",+ mode: "NORMAL",rule,};}@@ -198,17 +193,21 @@ const addNewRule = () => {});};-const onCancel = (id: string, mode: MaskingRuleMode) => {- if (mode !== "CREATE") {- return;- }- const index = state.maskingRuleItemList.findIndex(- (item) => item.rule.id === id- );- if (index < 0) {- return;+const onEdit = (index: number) => {+ state.maskingRuleItemList[index].mode = "EDIT";+};++const onCancel = (index: number) => {+ const item = state.maskingRuleItemList[index];++ if (item.mode === "CREATE") {+ state.maskingRuleItemList.splice(index, 1);+ } else {+ state.maskingRuleItemList[index] = {+ ...item,+ mode: "NORMAL",+ };}- state.maskingRuleItemList.splice(index, 1);};const onConfirm = async (rule: MaskingRulePolicy_MaskingRule) => {@@ -224,9 +223,10 @@ const onConfirm = async (rule: MaskingRulePolicy_MaskingRule) => {}state.processing = true;+ const isCreate = state.maskingRuleItemList[index].mode === "CREATE";state.maskingRuleItemList[index] = {- mode: "EDIT",+ mode: "NORMAL",rule,};try {@@ -234,7 +234,7 @@ const onConfirm = async (rule: MaskingRulePolicy_MaskingRule) => {pushNotification({module: "bytebase",style: "SUCCESS",- title: t("common.updated"),+ title: t(`common.${isCreate ? "created" : "updated"}`),});} finally {state.processing = false;@@ -262,16 +262,11 @@ const onReorderSubmit = async () => {state.reorderRules = false;};-const onRuleDelete = async (maskingRuleItem: MaskingRuleItem) => {- const index = state.maskingRuleItemList.findIndex(- (item) => item.rule.id === maskingRuleItem.rule.id- );- if (index < 0) {- return;- }+const onRuleDelete = async (index: number) => {+ const item = state.maskingRuleItemList[index];state.maskingRuleItemList.splice(index, 1);- if (maskingRuleItem.mode === "CREATE") {+ if (item.mode === "CREATE") {return;}@@ -279,7 +274,7 @@ const onRuleDelete = async (maskingRuleItem: MaskingRuleItem) => {pushNotification({module: "bytebase",style: "SUCCESS",- title: t("common.updated"),+ title: t("common.deleted"),});};@@ -290,7 +285,7 @@ const onPolicyUpsert = async () => {resourceUid: "1",maskingRulePolicy: {rules: state.maskingRuleItemList- .filter((item) => item.mode === "EDIT")+ .filter((item) => item.mode === "NORMAL").map((item) => item.rule),},};diff --git a/frontend/src/components/SensitiveData/SensitiveColumnDrawer.vue b/frontend/src/components/SensitiveData/SensitiveColumnDrawer.vueindex 4064e0c954..0bbc86ee98 100644--- a/frontend/src/components/SensitiveData/SensitiveColumnDrawer.vue+++ b/frontend/src/components/SensitiveData/SensitiveColumnDrawer.vue@@ -269,8 +269,6 @@ const expirationTimeRegex = /request.time < timestamp\("(.+)?"\)/;const getAccessUsers = (exception: MaskingExceptionPolicy_MaskingException): AccessUser => {- console.log("exception");- console.log(exception);let expirationTimestamp: number | undefined;const expression = exception.condition?.expression ?? "";const matches = expirationTimeRegex.exec(expression);@@ -319,8 +317,6 @@ const updateAccessUserList = (policy: Policy | undefined) => {// - 2 cannot merge: user1, action:export, level:FULL, expires at 2023-09-04// - 3 & 4 is merged: user1, action:export+action, level:PARTIAL, expires at 2023-09-04const userMap = new Map<string, AccessUser>();- console.log("policy.maskingExceptionPolicy.maskingExceptions");- console.log(policy.maskingExceptionPolicy.maskingExceptions);for (const exception of policy.maskingExceptionPolicy.maskingExceptions) {if (!isCurrentColumnException(exception, props.column)) {continue;diff --git a/frontend/src/components/SensitiveData/components/MaskingRuleConfig.vue b/frontend/src/components/SensitiveData/components/MaskingRuleConfig.vueindex 58e92ae5bf..529c55f3e4 100644--- a/frontend/src/components/SensitiveData/components/MaskingRuleConfig.vue+++ b/frontend/src/components/SensitiveData/components/MaskingRuleConfig.vue@@ -3,16 +3,18 @@<div class="flex items-stretch gap-x-4 overflow-hidden"><div class="flex-1 space-y-2 py-4 overflow-x-hidden overflow-y-auto"><NInput+ v-if="!readonly"v-model:value="state.title"class="!w-64 ml-0.5"- :placeholder="`${t(- 'settings.sensitive-data.global-rules.condition-order'- )} ${props.index}`"+ :placeholder="defaultTitle"type="text"size="small"- :disabled="readonly || disabled"+ :disabled="disabled"@input="state.dirty = true"/>+ <h3 v-else class="font-medium text-sm text-main py-2">+ {{ state.title || defaultTitle }}+ </h3><ExprEditor:expr="state.expr":allow-admin="!readonly"@@ -33,33 +35,46 @@:options="options":placeholder="$t('settings.sensitive-data.masking-level.selet-level')":consistent-menu-width="false"- :disabled="readonly || disabled"+ :disabled="disabled || readonly"@update:value="state.dirty = true"/></div></div>- <div- v-if="(state.dirty || isCreate) && !readonly"- class="flex justify-end gap-x-3"- >- <NButton :disabled="disabled" @click="onCancel">- {{ $t("common.cancel") }}- </NButton>- <NButton- type="primary"- :disabled="!isValid || disabled"- @click="onConfirm"- >- {{ $t("common.confirm") }}- </NButton>+ <div v-if="!readonly" class="flex justify-between items-center">+ <NPopconfirm v-if="allowDelete" @positive-click="$emit('delete')">+ <template #trigger>+ <button+ class="flex items-center space-x-1 py-1 px-2 hover:bg-gray-300 rounded cursor-pointer disabled:cursor-not-allowed disabled:hover:bg-white disabled:text-gray-400"+ :disabled="disabled"+ @click.stop=""+ >+ <heroicons-outline:trash class="w-4 h-4" />+ <span class="text-sm textlabel">{{ $t("common.delete") }}</span>+ </button>+ </template>+ <div class="whitespace-nowrap">+ {{ $t("settings.sensitive-data.global-rules.delete-rule-tip") }}+ </div>+ </NPopconfirm>+ <div class="flex justify-end gap-x-3 ml-auto">+ <NButton :disabled="disabled" @click="onCancel">+ {{ $t("common.cancel") }}+ </NButton>+ <NButton+ type="primary"+ :disabled="!isValid || disabled || !state.dirty"+ @click="onConfirm"+ >+ {{ $t("common.confirm") }}+ </NButton>+ </div></div></div></template><script lang="ts" setup>-import { cloneDeep } from "lodash-es";-import { NSelect, SelectOption } from "naive-ui";-import { computed, ref, onMounted, nextTick } from "vue";+import { NSelect, SelectOption, NPopconfirm } from "naive-ui";+import { computed, reactive, onMounted, nextTick } from "vue";import { useI18n } from "vue-i18n";import ExprEditor from "@/components/ExprEditor";import type { ConditionGroupExpr, Factor } from "@/plugins/cel";@@ -84,9 +99,9 @@ import { factorSupportDropdown, factorOperatorOverrideMap } from "./utils";const props = defineProps<{index: number;- isCreate?: boolean;readonly: boolean;disabled: boolean;+ allowDelete: boolean;factorList: Factor[];factorOptionsMap: Map<Factor, SelectOption[]>;maskingRule: MaskingRulePolicy_MaskingRule;@@ -94,6 +109,7 @@ const props = defineProps<{const emit = defineEmits<{(event: "cancel"): void;+ (event: "delete"): void;(event: "confirm", rule: MaskingRulePolicy_MaskingRule): void;}>();@@ -105,15 +121,34 @@ type LocalState = {};const { t } = useI18n();-const state = ref<LocalState>({+const state = reactive<LocalState>({title: "",expr: wrapAsGroup(resolveCELExpr(CELExpr.fromJSON({}))),maskingLevel: MaskingLevel.FULL,dirty: false,});+const resetLocalState = async (rule: MaskingRulePolicy_MaskingRule) => {+ const parsedExpr = await convertCELStringToParsedExpr(+ rule.condition?.expression ?? ""+ );++ state.dirty = false;+ state.title = rule.condition?.title ?? "";+ state.expr = wrapAsGroup(+ resolveCELExpr(parsedExpr.expr ?? CELExpr.fromJSON({}))+ );+ state.maskingLevel = rule.maskingLevel;+};+onMounted(async () => {- await resetLocalState();+ await resetLocalState(props.maskingRule);+});++const defaultTitle = computed(() => {+ return `${t("settings.sensitive-data.global-rules.condition-order")} ${+ props.index+ }`;});const options = computed(() => {@@ -132,27 +167,13 @@ const options = computed(() => {});const onCancel = async () => {- await resetLocalState();+ await resetLocalState(props.maskingRule);emit("cancel");- nextTick(() => (state.value.dirty = false));-};--const resetLocalState = async () => {- const rule = cloneDeep(props.maskingRule);- const parsedExpr = await convertCELStringToParsedExpr(- rule.condition?.expression ?? ""- );-- state.value = {- dirty: false,- title: rule.condition?.title ?? "",- maskingLevel: rule.maskingLevel,- expr: wrapAsGroup(resolveCELExpr(parsedExpr.expr ?? CELExpr.fromJSON({}))),- };+ nextTick(() => (state.dirty = false));};const isValid = computed(() => {- const { expr } = state.value;+ const { expr } = state;if (!expr) return false;return validateSimpleExpr(expr);});@@ -160,17 +181,17 @@ const isValid = computed(() => {const onConfirm = async () => {const expression = await convertParsedExprToCELString(ParsedExpr.fromJSON({- expr: buildCELExpr(state.value.expr),+ expr: buildCELExpr(state.expr),}));emit("confirm", {...props.maskingRule,- maskingLevel: state.value.maskingLevel,+ maskingLevel: state.maskingLevel,condition: Expr.fromJSON({expression,- title: state.value.title,+ title: state.title,}),});- state.value.dirty = false;+ state.dirty = false;};</script>