Skip to content

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

chore: use full page for grant masking exception policy (#14258)

ecmadao341ab2618d7c
diff --git a/frontend/src/components/QuickActionPanel.vue b/frontend/src/components/QuickActionPanel.vue
index 552863a7af..15edf33c81 100644
--- a/frontend/src/components/QuickActionPanel.vue
+++ b/frontend/src/components/QuickActionPanel.vue
@@ -78,15 +78,6 @@
"
@close="state.quickActionType = undefined"
/>
- <GrantAccessDrawer
- v-if="
- project &&
- state.quickActionType === 'quickaction.bb.database.masking-access'
- "
- :column-list="[]"
- :project-name="project.name"
- @close="state.quickActionType = undefined"
- />
</template>
<FeatureModal
@@ -121,10 +112,12 @@ import {
Buttons as InstanceFormButtons,
} from "@/components/InstanceForm/";
import ProjectCreatePanel from "@/components/Project/ProjectCreatePanel.vue";
-import GrantAccessDrawer from "@/components/SensitiveData/GrantAccessDrawer.vue";
import { TransferDatabaseForm } from "@/components/TransferDatabaseForm";
import { Drawer, DrawerContent } from "@/components/v2";
-import { PROJECT_V1_ROUTE_DATABASE_GROUP_DETAIL } from "@/router/dashboard/projectV1";
+import {
+ PROJECT_V1_ROUTE_DATABASE_GROUP_DETAIL,
+ PROJECT_V1_ROUTE_MASKING_ACCESS_CREATE,
+} from "@/router/dashboard/projectV1";
import { PROJECT_V1_ROUTE_DASHBOARD } from "@/router/dashboard/workspaceRoutes";
import {
useCommandStore,
@@ -326,8 +319,11 @@ const availableQuickActionList = computed((): QuickAction[] => {
type: "quickaction.bb.database.masking-access",
title: t("project.masking-access.grant-access"),
hide: !hasSensitiveDataFeature.value,
- action: () =>
- (state.quickActionType = "quickaction.bb.database.masking-access"),
+ action: () => {
+ router.push({
+ name: PROJECT_V1_ROUTE_MASKING_ACCESS_CREATE,
+ });
+ },
icon: h(ShieldCheckIcon),
},
];
diff --git a/frontend/src/components/SensitiveData/GrantAccessDrawer.vue b/frontend/src/components/SensitiveData/GrantAccessDrawer.vue
index e05207532f..4b009487bb 100644
--- a/frontend/src/components/SensitiveData/GrantAccessDrawer.vue
+++ b/frontend/src/components/SensitiveData/GrantAccessDrawer.vue
@@ -1,283 +1,33 @@
<template>
- <Drawer :show="true" @close="onDismiss">
+ <Drawer :show="true" @close="() => emit('dismiss')">
<DrawerContent
:title="$t('settings.sensitive-data.grant-access')"
- class="w-[64rem] max-w-[100vw] relative"
+ class="w-[64rem] max-w-[100vw] relative grant-access-drawer"
>
- <div class="divide-block-border space-y-8 h-full">
- <div class="w-full">
- <div class="flex items-center gap-x-1 mb-2">
- <span>{{ $t("common.resources") }}</span>
- <span class="text-red-600">*</span>
- </div>
- <DatabaseResourceForm
- v-model:database-resources="state.databaseResources"
- :project-name="projectName"
- :required-feature="'bb.feature.sensitive-data'"
- :include-cloumn="true"
- />
- </div>
-
- <div class="w-full">
- <div class="flex items-center gap-x-1 mb-2">
- <span>{{ $t("settings.sensitive-data.action.self") }}</span>
- <span class="text-red-600">*</span>
- </div>
- <div class="flex space-x-4">
- <NCheckbox
- v-for="action in ACTIONS"
- :key="action"
- :checked="state.supportActions.has(action)"
- @update:checked="toggleAction(action, $event)"
- >
- {{
- $t(
- `settings.sensitive-data.action.${maskingExceptionPolicy_MaskingException_ActionToJSON(
- action
- ).toLowerCase()}`
- )
- }}
- </NCheckbox>
- </div>
- </div>
-
- <div class="w-full">
- <div class="flex items-center gap-x-1 mb-2">
- <span>{{ $t("settings.sensitive-data.masking-level.self") }}</span>
- <span class="text-red-600">*</span>
- </div>
- <MaskingLevelRadioGroup
- :level="state.maskingLevel"
- :level-list="MASKING_LEVELS"
- @update:level="state.maskingLevel = $event"
- />
- </div>
-
- <div class="w-full">
- <p class="mb-2">{{ $t("common.expiration") }}</p>
- <NDatePicker
- v-model:value="state.expirationTimestamp"
- style="width: 100%"
- type="datetime"
- :is-date-disabled="(date: number) => date < Date.now()"
- clearable
- />
- <span v-if="!state.expirationTimestamp" class="textinfolabel">{{
- $t("settings.sensitive-data.never-expires")
- }}</span>
- </div>
-
- <MembersBindingSelect
- v-model:value="state.memberList"
- :required="true"
- :project-name="projectName"
- :include-all-users="false"
- :include-service-account="false"
- />
- </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="onDismiss">
- {{ $t("common.cancel") }}
- </NButton>
- <NButton
- :disabled="submitDisabled || state.processing"
- type="primary"
- @click.prevent="onSubmit"
- >
- {{ $t("common.confirm") }}
- </NButton>
- </div>
- </div>
- </template>
+ <GrantAccessForm
+ :column-list="columnList"
+ :project-name="projectName"
+ @dismiss="() => emit('dismiss')"
+ />
</DrawerContent>
</Drawer>
</template>
<script lang="ts" setup>
-import { isUndefined } from "lodash-es";
-import { NButton, NCheckbox, NDatePicker } from "naive-ui";
-import { computed, reactive } from "vue";
-import { useI18n } from "vue-i18n";
-import DatabaseResourceForm from "@/components/GrantRequestPanel/DatabaseResourceForm/index.vue";
-import MembersBindingSelect from "@/components/Member/MembersBindingSelect.vue";
+import GrantAccessForm from "@/components/SensitiveData/GrantAccessForm.vue";
import { Drawer, DrawerContent } from "@/components/v2";
-import { usePolicyV1Store, pushNotification } from "@/store";
-import type { DatabaseResource } from "@/types";
-import { Expr } from "@/types/proto/google/type/expr";
-import { MaskingLevel } from "@/types/proto/v1/common";
-import type {
- Policy,
- MaskingExceptionPolicy_MaskingException,
-} from "@/types/proto/v1/org_policy_service";
-import {
- PolicyType,
- PolicyResourceType,
- MaskingExceptionPolicy_MaskingException_Action,
- maskingExceptionPolicy_MaskingException_ActionToJSON,
-} from "@/types/proto/v1/org_policy_service";
-import MaskingLevelRadioGroup from "./components/MaskingLevelRadioGroup.vue";
import type { SensitiveColumn } from "./types";
-import {
- getExpressionsForDatabaseResource,
- convertSensitiveColumnToDatabaseResource,
-} from "./utils";
-const props = defineProps<{
+defineProps<{
columnList: SensitiveColumn[];
projectName: string;
}>();
const emit = defineEmits(["dismiss"]);
+</script>
-interface LocalState {
- memberList: string[];
- expirationTimestamp?: number;
- maskingLevel: MaskingLevel;
- processing: boolean;
- supportActions: Set<MaskingExceptionPolicy_MaskingException_Action>;
- databaseResources?: DatabaseResource[];
+<style scoped lang="postcss">
+.grant-access-drawer :deep(.n-drawer-body-content-wrapper) {
+ padding-bottom: 0 !important;
}
-
-const ACTIONS = [
- MaskingExceptionPolicy_MaskingException_Action.EXPORT,
- MaskingExceptionPolicy_MaskingException_Action.QUERY,
-];
-const MASKING_LEVELS = [MaskingLevel.PARTIAL, MaskingLevel.NONE];
-
-const state = reactive<LocalState>({
- memberList: [],
- maskingLevel: MaskingLevel.PARTIAL,
- processing: false,
- supportActions: new Set(ACTIONS),
- databaseResources: props.columnList.map(
- convertSensitiveColumnToDatabaseResource
- ),
-});
-
-const policyStore = usePolicyV1Store();
-const { t } = useI18n();
-
-const resetState = () => {
- state.expirationTimestamp = undefined;
- state.maskingLevel = MaskingLevel.PARTIAL;
- state.supportActions = new Set(ACTIONS);
- state.memberList = [];
- state.databaseResources = undefined;
- state.processing = false;
-};
-
-const onDismiss = () => {
- emit("dismiss");
- resetState();
-};
-
-const submitDisabled = computed(() => {
- if (state.memberList.length === 0) {
- return true;
- }
- if (state.supportActions.size === 0) {
- return true;
- }
- if (
- !isUndefined(state.databaseResources) &&
- state.databaseResources.length === 0
- ) {
- return true;
- }
- return false;
-});
-
-const onSubmit = async () => {
- state.processing = true;
-
- try {
- const pendingUpdate = await getPendingUpdatePolicy(props.projectName);
- await policyStore.upsertPolicy({
- parentPath: props.projectName,
- policy: pendingUpdate,
- updateMask: ["payload"],
- });
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("common.created"),
- });
- onDismiss();
- } finally {
- state.processing = false;
- }
-};
-
-const getPendingUpdatePolicy = async (
- parentPath: string
-): Promise<Partial<Policy>> => {
- const maskingExceptions: MaskingExceptionPolicy_MaskingException[] = [];
-
- const expressions = [];
- if (state.expirationTimestamp) {
- expressions.push(
- `request.time < timestamp("${new Date(
- state.expirationTimestamp
- ).toISOString()}")`
- );
- }
-
- for (const action of state.supportActions.values()) {
- for (const member of state.memberList) {
- if (!state.databaseResources) {
- maskingExceptions.push({
- member,
- action,
- maskingLevel: state.maskingLevel,
- condition: Expr.fromPartial({
- expression:
- expressions.length > 0 ? expressions.join(" && ") : undefined,
- }),
- });
- } else {
- for (const databaseResource of state.databaseResources) {
- const resourceExpressions =
- getExpressionsForDatabaseResource(databaseResource);
- resourceExpressions.push(...expressions);
- maskingExceptions.push({
- member,
- action,
- maskingLevel: state.maskingLevel,
- condition: Expr.fromPartial({
- expression: resourceExpressions.join(" && "),
- }),
- });
- }
- }
- }
- }
-
- const policy = await policyStore.getOrFetchPolicyByParentAndType({
- parentPath,
- policyType: PolicyType.MASKING_EXCEPTION,
- });
- const existed = policy?.maskingExceptionPolicy?.maskingExceptions ?? [];
- return {
- name: policy?.name,
- type: PolicyType.MASKING_EXCEPTION,
- resourceType: PolicyResourceType.PROJECT,
- maskingExceptionPolicy: {
- maskingExceptions: [...existed, ...maskingExceptions],
- },
- };
-};
-
-const toggleAction = (
- action: MaskingExceptionPolicy_MaskingException_Action,
- check: boolean
-) => {
- if (check) {
- state.supportActions.add(action);
- } else {
- state.supportActions.delete(action);
- }
-};
-</script>
+</style>
diff --git a/frontend/src/components/SensitiveData/GrantAccessForm.vue b/frontend/src/components/SensitiveData/GrantAccessForm.vue
new file mode 100644
index 0000000000..84c39ad6f7
--- /dev/null
+++ b/frontend/src/components/SensitiveData/GrantAccessForm.vue
@@ -0,0 +1,278 @@
+<template>
+ <div class="space-y-6 h-full relative">
+ <div class="space-y-8 mb-8">
+ <div class="w-full">
+ <div class="flex items-center gap-x-1 mb-2">
+ <span>{{ $t("common.resources") }}</span>
+ <span class="text-red-600">*</span>
+ </div>
+ <DatabaseResourceForm
+ v-model:database-resources="state.databaseResources"
+ :project-name="projectName"
+ :required-feature="'bb.feature.sensitive-data'"
+ :include-cloumn="true"
+ />
+ </div>
+
+ <div class="w-full">
+ <div class="flex items-center gap-x-1 mb-2">
+ <span>{{ $t("settings.sensitive-data.action.self") }}</span>
+ <span class="text-red-600">*</span>
+ </div>
+ <div class="flex space-x-4">
+ <NCheckbox
+ v-for="action in ACTIONS"
+ :key="action"
+ :checked="state.supportActions.has(action)"
+ @update:checked="toggleAction(action, $event)"
+ >
+ {{
+ $t(
+ `settings.sensitive-data.action.${maskingExceptionPolicy_MaskingException_ActionToJSON(
+ action
+ ).toLowerCase()}`
+ )
+ }}
+ </NCheckbox>
+ </div>
+ </div>
+
+ <div class="w-full">
+ <div class="flex items-center gap-x-1 mb-2">
+ <span>{{ $t("settings.sensitive-data.masking-level.self") }}</span>
+ <span class="text-red-600">*</span>
+ </div>
+ <MaskingLevelRadioGroup
+ :level="state.maskingLevel"
+ :level-list="MASKING_LEVELS"
+ @update:level="state.maskingLevel = $event"
+ />
+ </div>
+
+ <div class="w-full">
+ <p class="mb-2">{{ $t("common.expiration") }}</p>
+ <NDatePicker
+ v-model:value="state.expirationTimestamp"
+ style="width: 100%"
+ type="datetime"
+ :is-date-disabled="(date: number) => date < Date.now()"
+ clearable
+ />
+ <span v-if="!state.expirationTimestamp" class="textinfolabel">{{
+ $t("settings.sensitive-data.never-expires")
+ }}</span>
+ </div>
+
+ <MembersBindingSelect
+ v-model:value="state.memberList"
+ :required="true"
+ :project-name="projectName"
+ :include-all-users="false"
+ :include-service-account="false"
+ />
+ </div>
+
+ <div class="space-y-6 w-full sticky bottom-0 bg-white">
+ <NDivider />
+ <div class="flex justify-end items-center pb-4">
+ <div class="flex items-center gap-x-3">
+ <NButton @click.prevent="onDismiss">
+ {{ $t("common.cancel") }}
+ </NButton>
+ <NButton
+ :disabled="submitDisabled || state.processing"
+ type="primary"
+ @click.prevent="onSubmit"
+ >
+ {{ $t("common.confirm") }}
+ </NButton>
+ </div>
+ </div>
+ </div>
+ </div>
+</template>
+
+<script lang="tsx" setup>
+import { isUndefined } from "lodash-es";
+import { NButton, NCheckbox, NDivider, NDatePicker } from "naive-ui";
+import { computed, reactive } from "vue";
+import { useI18n } from "vue-i18n";
+import DatabaseResourceForm from "@/components/GrantRequestPanel/DatabaseResourceForm/index.vue";
+import MembersBindingSelect from "@/components/Member/MembersBindingSelect.vue";
+import { usePolicyV1Store, pushNotification } from "@/store";
+import type { DatabaseResource } from "@/types";
+import { Expr } from "@/types/proto/google/type/expr";
+import { MaskingLevel } from "@/types/proto/v1/common";
+import type {
+ Policy,
+ MaskingExceptionPolicy_MaskingException,
+} from "@/types/proto/v1/org_policy_service";
+import {
+ PolicyType,
+ PolicyResourceType,
+ MaskingExceptionPolicy_MaskingException_Action,
+ maskingExceptionPolicy_MaskingException_ActionToJSON,
+} from "@/types/proto/v1/org_policy_service";
+import MaskingLevelRadioGroup from "./components/MaskingLevelRadioGroup.vue";
+import type { SensitiveColumn } from "./types";
+import {
+ getExpressionsForDatabaseResource,
+ convertSensitiveColumnToDatabaseResource,
+} from "./utils";
+
+const props = defineProps<{
+ columnList: SensitiveColumn[];
+ projectName: string;
+}>();
+
+const emit = defineEmits(["dismiss"]);
+
+interface LocalState {
+ memberList: string[];
+ expirationTimestamp?: number;
+ maskingLevel: MaskingLevel;
+ processing: boolean;
+ supportActions: Set<MaskingExceptionPolicy_MaskingException_Action>;
+ databaseResources?: DatabaseResource[];
+}
+
+const ACTIONS = [
+ MaskingExceptionPolicy_MaskingException_Action.EXPORT,
+ MaskingExceptionPolicy_MaskingException_Action.QUERY,
+];
+const MASKING_LEVELS = [MaskingLevel.PARTIAL, MaskingLevel.NONE];
+
+const state = reactive<LocalState>({
+ memberList: [],
+ maskingLevel: MaskingLevel.PARTIAL,
+ processing: false,
+ supportActions: new Set(ACTIONS),
+ databaseResources: props.columnList.map(
+ convertSensitiveColumnToDatabaseResource
+ ),
+});
+
+const policyStore = usePolicyV1Store();
+const { t } = useI18n();
+
+const resetState = () => {
+ state.expirationTimestamp = undefined;
+ state.maskingLevel = MaskingLevel.PARTIAL;
+ state.supportActions = new Set(ACTIONS);
+ state.memberList = [];
+ state.databaseResources = undefined;
+ state.processing = false;
+};
+
+const onDismiss = () => {
+ emit("dismiss");
+ resetState();
+};
+
+const submitDisabled = computed(() => {
+ if (state.memberList.length === 0) {
+ return true;
+ }
+ if (state.supportActions.size === 0) {
+ return true;
+ }
+ if (
+ !isUndefined(state.databaseResources) &&
+ state.databaseResources.length === 0
+ ) {
+ return true;
+ }
+ return false;
+});
+
+const onSubmit = async () => {
+ state.processing = true;
+
+ try {
+ const pendingUpdate = await getPendingUpdatePolicy(props.projectName);
+ await policyStore.upsertPolicy({
+ parentPath: props.projectName,
+ policy: pendingUpdate,
+ updateMask: ["payload"],
+ });
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("common.created"),
+ });
+ onDismiss();
+ } finally {
+ state.processing = false;
+ }
+};
+
+const getPendingUpdatePolicy = async (
+ parentPath: string
+): Promise<Partial<Policy>> => {
+ const maskingExceptions: MaskingExceptionPolicy_MaskingException[] = [];
+
+ const expressions = [];
+ if (state.expirationTimestamp) {
+ expressions.push(
+ `request.time < timestamp("${new Date(
+ state.expirationTimestamp
+ ).toISOString()}")`
+ );
+ }
+
+ for (const action of state.supportActions.values()) {
+ for (const member of state.memberList) {
+ if (!state.databaseResources) {
+ maskingExceptions.push({
+ member,
+ action,
+ maskingLevel: state.maskingLevel,
+ condition: Expr.fromPartial({
+ expression:
+ expressions.length > 0 ? expressions.join(" && ") : undefined,
+ }),
+ });
+ } else {
+ for (const databaseResource of state.databaseResources) {
+ const resourceExpressions =
+ getExpressionsForDatabaseResource(databaseResource);
+ resourceExpressions.push(...expressions);
+ maskingExceptions.push({
+ member,
+ action,
+ maskingLevel: state.maskingLevel,
+ condition: Expr.fromPartial({
+ expression: resourceExpressions.join(" && "),
+ }),
+ });
+ }
+ }
+ }
+ }
+
+ const policy = await policyStore.getOrFetchPolicyByParentAndType({
+ parentPath,
+ policyType: PolicyType.MASKING_EXCEPTION,
+ });
+ const existed = policy?.maskingExceptionPolicy?.maskingExceptions ?? [];
+ return {
+ name: policy?.name,
+ type: PolicyType.MASKING_EXCEPTION,
+ resourceType: PolicyResourceType.PROJECT,
+ maskingExceptionPolicy: {
+ maskingExceptions: [...existed, ...maskingExceptions],
+ },
+ };
+};
+
+const toggleAction = (
+ action: MaskingExceptionPolicy_MaskingException_Action,
+ check: boolean
+) => {
+ if (check) {
+ state.supportActions.add(action);
+ } else {
+ state.supportActions.delete(action);
+ }
+};
+</script>
diff --git a/frontend/src/router/dashboard/projectV1.ts b/frontend/src/router/dashboard/projectV1.ts
index 701956950c..b303ea4e0c 100644
--- a/frontend/src/router/dashboard/projectV1.ts
+++ b/frontend/src/router/dashboard/projectV1.ts
@@ -6,6 +6,7 @@ import { PROJECT_V1_ROUTE_DASHBOARD } from "./workspaceRoutes";
export const PROJECT_V1_ROUTE_DETAIL = `${PROJECT_V1_ROUTE_DASHBOARD}.detail`;
export const PROJECT_V1_ROUTE_DATABASES = `${PROJECT_V1_ROUTE_DASHBOARD}.database`;
export const PROJECT_V1_ROUTE_MASKING_ACCESS = `${PROJECT_V1_ROUTE_DASHBOARD}.masking-access`;
+export const PROJECT_V1_ROUTE_MASKING_ACCESS_CREATE = `${PROJECT_V1_ROUTE_DASHBOARD}.masking-access.create`;
export const PROJECT_V1_ROUTE_DATABASE_DETAIL = `${PROJECT_V1_ROUTE_DASHBOARD}.database.detail`;
export const PROJECT_V1_ROUTE_DATABASE_CHANGE_HISTORY_DETAIL = `${PROJECT_V1_ROUTE_DASHBOARD}.database.change-history.detail`;
export const PROJECT_V1_ROUTE_DATABASE_GROUPS = `${PROJECT_V1_ROUTE_DASHBOARD}.database-group`;
@@ -70,7 +71,6 @@ const projectV1Routes: RouteRecordRaw[] = [
},
{
path: "masking-access",
- name: PROJECT_V1_ROUTE_MASKING_ACCESS,
meta: {
overrideTitle: true,
requiredProjectPermissionList: () => [
@@ -79,9 +79,26 @@ const projectV1Routes: RouteRecordRaw[] = [
"bb.policies.get",
],
},
- component: () =>
- import("@/views/project/ProjectDatabaseMaskingAccess.vue"),
props: true,
+ children: [
+ {
+ path: "",
+ name: PROJECT_V1_ROUTE_MASKING_ACCESS,
+ component: () =>
+ import("@/views/project/ProjectDatabaseMaskingAccess.vue"),
+ props: true,
+ },
+ {
+ path: "create",
+ name: PROJECT_V1_ROUTE_MASKING_ACCESS_CREATE,
+ component: () =>
+ import("@/views/project/ProjectDatabaseMaskingAccessCreate.vue"),
+ props: true,
+ meta: {
+ requiredProjectPermissionList: () => ["bb.policies.create"],
+ },
+ },
+ ],
},
{
path: "database-groups",
diff --git a/frontend/src/views/project/ProjectDatabaseMaskingAccessCreate.vue b/frontend/src/views/project/ProjectDatabaseMaskingAccessCreate.vue
new file mode 100644
index 0000000000..c5962f5fa6
--- /dev/null
+++ b/frontend/src/views/project/ProjectDatabaseMaskingAccessCreate.vue
@@ -0,0 +1,24 @@
+<template>
+ <GrantAccessForm
+ :column-list="[]"
+ :project-name="project.name"
+ @dismiss="() => router.back()"
+ />
+</template>
+
+<script lang="tsx" setup>
+import { computed } from "vue";
+import { useRouter } from "vue-router";
+import GrantAccessForm from "@/components/SensitiveData/GrantAccessForm.vue";
+import { useProjectByName } from "@/store";
+import { projectNamePrefix } from "@/store/modules/v1/common";
+
+const props = defineProps<{
+ projectId: string;
+}>();
+
+const { project } = useProjectByName(
+ computed(() => `${projectNamePrefix}${props.projectId}`)
+);
+const router = useRouter();
+</script>