Skip to content

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

chore: update masking exception table (#14184)

ecmadaoe321b8405e87
diff --git a/frontend/src/components/SensitiveData/MaskingExceptionUserTable.vue b/frontend/src/components/SensitiveData/MaskingExceptionUserTable.vue
index dc257c2773..71234e1d2e 100644
--- a/frontend/src/components/SensitiveData/MaskingExceptionUserTable.vue
+++ b/frontend/src/components/SensitiveData/MaskingExceptionUserTable.vue
@@ -46,6 +46,16 @@ const hasPermission = computed(() => {
return hasWorkspacePermissionV2("bb.policies.update");
});
+const getDatabaseAccessResource = (expr: string) => {
+ const expressions = expr
+ .split(" && ")
+ .filter((expr) => !expr.startsWith("request.time"));
+ if (expressions.length === 0) {
+ expressions.push("all databases");
+ }
+ return expressions;
+};
+
const accessTableColumns = computed(
(): DataTableColumn<AccessUser & { hide?: boolean }>[] => {
return [
@@ -54,14 +64,7 @@ const accessTableColumns = computed(
expandable: (_: AccessUser) => true,
hide: props.showDatabaseColumn,
renderExpand: (item: AccessUser) => {
- const expressions = item.rawExpression.split(" && ");
- if (
- expressions.length === 0 ||
- (expressions.length === 1 &&
- expressions[0].startsWith("request.time"))
- ) {
- expressions.push("all databases");
- }
+ const expressions = getDatabaseAccessResource(item.rawExpression);
return (
<ul class="list-disc pl-6 textinfolabel">
@@ -107,17 +110,10 @@ const accessTableColumns = computed(
title: t("common.resource"),
hide: !props.showDatabaseColumn,
render: (item: AccessUser) => {
- const expressions = item.rawExpression.split(" && ");
- if (
- expressions.length === 0 ||
- (expressions.length === 1 &&
- expressions[0].startsWith("request.time"))
- ) {
- expressions.push("all databases");
- }
+ const expressions = getDatabaseAccessResource(item.rawExpression);
return (
- <ul class="list-disc pl-6 textinfolabel">
+ <ul class="list-disc">
{expressions.map((expression, i) => (
<li key={`${item.key}.${i}`}>{expression}</li>
))}
diff --git a/frontend/src/components/SensitiveData/SensitiveColumnDrawer.vue b/frontend/src/components/SensitiveData/SensitiveColumnDrawer.vue
index bd232b0aed..4b4fa52249 100644
--- a/frontend/src/components/SensitiveData/SensitiveColumnDrawer.vue
+++ b/frontend/src/components/SensitiveData/SensitiveColumnDrawer.vue
@@ -128,7 +128,7 @@
size="small"
:access-list="accessUserList"
:disabled="state.processing"
- :show-database-column="true"
+ :show-database-column="false"
@remove:access="onRemove"
@update:access="onAccessControlUpdate"
/>
diff --git a/frontend/src/views/project/ProjectDatabaseMaskingAccess.vue b/frontend/src/views/project/ProjectDatabaseMaskingAccess.vue
index 5184f7de07..af79d6184f 100644
--- a/frontend/src/views/project/ProjectDatabaseMaskingAccess.vue
+++ b/frontend/src/views/project/ProjectDatabaseMaskingAccess.vue
@@ -1,5 +1,145 @@
<template>
- <div></div>
+ <MaskingExceptionUserTable
+ size="medium"
+ :access-list="accessList"
+ :disabled="false"
+ :show-database-column="true"
+ />
</template>
-<script lang="tsx" setup></script>
+<script lang="tsx" setup>
+import { orderBy } from "lodash-es";
+import { computed } from "vue";
+import MaskingExceptionUserTable from "@/components/SensitiveData/MaskingExceptionUserTable.vue";
+import type { AccessUser } from "@/components/SensitiveData/types";
+import { useProjectByName } from "@/store";
+import {
+ usePolicyByParentAndType,
+ useUserStore,
+ useGroupStore,
+ extractGroupEmail,
+} from "@/store";
+import { projectNamePrefix } from "@/store/modules/v1/common";
+import {
+ getUserEmailInBinding,
+ getGroupEmailInBinding,
+ groupBindingPrefix,
+} from "@/types";
+import { maskingLevelToJSON } from "@/types/proto/v1/common";
+import { PolicyType } from "@/types/proto/v1/org_policy_service";
+import type { MaskingExceptionPolicy_MaskingException } from "@/types/proto/v1/org_policy_service";
+
+const props = defineProps<{
+ projectId: string;
+}>();
+
+const userStore = useUserStore();
+const groupStore = useGroupStore();
+
+const { project } = useProjectByName(
+ computed(() => `${projectNamePrefix}${props.projectId}`)
+);
+
+const policy = usePolicyByParentAndType(
+ computed(() => ({
+ parentPath: project.value.name,
+ policyType: PolicyType.MASKING_EXCEPTION,
+ }))
+);
+
+const expirationTimeRegex = /request.time < timestamp\("(.+)?"\)/;
+
+const getAccessUsers = (
+ exception: MaskingExceptionPolicy_MaskingException
+): AccessUser | undefined => {
+ let expirationTimestamp: number | undefined;
+ const expression = exception.condition?.expression ?? "";
+ const matches = expirationTimeRegex.exec(expression);
+ if (matches) {
+ expirationTimestamp = new Date(matches[1]).getTime();
+ }
+
+ const access: AccessUser = {
+ type: "user",
+ key: exception.member,
+ maskingLevel: exception.maskingLevel,
+ expirationTimestamp,
+ supportActions: new Set([exception.action]),
+ rawExpression: expression,
+ };
+
+ if (exception.member.startsWith(groupBindingPrefix)) {
+ access.type = "group";
+ access.group = groupStore.getGroupByIdentifier(exception.member);
+ } else {
+ access.type = "user";
+ access.user = userStore.getUserByIdentifier(exception.member);
+ }
+
+ if (!access.group && !access.user) {
+ return;
+ }
+
+ return access;
+};
+
+const getExceptionIdentifier = (
+ exception: MaskingExceptionPolicy_MaskingException
+): string => {
+ const expression = exception.condition?.expression ?? "";
+ const res: string[] = [
+ `level:"${maskingLevelToJSON(exception.maskingLevel)}"`,
+ expression,
+ ];
+ return res.join(" && ");
+};
+
+const getMemberBinding = (access: AccessUser): string => {
+ if (access.type === "user") {
+ return getUserEmailInBinding(access.user!.email);
+ }
+ const email = extractGroupEmail(access.group!.name);
+ return getGroupEmailInBinding(email);
+};
+
+const accessList = computed(() => {
+ if (!policy.value || !policy.value.maskingExceptionPolicy) {
+ return [];
+ }
+
+ const memberMap = new Map<string, AccessUser>();
+ for (const exception of policy.value.maskingExceptionPolicy
+ .maskingExceptions) {
+ const identifier = getExceptionIdentifier(exception);
+ const item = getAccessUsers(exception);
+ if (!item) {
+ continue;
+ }
+ const id = `${getMemberBinding(item)}:${identifier}`;
+ item.key = id;
+ const target = memberMap.get(id) ?? item;
+ if (memberMap.has(id)) {
+ for (const action of item.supportActions) {
+ target.supportActions.add(action);
+ }
+ }
+ memberMap.set(id, target);
+ }
+
+ return orderBy(
+ [...memberMap.values()],
+ [
+ (access) => (access.type === "user" ? 1 : 0),
+ (access) => {
+ if (access.group) {
+ return access.group.name;
+ } else if (access.user) {
+ return access.user.name;
+ }
+ return "";
+ },
+ ],
+ ["desc", "desc"]
+ );
+});
+</script>