Skip to content

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

chore: optimize perf for masking exemption (#15077)

ecmadaoee71c8b2a790
diff --git a/frontend/src/components/Database/DatabaseSensitiveDataPanel.vue b/frontend/src/components/Database/DatabaseSensitiveDataPanel.vue
index 3d0e13f5dd..6054cc1089 100644
--- a/frontend/src/components/Database/DatabaseSensitiveDataPanel.vue
+++ b/frontend/src/components/Database/DatabaseSensitiveDataPanel.vue
@@ -70,26 +70,6 @@
}
"
/>
-
- <SensitiveColumnDrawer
- v-if="
- filteredColumnList.length > 0 &&
- state.showSensitiveColumnDrawer &&
- state.pendingGrantAccessColumn.length === 1
- "
- :database="database"
- :mask="
- state.pendingGrantAccessColumn.length === 1
- ? state.pendingGrantAccessColumn[0]
- : filteredColumnList[0]
- "
- @dismiss="
- () => {
- state.showSensitiveColumnDrawer = false;
- state.pendingGrantAccessColumn = [];
- }
- "
- />
</template>
<script lang="tsx" setup>
@@ -103,7 +83,6 @@ import {
FeatureAttentionForInstanceLicense,
} from "@/components/FeatureGuard";
import GrantAccessDrawer from "@/components/SensitiveData/GrantAccessDrawer.vue";
-import SensitiveColumnDrawer from "@/components/SensitiveData/SensitiveColumnDrawer.vue";
import SensitiveColumnTable from "@/components/SensitiveData/components/SensitiveColumnTable.vue";
import type { MaskData } from "@/components/SensitiveData/types";
import { isCurrentColumnException } from "@/components/SensitiveData/utils";
@@ -130,7 +109,6 @@ interface LocalState {
sensitiveColumnList: MaskData[];
pendingGrantAccessColumn: MaskData[];
showGrantAccessDrawer: boolean;
- showSensitiveColumnDrawer: boolean;
}
const state = reactive<LocalState>({
@@ -140,7 +118,6 @@ const state = reactive<LocalState>({
sensitiveColumnList: [],
pendingGrantAccessColumn: [],
showGrantAccessDrawer: false,
- showSensitiveColumnDrawer: false,
});
const hasUpdateCatalogPermission = computed(() => {
diff --git a/frontend/src/components/SensitiveData/MaskingExceptionUserTable.vue b/frontend/src/components/SensitiveData/MaskingExceptionUserTable.vue
index 5396cb35c0..5f10105a58 100644
--- a/frontend/src/components/SensitiveData/MaskingExceptionUserTable.vue
+++ b/frontend/src/components/SensitiveData/MaskingExceptionUserTable.vue
@@ -2,7 +2,7 @@
<NDataTable
:size="size"
:columns="accessTableColumns"
- :data="state.accessList"
+ :data="filteredList"
:row-key="(row: AccessUser) => row.key"
:bordered="true"
:striped="true"
@@ -49,10 +49,7 @@ import {
} from "@/types";
import { Expr } from "@/types/proto/google/type/expr";
import { MaskingExceptionPolicy_MaskingException_Action } from "@/types/proto/v1/org_policy_service";
-import type {
- Policy,
- MaskingExceptionPolicy_MaskingException,
-} from "@/types/proto/v1/org_policy_service";
+import type { MaskingExceptionPolicy_MaskingException } from "@/types/proto/v1/org_policy_service";
import { PolicyType } from "@/types/proto/v1/org_policy_service";
import { autoDatabaseRoute, hasWorkspacePermissionV2 } from "@/utils";
import {
@@ -64,7 +61,7 @@ import { type AccessUser } from "./types";
interface LocalState {
processing: boolean;
- accessList: AccessUser[];
+ rawAccessList: AccessUser[];
}
const props = defineProps<{
@@ -73,14 +70,12 @@ const props = defineProps<{
// project full name
project: string;
showDatabaseColumn: boolean;
- filterException: (
- exception: MaskingExceptionPolicy_MaskingException
- ) => boolean;
+ filterAccessUser: (accessUser: AccessUser) => boolean;
}>();
const state = reactive<LocalState>({
processing: false,
- accessList: [],
+ rawAccessList: [],
});
const { t } = useI18n();
const router = useRouter();
@@ -101,6 +96,10 @@ const { policy, ready } = usePolicyByParentAndType(
}))
);
+const filteredList = computed(() =>
+ state.rawAccessList.filter(props.filterAccessUser)
+);
+
const isValidDatabaseResource = (access: AccessUser): boolean => {
if (!access.databaseResource) {
return true;
@@ -193,7 +192,7 @@ const getAccessUsers = (
const access: AccessUser = {
type: "user",
- key: exception.member,
+ key: `${exception.member}:${expression}`,
expirationTimestamp,
supportActions: new Set([exception.action]),
rawExpression: expression,
@@ -217,14 +216,6 @@ const getAccessUsers = (
return access;
};
-const getExceptionIdentifier = (
- exception: MaskingExceptionPolicy_MaskingException
-): string => {
- const expression = exception.condition?.expression ?? "";
- const res: string[] = [expression];
- return res.join(" && ");
-};
-
const getMemberBinding = (access: AccessUser): string => {
if (access.type === "user") {
return getUserEmailInBinding(access.user!.email);
@@ -233,8 +224,8 @@ const getMemberBinding = (access: AccessUser): string => {
return getGroupEmailInBinding(email);
};
-const updateAccessUserList = async (policy: Policy | undefined) => {
- if (!policy || !policy.maskingExceptionPolicy) {
+const updateAccessUserList = async () => {
+ if (!ready.value || !policy.value || !policy.value.maskingExceptionPolicy) {
return [];
}
@@ -250,7 +241,7 @@ const updateAccessUserList = async (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-04
const memberMap = new Map<string, AccessUser>();
- const { maskingExceptions } = policy.maskingExceptionPolicy;
+ const { maskingExceptions } = policy.value.maskingExceptionPolicy;
const expressionList = maskingExceptions.map((e) =>
e.condition?.expression ? e.condition?.expression : "true"
);
@@ -260,26 +251,21 @@ const updateAccessUserList = async (policy: Policy | undefined) => {
const exception = maskingExceptions[i];
const condition = conditionList[i];
- if (!props.filterException(exception)) {
- continue;
- }
- const identifier = getExceptionIdentifier(exception);
const item = getAccessUsers(exception, condition);
if (!item) {
continue;
}
- const id = `${getMemberBinding(item)}:${identifier}`;
- item.key = id;
- const target = memberMap.get(id) ?? item;
- if (memberMap.has(id)) {
+
+ const target = memberMap.get(item.key) ?? item;
+ if (memberMap.has(item.key)) {
for (const action of item.supportActions) {
target.supportActions.add(action);
}
}
- memberMap.set(id, target);
+ memberMap.set(item.key, target);
}
- state.accessList = orderBy(
+ state.rawAccessList = orderBy(
[...memberMap.values()],
[
(access) => (access.type === "user" ? 1 : 0),
@@ -296,9 +282,7 @@ const updateAccessUserList = async (policy: Policy | undefined) => {
);
};
-watchEffect(async () => {
- updateAccessUserList(policy.value);
-});
+watchEffect(updateAccessUserList);
const accessTableColumns = computed(
(): DataTableColumn<AccessUser & { hide?: boolean }>[] => {
@@ -354,7 +338,7 @@ const accessTableColumns = computed(
key: "export",
title: t("settings.sensitive-data.action.export"),
width: "5rem",
- render: (item: AccessUser, row: number) => {
+ render: (item: AccessUser) => {
return (
<NCheckbox
checked={item.supportActions.has(
@@ -363,7 +347,7 @@ const accessTableColumns = computed(
disabled={!hasPermission.value || props.disabled}
onUpdateChecked={() =>
onAccessControlUpdate(
- row,
+ item,
(item) =>
toggleAction(
item,
@@ -384,7 +368,7 @@ const accessTableColumns = computed(
key: "query",
title: t("settings.sensitive-data.action.query"),
width: "5rem",
- render: (item: AccessUser, row: number) => {
+ render: (item: AccessUser) => {
return (
<NCheckbox
checked={item.supportActions.has(
@@ -393,7 +377,7 @@ const accessTableColumns = computed(
disabled={!hasPermission.value || props.disabled}
onUpdate:checked={() =>
onAccessControlUpdate(
- row,
+ item,
(item) =>
toggleAction(
item,
@@ -413,7 +397,7 @@ const accessTableColumns = computed(
{
key: "expire",
title: t("common.expiration"),
- render: (item: AccessUser, row: number) => {
+ render: (item: AccessUser) => {
return (
<NDatePicker
value={item.expirationTimestamp}
@@ -425,7 +409,7 @@ const accessTableColumns = computed(
disabled={!hasPermission.value || props.disabled}
onUpdate:value={(val: number | undefined) =>
onAccessControlUpdate(
- row,
+ item,
(item) => (item.expirationTimestamp = val)
)
}
@@ -438,12 +422,12 @@ const accessTableColumns = computed(
title: "",
hide: !hasPermission.value,
width: "4rem",
- render: (_: AccessUser, row: number) => {
+ render: (item: AccessUser) => {
return h(
MiniActionButton,
{
onClick: () => {
- revokeAccessAlert(row);
+ revokeAccessAlert(item);
},
},
{
@@ -468,10 +452,9 @@ const toggleAction = (
};
const revokeAccessAlert = (
- index: number,
+ item: AccessUser,
revert: (item: AccessUser) => void = () => {}
) => {
- const item = state.accessList[index];
$dialog.warning({
title: t("common.warning"),
content: () => {
@@ -493,29 +476,29 @@ const revokeAccessAlert = (
maskClosable: false,
onClose: () => revert(item),
onPositiveClick: async () => {
- await onRemove(index);
+ await onRemove(item);
},
onNegativeClick: () => revert(item),
});
};
-const onRemove = async (index: number) => {
- state.accessList.splice(index, 1);
+const onRemove = async (item: AccessUser) => {
+ const index = state.rawAccessList.findIndex((a) => a.key === item.key);
+ if (index < 0) {
+ return;
+ }
+ state.rawAccessList.splice(index, 1);
await onSubmit();
};
const onAccessControlUpdate = async (
- index: number,
+ item: AccessUser,
callback: (item: AccessUser) => void,
revert: (item: AccessUser) => void = () => {}
) => {
- const item = state.accessList[index];
- if (!item) {
- return;
- }
callback(item);
if (item.supportActions.size === 0) {
- revokeAccessAlert(index, revert);
+ revokeAccessAlert(item, revert);
} else {
await onSubmit();
}
@@ -545,11 +528,8 @@ const updateExceptionPolicy = async () => {
return;
}
- const unChangedExceptions = (
- policy.maskingExceptionPolicy?.maskingExceptions ?? []
- ).filter((exception) => !props.filterException(exception));
-
- for (const accessUser of state.accessList) {
+ const exceptions = [];
+ for (const accessUser of state.rawAccessList) {
const expressions = accessUser.rawExpression
.split(" && ")
.filter((expression) => expression);
@@ -572,7 +552,7 @@ const updateExceptionPolicy = async () => {
);
}
for (const action of accessUser.supportActions) {
- unChangedExceptions.push({
+ exceptions.push({
action,
member: getMemberBinding(accessUser),
condition: Expr.fromPartial({
@@ -584,7 +564,7 @@ const updateExceptionPolicy = async () => {
policy.maskingExceptionPolicy = {
...(policy.maskingExceptionPolicy ?? {}),
- maskingExceptions: unChangedExceptions,
+ maskingExceptions: exceptions,
};
await policyStore.upsertPolicy({
parentPath: props.project,
diff --git a/frontend/src/components/SensitiveData/SensitiveColumnDrawer.vue b/frontend/src/components/SensitiveData/SensitiveColumnDrawer.vue
deleted file mode 100644
index b64eb91eec..0000000000
--- a/frontend/src/components/SensitiveData/SensitiveColumnDrawer.vue
+++ /dev/null
@@ -1,105 +0,0 @@
-<template>
- <Drawer :show="true" @close="$emit('dismiss')">
- <DrawerContent
- :title="
- $t('settings.sensitive-data.column-detail.masking-setting-for-column', {
- column: mask.column,
- })
- "
- >
- <div class="divide-block-border divide-y space-y-8 w-[50rem] h-full">
- <div class="space-y-5">
- <div class="flex justify-between">
- <div>
- <h1 class="font-semibold">
- {{
- $t("settings.sensitive-data.column-detail.access-user-list")
- }}
- </h1>
- <span class="textinfolabel">{{
- $t(
- "settings.sensitive-data.column-detail.access-user-list-desc"
- )
- }}</span>
- </div>
- <NButton
- type="primary"
- :disabled="!hasPermissionToUpdatePolicy"
- @click="state.showGrantAccessDrawer = true"
- >
- {{ $t("settings.sensitive-data.grant-access") }}
- </NButton>
- </div>
- <MaskingExceptionUserTable
- size="small"
- :project="database.project"
- :disabled="state.processing"
- :show-database-column="false"
- :filter-exception="
- (exception) =>
- isCurrentColumnException(exception, {
- maskData: mask,
- database,
- })
- "
- />
- </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>
- </div>
- </div>
- </template>
- </DrawerContent>
- </Drawer>
-
- <GrantAccessDrawer
- v-if="state.showGrantAccessDrawer"
- :column-list="[
- {
- maskData: mask,
- database,
- },
- ]"
- :project-name="database.project"
- @dismiss="state.showGrantAccessDrawer = false"
- />
-</template>
-
-<script lang="tsx" setup>
-import { NButton } from "naive-ui";
-import { computed, reactive } from "vue";
-import type { MaskData } from "@/components/SensitiveData/types";
-import { Drawer, DrawerContent } from "@/components/v2";
-import { type ComposedDatabase } from "@/types";
-import { hasWorkspacePermissionV2 } from "@/utils";
-import GrantAccessDrawer from "./GrantAccessDrawer.vue";
-import MaskingExceptionUserTable from "./MaskingExceptionUserTable.vue";
-import { isCurrentColumnException } from "./utils";
-
-interface LocalState {
- processing: boolean;
- showGrantAccessDrawer: boolean;
-}
-
-defineProps<{
- mask: MaskData;
- database: ComposedDatabase;
-}>();
-
-defineEmits(["dismiss"]);
-
-const state = reactive<LocalState>({
- processing: false,
- showGrantAccessDrawer: false,
-});
-
-const hasPermissionToUpdatePolicy = computed(() => {
- return hasWorkspacePermissionV2("bb.policies.update");
-});
-</script>
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 9d58b57f36..1c0155e6a2 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -665,11 +665,6 @@
},
"select": "Select semantic type"
},
- "column-detail": {
- "masking-setting-for-column": "Masking Setting for \"{column}\"",
- "access-user-list": "Access User List",
- "access-user-list-desc": "Users granted to access de-masked data."
- },
"algorithms": {
"add": "Add algorithm",
"edit": "Edit algorithm",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index cc39dff243..efac64d444 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -665,11 +665,6 @@
},
"select": "Seleccionar tipo semántico"
},
- "column-detail": {
- "masking-setting-for-column": "Configuración de enmascaramiento para \"{columna}\"",
- "access-user-list": "Acceder a la lista de usuarios",
- "access-user-list-desc": "Usuarios autorizados a acceder a datos desenmascarados."
- },
"algorithms": {
"add": "Agregar algoritmo",
"edit": "Editar algoritmo",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index b3d5654cc3..5272a37804 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -665,11 +665,6 @@
},
"select": "セマンティックタイプの選択"
},
- "column-detail": {
- "masking-setting-for-column": "「{column}」の感度解除設定",
- "access-user-list": "ユーザーアクセスリスト",
- "access-user-list-desc": "許可されたユーザーは、感度を下げられていない生データにアクセスできます。"
- },
"algorithms": {
"add": "アルゴリズムを追加",
"edit": "アルゴリズムを編集",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index a459ee12c5..b089864559 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -665,11 +665,6 @@
},
"select": "选择语义类型"
},
- "column-detail": {
- "masking-setting-for-column": "\"{column}\" 脱敏设置",
- "access-user-list": "用户访问列表",
- "access-user-list-desc": "被授权的用户可以访问非脱敏的原始数据。"
- },
"algorithms": {
"add": "添加算法",
"edit": "编辑算法",
@@ -1714,7 +1709,7 @@
"masking-exemption": {
"self": "脱敏豁免",
"grant-exemption": "授予豁免",
- "revoke-exemption-title": "是否豁免 {member} 的导出和查询脱敏?"
+ "revoke-exemption-title": "是否撤销 {member} 的导出和查询脱敏?"
}
},
"gitops": {
diff --git a/frontend/src/views/project/ProjectMaskingExemption.vue b/frontend/src/views/project/ProjectMaskingExemption.vue
index e01b255cd4..b254a6c840 100644
--- a/frontend/src/views/project/ProjectMaskingExemption.vue
+++ b/frontend/src/views/project/ProjectMaskingExemption.vue
@@ -9,7 +9,7 @@
:include-all="false"
:clearable="true"
:project-name="project.name"
- :database-name="state.selectedDatabaseName"
+ v-model:database-name="state.selectedDatabaseName"
/>
<MaskingActionDropdown
v-model:action="state.selectedAction"
@@ -58,7 +58,7 @@
:disabled="false"
:project="project.name"
:show-database-column="true"
- :filter-exception="filterException"
+ :filter-access-user="filterAccessUser"
/>
</div>
@@ -77,18 +77,17 @@ import { useRouter } from "vue-router";
import { FeatureModal, FeatureBadge } from "@/components/FeatureGuard";
import MaskingExceptionUserTable from "@/components/SensitiveData/MaskingExceptionUserTable.vue";
import MaskingActionDropdown from "@/components/SensitiveData/components/MaskingActionDropdown.vue";
+import { type AccessUser } from "@/components/SensitiveData/types";
import { SearchBox, DatabaseSelect } from "@/components/v2";
import { PROJECT_V1_ROUTE_MASKING_EXEMPTION_CREATE } from "@/router/dashboard/projectV1";
import { useProjectByName, hasFeature } from "@/store";
import { projectNamePrefix } from "@/store/modules/v1/common";
-import type { MaskingExceptionPolicy_MaskingException } from "@/types/proto/v1/org_policy_service";
import { MaskingExceptionPolicy_MaskingException_Action as Action } from "@/types/proto/v1/org_policy_service";
-import { extractDatabaseResourceName, hasProjectPermissionV2 } from "@/utils";
+import { hasProjectPermissionV2 } from "@/utils";
interface LocalState {
searchText: string;
showFeatureModal: boolean;
- selectedEnvironmentName?: string;
selectedDatabaseName?: string;
selectedAction?: Action;
}
@@ -118,27 +117,23 @@ const allowCreate = computed(() => {
);
});
-const filterException = (
- exception: MaskingExceptionPolicy_MaskingException
-): boolean => {
- if (state.selectedAction && exception.action !== state.selectedAction) {
+const filterAccessUser = (user: AccessUser): boolean => {
+ if (state.selectedAction && !user.supportActions.has(state.selectedAction)) {
return false;
}
if (
state.searchText.trim() &&
- !exception.member.toLowerCase().includes(state.searchText.trim())
+ !user.key.toLowerCase().includes(state.searchText.trim())
) {
return false;
}
if (state.selectedDatabaseName) {
- const { instanceName, databaseName } = extractDatabaseResourceName(
- state.selectedDatabaseName
+ if (!user.databaseResource) {
+ return true;
+ }
+ return (
+ user.databaseResource.databaseFullName === state.selectedDatabaseName
);
- const expression = [
- `resource.instance_id == "${instanceName}"`,
- `resource.database_name == "${databaseName}"`,
- ].join(" && ");
- return exception.condition?.expression?.includes(expression) ?? false;
}
return true;