Skip to content

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

chore: retire workspace access control setting (#11125)

boojacke16cffb0716a
diff --git a/frontend/src/components/EnvironmentForm.vue b/frontend/src/components/EnvironmentForm.vue
index 5d93452af5..727ddac778 100644
--- a/frontend/src/components/EnvironmentForm.vue
+++ b/frontend/src/components/EnvironmentForm.vue
@@ -154,13 +154,11 @@
:text="true"
@update:value="toggleSQLReviewPolicy"
/>
- <NButton
- quaternary
- type="primary"
+ <span
+ class="textlabel normal-link !text-accent"
@click="onSQLReviewPolicyClick"
+ >{{ sqlReviewPolicy.name }}</span
>
- {{ sqlReviewPolicy.name }}
- </NButton>
</div>
<NButton
v-else-if="hasPermission('bb.policies.update')"
@@ -173,6 +171,27 @@
</span>
</div>
</div>
+
+ <div v-if="!create" class="flex flex-col gap-y-2">
+ <label class="textlabel">
+ {{ $t("environment.access-control.title") }}
+ </label>
+ <div>
+ <div class="inline-flex items-center gap-x-2">
+ <Switch
+ :value="disableCopyDataPolicy"
+ :text="true"
+ :disabled="!allowEditDisableCopyData"
+ @update:value="upsertPolicy"
+ />
+ <span class="textlabel">{{
+ $t(
+ "environment.access-control.disable-copy-data-from-sql-editor"
+ )
+ }}</span>
+ </div>
+ </div>
+ </div>
</div>
<div v-if="!create" class="mt-6 flex justify-between items-center pt-5">
@@ -251,7 +270,7 @@ import { computedAsync, useEventListener } from "@vueuse/core";
import { cloneDeep, isEqual, isEmpty } from "lodash-es";
import { NButton, NCheckbox, NInput, NRadioGroup } from "naive-ui";
import { Status } from "nice-grpc-common";
-import { computed, reactive, PropType, watch, ref } from "vue";
+import { computed, reactive, PropType, watch, ref, onMounted } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter, onBeforeRouteLeave } from "vue-router";
import { DrawerContent, Switch } from "@/components/v2";
@@ -264,6 +283,7 @@ import {
pushNotification,
useCurrentUserV1,
useEnvironmentV1List,
+ usePolicyV1Store,
useSQLReviewStore,
} from "@/store";
import { environmentNamePrefix } from "@/store/modules/v1/common";
@@ -282,6 +302,7 @@ import {
Policy,
PolicyType,
BackupPlanSchedule,
+ PolicyResourceType,
} from "@/types/proto/v1/org_policy_service";
import {
extractEnvironmentResourceName,
@@ -333,6 +354,7 @@ const emit = defineEmits([
const { t } = useI18n();
const router = useRouter();
const currentUserV1 = useCurrentUserV1();
+const policyStore = usePolicyV1Store();
const environmentV1Store = useEnvironmentV1Store();
const environmentList = useEnvironmentV1List();
const sqlReviewStore = useSQLReviewStore();
@@ -365,6 +387,17 @@ const sqlReviewPolicy = computedAsync(() => {
);
}, undefined);
+const disableCopyDataPolicy = computed(() => {
+ const policies = policyStore.policyList.filter(
+ (policy) =>
+ policy.resourceType === PolicyResourceType.ENVIRONMENT &&
+ policy.type === PolicyType.DISABLE_COPY_DATA &&
+ policy.resourceUid === (props.environment as Environment).uid &&
+ policy.disableCopyDataPolicy?.active
+ );
+ return policies.length > 0;
+});
+
const onSQLReviewPolicyClick = () => {
if (sqlReviewPolicy.value) {
router.push({
@@ -383,6 +416,17 @@ const onSQLReviewPolicyClick = () => {
}
};
+const prepareEnvironmentDisableCopyDataPolicy = async () => {
+ await policyStore.fetchPolicies({
+ resourceType: PolicyResourceType.ENVIRONMENT,
+ policyType: PolicyType.DISABLE_COPY_DATA,
+ });
+};
+
+onMounted(() => {
+ prepareEnvironmentDisableCopyDataPolicy();
+});
+
watch(
() => props.environment,
(cur) => {
@@ -463,6 +507,10 @@ const allowEdit = computed(() => {
);
});
+const allowEditDisableCopyData = computed(() => {
+ return hasWorkspacePermissionV2(currentUserV1.value, "bb.policies.update");
+});
+
const allowCreate = computed(() => {
return (
!isEmpty(state.environment?.title) &&
@@ -595,4 +643,19 @@ const toggleSQLReviewPolicy = async (on: boolean) => {
title: t("sql-review.policy-updated"),
});
};
+
+const upsertPolicy = async (on: boolean) => {
+ await policyStore.createPolicy(props.environment.name, {
+ type: PolicyType.DISABLE_COPY_DATA,
+ resourceType: PolicyResourceType.ENVIRONMENT,
+ disableCopyDataPolicy: {
+ active: on,
+ },
+ });
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("common.updated"),
+ });
+};
</script>
diff --git a/frontend/src/components/v2/Form/Switch.vue b/frontend/src/components/v2/Form/Switch.vue
index 966d02e1e0..abf11b611c 100644
--- a/frontend/src/components/v2/Form/Switch.vue
+++ b/frontend/src/components/v2/Form/Switch.vue
@@ -7,6 +7,7 @@
calc(var(--n-rail-width) + var(--n-button-width) - var(--n-rail-height))
);
"
+ v-bind="$attrs"
>
<template v-if="text" #checked>
<span style="font-size: 10px">{{ $t("common.on") }}</span>
diff --git a/frontend/src/components/v2/Model/EnvironmentV1Name.vue b/frontend/src/components/v2/Model/EnvironmentV1Name.vue
index 6169a24c8d..e67325b9d4 100644
--- a/frontend/src/components/v2/Model/EnvironmentV1Name.vue
+++ b/frontend/src/components/v2/Model/EnvironmentV1Name.vue
@@ -5,7 +5,7 @@
class="inline-flex items-center gap-x-1"
:class="[link && !plain && 'normal-link', link && 'hover:underline']"
>
- <span class="line-clamp-1" :class="textClass">
+ <span class="line-clamp-1 select-none" :class="textClass">
{{ prefix }}
{{ environmentV1Name(environment) }}
{{ suffix }}
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 657f1266cf..5bd40aa1e0 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1406,7 +1406,11 @@
"self": "Disable database automatic backup",
"content": "Disabling automatic backup policy is not applied retroactively.\nAre you sure about applying to all databases in this environment?"
},
- "production-environment": "Production environment"
+ "production-environment": "Production environment",
+ "access-control": {
+ "title": "Access control",
+ "disable-copy-data-from-sql-editor": "Disable copy data from SQL editor"
+ }
},
"quick-start": {
"self": "Quickstart",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 7d7c83ba86..d998bc1b8c 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -1406,7 +1406,11 @@
"self": "Desactivar copia de seguridad automática de la base de datos",
"content": "La política de desactivación de copias de seguridad automáticas no se aplica de forma retroactiva.\n¿Está seguro de aplicarla a todas las bases de datos en este entorno?"
},
- "production-environment": "Entorno de producción"
+ "production-environment": "Entorno de producción",
+ "access-control": {
+ "title": "Control de acceso",
+ "disable-copy-data-from-sql-editor": "Desactivar copiar datos desde el editor SQL"
+ }
},
"quick-start": {
"self": "Inicio rápido",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index bca1febcbe..0c9e1d5d0c 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -1406,7 +1406,11 @@
"self": "データベースの自動バックアップを無効にする",
"content": "自動バックアップポリシーの無効化は過去に適用されません。\nこの環境のすべてのデータベースに適用することを確認していますか?"
},
- "production-environment": "本番環境"
+ "production-environment": "本番環境",
+ "access-control": {
+ "title": "アクセス制御",
+ "disable-copy-data-from-sql-editor": "SQLエディターからのデータコピーを無効にする"
+ }
},
"quick-start": {
"self": "クイックスタート",
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 26290a6e78..821b5ae469 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -1406,7 +1406,11 @@
"self": "Vô hiệu hóa sao lưu tự động cơ sở dữ liệu",
"content": "Việc tắt chính sách sao lưu tự động không được áp dụng trở về trước.\nBạn có chắc chắn về việc áp dụng cho tất cả cơ sở dữ liệu trong môi trường này không?"
},
- "production-environment": "Môi trường sản xuất"
+ "production-environment": "Môi trường sản xuất",
+ "access-control": {
+ "title": "Kiểm soát truy cập",
+ "disable-copy-data-from-sql-editor": "Vô hiệu hóa sao chép dữ liệu từ trình chỉnh sửa SQL"
+ }
},
"quick-start": {
"self": "Bắt đầu nhanh",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 29ff90f759..1d32d75e7f 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1406,7 +1406,11 @@
"self": "禁用数据库自动备份",
"content": "禁用自动备份策略仅对新添加的数据库生效。\n是否要将该设置应用到当前环境下的所有数据库?"
},
- "production-environment": "生产环境"
+ "production-environment": "生产环境",
+ "access-control": {
+ "title": "访问控制",
+ "disable-copy-data-from-sql-editor": "禁止从 SQL 编辑器复制数据"
+ }
},
"quick-start": {
"self": "新手任务",
diff --git a/frontend/src/router/dashboard/workspaceSetting.ts b/frontend/src/router/dashboard/workspaceSetting.ts
index 4ef6978a51..d1b605d3cf 100644
--- a/frontend/src/router/dashboard/workspaceSetting.ts
+++ b/frontend/src/router/dashboard/workspaceSetting.ts
@@ -20,7 +20,6 @@ export const SETTING_ROUTE_WORKSPACE_SSO = `${SETTING_ROUTE_WORKSPACE}.sso`;
export const SETTING_ROUTE_WORKSPACE_SSO_CREATE = `${SETTING_ROUTE_WORKSPACE_SSO}.create`;
export const SETTING_ROUTE_WORKSPACE_SSO_DETAIL = `${SETTING_ROUTE_WORKSPACE_SSO}.detail`;
export const SETTING_ROUTE_WORKSPACE_SENSITIVE_DATA = `${SETTING_ROUTE_WORKSPACE}.sensitive-data`;
-export const SETTING_ROUTE_WORKSPACE_ACCESS_CONTROL = `${SETTING_ROUTE_WORKSPACE}.access-control`;
export const SETTING_ROUTE_WORKSPACE_RISK_CENTER = `${SETTING_ROUTE_WORKSPACE}.risk-center`;
export const SETTING_ROUTE_WORKSPACE_CUSTOM_APPROVAL = `${SETTING_ROUTE_WORKSPACE}.custom-approval`;
export const SETTING_ROUTE_WORKSPACE_SLOW_QUERY = `${SETTING_ROUTE_WORKSPACE}.slow-query`;
@@ -141,16 +140,6 @@ const workspaceSettingRoutes: RouteRecordRaw[] = [
component: () => import("@/views/SettingWorkspaceSensitiveData.vue"),
props: true,
},
- {
- path: "access-control",
- name: SETTING_ROUTE_WORKSPACE_ACCESS_CONTROL,
- meta: {
- title: () => t("settings.sidebar.access-control"),
- requiredWorkspacePermissionList: () => ["bb.policies.get"],
- },
- component: () => import("@/views/SettingWorkspaceAccessControl.vue"),
- props: true,
- },
{
path: "risk-center",
name: SETTING_ROUTE_WORKSPACE_RISK_CENTER,
diff --git a/frontend/src/views/SettingSidebar.vue b/frontend/src/views/SettingSidebar.vue
index 6bf4657cd3..e837d11049 100644
--- a/frontend/src/views/SettingSidebar.vue
+++ b/frontend/src/views/SettingSidebar.vue
@@ -35,7 +35,6 @@ import workspaceSettingRoutes, {
SETTING_ROUTE_WORKSPACE_RISK_CENTER,
SETTING_ROUTE_WORKSPACE_CUSTOM_APPROVAL,
SETTING_ROUTE_WORKSPACE_SENSITIVE_DATA,
- SETTING_ROUTE_WORKSPACE_ACCESS_CONTROL,
SETTING_ROUTE_WORKSPACE_AUDIT_LOG,
SETTING_ROUTE_WORKSPACE_GITOPS,
SETTING_ROUTE_WORKSPACE_GITOPS_CREATE,
@@ -189,11 +188,6 @@ const settingSidebarItemList = computed((): SidebarItem[] => {
name: SETTING_ROUTE_WORKSPACE_SENSITIVE_DATA,
type: "route",
},
- {
- title: t("settings.sidebar.access-control"),
- name: SETTING_ROUTE_WORKSPACE_ACCESS_CONTROL,
- type: "route",
- },
{
title: t("settings.sidebar.audit-log"),
name: SETTING_ROUTE_WORKSPACE_AUDIT_LOG,
diff --git a/frontend/src/views/SettingWorkspaceAccessControl.vue b/frontend/src/views/SettingWorkspaceAccessControl.vue
deleted file mode 100644
index cccdbfe659..0000000000
--- a/frontend/src/views/SettingWorkspaceAccessControl.vue
+++ /dev/null
@@ -1,331 +0,0 @@
-<template>
- <div class="w-full space-y-4">
- <FeatureAttention
- v-if="!hasDataAccessControlFeature"
- feature="bb.feature.access-control"
- />
- <div class="flex justify-between">
- <i18n-t
- tag="div"
- keypath="settings.access-control.description"
- class="textinfolabel"
- >
- <template #link>
- <LearnMoreLink
- url="https://www.bytebase.com/docs/security/data-access-control"
- />
- </template>
- </i18n-t>
- </div>
-
- <div class="relative">
- <BBTable
- :column-list="COLUMN_LIST"
- :data-source="state.environmentPolicyList"
- :show-header="true"
- :left-bordered="true"
- :right-bordered="true"
- :row-clickable="false"
- >
- <template #body="{ rowData: policy }: { rowData: EnvironmentPolicy }">
- <BBTableCell>
- <EnvironmentV1Name
- class="pl-2"
- :environment="policy.environment"
- :link="false"
- />
- </BBTableCell>
- <BBTableCell>
- <NCheckbox
- v-model:checked="policy.allowQueryData"
- :disabled="!allowAdmin"
- >
- {{ $t("settings.access-control.skip-approval") }}
- </NCheckbox>
- </BBTableCell>
- <BBTableCell>
- <NCheckbox
- v-model:checked="policy.allowExportData"
- :disabled="!allowAdmin"
- >
- {{ $t("settings.access-control.skip-approval") }}
- </NCheckbox>
- </BBTableCell>
- <BBTableCell>
- <NCheckbox
- v-model:checked="policy.disallowCopyingDataFromSQLEditor"
- :disabled="!allowAdmin"
- >
- {{ $t("settings.access-control.disallowed") }}
- </NCheckbox>
- </BBTableCell>
- </template>
- </BBTable>
-
- <div
- v-if="state.isLoading"
- class="absolute w-full h-full inset-0 z-1 bg-white/50 flex flex-col items-center justify-center"
- >
- <BBSpin />
- </div>
-
- <div
- v-if="!hasDataAccessControlFeature"
- class="absolute w-full h-full inset-0 z-10 bg-gray-300/80 flex flex-col items-center justify-center"
- >
- <UpgradeSubscriptionButton />
- </div>
- </div>
- </div>
-
- <FeatureModal
- feature="bb.feature.access-control"
- :open="state.showFeatureModal"
- @cancel="state.showFeatureModal = false"
- />
-</template>
-
-<script lang="ts" setup>
-import { useDebounceFn } from "@vueuse/core";
-import { NCheckbox } from "naive-ui";
-import { computed, reactive, watch, onMounted } from "vue";
-import { useI18n } from "vue-i18n";
-import { BBTableColumn } from "@/bbkit/types";
-import UpgradeSubscriptionButton from "@/components/UpgradeSubscriptionButton.vue";
-import { EnvironmentV1Name } from "@/components/v2";
-import { resolveCELExpr } from "@/plugins/cel";
-import {
- featureToRef,
- pushNotification,
- useCurrentUserV1,
- useEnvironmentV1List,
-} from "@/store";
-import { usePolicyV1Store } from "@/store/modules/v1/policy";
-import { ALL_USERS_USER_EMAIL, PresetRoleType } from "@/types";
-import { Environment } from "@/types/proto/v1/environment_service";
-import { Binding, IamPolicy } from "@/types/proto/v1/iam_policy";
-import {
- PolicyResourceType,
- PolicyType,
-} from "@/types/proto/v1/org_policy_service";
-import { hasWorkspacePermissionV2 } from "@/utils";
-
-interface EnvironmentPolicy {
- environment: Environment;
- allowQueryData: boolean;
- allowExportData: boolean;
- disallowCopyingDataFromSQLEditor: boolean;
-}
-
-interface LocalState {
- showFeatureModal: boolean;
- isLoading: boolean;
- environmentPolicyList: EnvironmentPolicy[];
-}
-
-const { t } = useI18n();
-const environmentList = useEnvironmentV1List();
-const policyStore = usePolicyV1Store();
-const currentUserV1 = useCurrentUserV1();
-const hasDataAccessControlFeature = featureToRef("bb.feature.access-control");
-const state = reactive<LocalState>({
- showFeatureModal: false,
- isLoading: true,
- environmentPolicyList: environmentList.value.map((environment) => {
- const defaultValue = false;
- return {
- environment,
- allowQueryData: defaultValue,
- allowExportData: defaultValue,
- disallowCopyingDataFromSQLEditor: defaultValue,
- };
- }),
-});
-
-const allowAdmin = computed(() => {
- return hasWorkspacePermissionV2(currentUserV1.value, "bb.policies.update");
-});
-
-const COLUMN_LIST = computed((): BBTableColumn[] => [
- {
- title: t("common.environment"),
- },
- {
- title: t("settings.access-control.query-data"),
- },
- {
- title: t("settings.access-control.export-data"),
- },
- {
- title: t("settings.access-control.copy-data-from-sql-editor"),
- },
-]);
-
-onMounted(async () => {
- if (!hasDataAccessControlFeature.value) {
- state.isLoading = false;
- return;
- }
-
- const processWorkspaceIAMPolicy = async () => {
- const policy = await policyStore.getOrFetchPolicyByName(
- "policies/WORKSPACE_IAM"
- );
- if (!policy || !policy.workspaceIamPolicy) {
- return;
- }
-
- for (const binding of policy.workspaceIamPolicy.bindings) {
- if (!binding.members.includes(ALL_USERS_USER_EMAIL)) {
- continue;
- }
-
- if (binding.parsedExpr?.expr) {
- const simpleExpr = resolveCELExpr(binding.parsedExpr.expr);
- const args = simpleExpr.args;
- if (
- simpleExpr.operator !== "@in" ||
- args[0] !== "resource.environment_name"
- ) {
- continue;
- }
-
- const environmentNameList = args[1] as string[];
- for (const environmentPolicy of state.environmentPolicyList) {
- if (
- environmentNameList.includes(environmentPolicy.environment.name)
- ) {
- if (binding.role === PresetRoleType.PROJECT_QUERIER) {
- environmentPolicy.allowQueryData = true;
- } else if (binding.role === PresetRoleType.PROJECT_EXPORTER) {
- environmentPolicy.allowExportData = true;
- }
- }
- }
- }
- }
- };
- const processEnvironmentDisableCopyDataPolicy = async () => {
- const policyList = await policyStore.fetchPolicies({
- resourceType: PolicyResourceType.ENVIRONMENT,
- policyType: PolicyType.DISABLE_COPY_DATA,
- });
- policyList.forEach((policy) => {
- if (policy.disableCopyDataPolicy?.active) {
- const environmentPolicy = state.environmentPolicyList.find(
- (ep) => ep.environment.uid === policy.resourceUid
- );
- if (environmentPolicy) {
- environmentPolicy.disallowCopyingDataFromSQLEditor = true;
- }
- }
- });
- };
-
- try {
- await Promise.allSettled([
- processWorkspaceIAMPolicy(),
- processEnvironmentDisableCopyDataPolicy(),
- ]);
- state.isLoading = true;
- } finally {
- state.isLoading = false;
- }
-});
-
-const buildWorkspaceIAMPolicy = (envPolicyList: EnvironmentPolicy[]) => {
- const workspaceIamPolicy: IamPolicy = IamPolicy.fromPartial({});
-
- const allowQueryEnvNameList: string[] = envPolicyList
- .filter((item) => item.allowQueryData)
- .map((item) => item.environment.name);
- const allowExportEnvNameList: string[] = envPolicyList
- .filter((item) => item.allowExportData)
- .map((item) => item.environment.name);
- if (allowQueryEnvNameList.length > 0) {
- workspaceIamPolicy.bindings.push(
- Binding.fromPartial({
- role: PresetRoleType.PROJECT_QUERIER,
- members: [ALL_USERS_USER_EMAIL],
- condition: {
- expression: `resource.environment_name in ["${allowQueryEnvNameList.join(
- '", "'
- )}"]`,
- },
- })
- );
- }
- if (allowExportEnvNameList.length > 0) {
- workspaceIamPolicy.bindings.push(
- Binding.fromPartial({
- role: PresetRoleType.PROJECT_EXPORTER,
- members: [ALL_USERS_USER_EMAIL],
- condition: {
- expression: `resource.environment_name in ["${allowExportEnvNameList.join(
- '", "'
- )}"]`,
- },
- })
- );
- }
- return workspaceIamPolicy;
-};
-
-const upsertPolicy = useDebounceFn(async () => {
- if (!hasDataAccessControlFeature.value) {
- state.showFeatureModal = true;
- return;
- }
-
- if (!allowAdmin.value) {
- return;
- }
-
- const upsertWorkspaceIAMPolicy = async () => {
- await policyStore.createPolicy("", {
- type: PolicyType.WORKSPACE_IAM,
- resourceType: PolicyResourceType.WORKSPACE,
- resourceUid: "1",
- workspaceIamPolicy: buildWorkspaceIAMPolicy(state.environmentPolicyList),
- });
- };
-
- const upsertEnvironmentDisableCopyDataPolicy = async () => {
- for (let i = 0; i < state.environmentPolicyList.length; i++) {
- const environmentPolicy = state.environmentPolicyList[i];
- await policyStore.createPolicy(environmentPolicy.environment.name, {
- type: PolicyType.DISABLE_COPY_DATA,
- resourceType: PolicyResourceType.ENVIRONMENT,
- disableCopyDataPolicy: {
- active: environmentPolicy.disallowCopyingDataFromSQLEditor,
- },
- });
- }
- };
-
- await Promise.allSettled([
- upsertWorkspaceIAMPolicy(),
- upsertEnvironmentDisableCopyDataPolicy(),
- ]);
-
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("common.updated"),
- });
-}, 200);
-
-watch(
- () => state.environmentPolicyList,
- async () => {
- if (state.isLoading) {
- return;
- }
-
- await upsertPolicy();
- },
- {
- deep: true,
- }
-);
-</script>