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: configure policy in project level (#12503)
ecmadao12fd83d16eec
diff --git a/frontend/src/components/EnvironmentForm/AccessControlConfigure.vue b/frontend/src/components/EnvironmentForm/AccessControlConfigure.vuenew file mode 100644index 0000000000..3273506a0a--- /dev/null+++ b/frontend/src/components/EnvironmentForm/AccessControlConfigure.vue@@ -0,0 +1,78 @@+<template>+ <div class="flex flex-col gap-y-2">+ <div class="textlabel flex items-center space-x-1">+ <label>+ {{ $t("environment.access-control.title") }}+ </label>+ <FeatureBadge feature="bb.feature.access-control" />+ </div>+ <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>+</template>++<script setup lang="ts">+import { computed } from "vue";+import { useI18n } from "vue-i18n";+import {+ hasFeature,+ pushNotification,+ usePolicyV1Store,+ useCurrentUserV1,+} from "@/store";+import {+ PolicyResourceType,+ PolicyType,+} from "@/types/proto/v1/org_policy_service";+import { hasWorkspacePermissionV2 } from "@/utils";++const props = defineProps<{+ resource: string;+ allowEdit: boolean;+}>();++const policyStore = usePolicyV1Store();+const me = useCurrentUserV1();+const { t } = useI18n();++const disableCopyDataPolicy = computed(() => {+ return policyStore.getPolicyByParentAndType({+ parentPath: props.resource,+ policyType: PolicyType.DISABLE_COPY_DATA,+ })?.disableCopyDataPolicy?.active;+});++const allowEditDisableCopyData = computed(() => {+ return (+ props.allowEdit &&+ hasWorkspacePermissionV2(me.value, "bb.policies.update") &&+ hasFeature("bb.feature.access-control")+ );+});++const upsertPolicy = async (on: boolean) => {+ await policyStore.createPolicy(props.resource, {+ 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/EnvironmentForm/Form.vue b/frontend/src/components/EnvironmentForm/Form.vueindex 7eafd31104..e4e315252a 100644--- a/frontend/src/components/EnvironmentForm/Form.vue+++ b/frontend/src/components/EnvironmentForm/Form.vue@@ -87,29 +87,11 @@:allow-edit="allowEdit"/>- <div v-if="!create" class="flex flex-col gap-y-2">- <div class="textlabel flex items-center space-x-1">- <label>- {{ $t("environment.access-control.title") }}- </label>- <FeatureBadge feature="bb.feature.access-control" />- </div>- <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>+ <AccessControlConfigure+ v-if="!create"+ :resource="environment.name"+ :allow-edit="allowEdit"+ /></template></div>@@ -156,8 +138,6 @@ import { Status } from "nice-grpc-common";import { computed, onMounted } from "vue";import { useI18n } from "vue-i18n";import {- hasFeature,- pushNotification,useEnvironmentV1List,useEnvironmentV1Store,usePolicyV1Store,@@ -193,21 +173,6 @@ const {const policyStore = usePolicyV1Store();const environmentList = useEnvironmentV1List();-const disableCopyDataPolicy = computed(() => {- const policies = policyStore.policyList.filter(- (policy) =>- policy.resourceType === PolicyResourceType.ENVIRONMENT &&- policy.type === PolicyType.DISABLE_COPY_DATA &&- policy.resourceUid === environment.value.uid &&- policy.disableCopyDataPolicy?.active- );- return policies.length > 0;-});--const allowEditDisableCopyData = computed(() => {- return hasPermission("bb.policies.update");-});-const allowArchive = computed(() => {return (hasPermission("bb.environments.delete") && environmentList.value.length > 1@@ -255,26 +220,6 @@ const validateResourceId = async (return [];};-const upsertPolicy = async (on: boolean) => {- if (!hasFeature("bb.feature.access-control")) {- state.value.missingRequiredFeature = "bb.feature.access-control";- return;- }-- await policyStore.createPolicy(environment.value.name, {- type: PolicyType.DISABLE_COPY_DATA,- resourceType: PolicyResourceType.ENVIRONMENT,- disableCopyDataPolicy: {- active: on,- },- });- pushNotification({- module: "bytebase",- style: "SUCCESS",- title: t("common.updated"),- });-};-const archiveEnvironment = () => {events.emit("archive", state.value.environment);};diff --git a/frontend/src/components/GeneralSetting/RestrictIssueCreationConfigure.vue b/frontend/src/components/GeneralSetting/RestrictIssueCreationConfigure.vuenew file mode 100644index 0000000000..7aa91db779--- /dev/null+++ b/frontend/src/components/GeneralSetting/RestrictIssueCreationConfigure.vue@@ -0,0 +1,84 @@+<template>+ <div>+ <NTooltip placement="top-start" :disabled="allowEdit">+ <template #trigger>+ <label+ class="flex items-center gap-x-2"+ :class="[allowEdit ? 'cursor-pointer' : 'cursor-not-allowed']"+ >+ <NCheckbox+ :disabled="!allowEdit"+ :checked="restrictIssueCreationForSQLReview"+ :label="+ $t(+ 'settings.general.workspace.restrict-issue-creation-for-sql-review.title'+ )+ "+ @update:checked="handleRestrictIssueCreationForSQLReviewToggle"+ />+ </label>+ </template>+ <span class="text-sm text-gray-400 -translate-y-2">+ {{ $t("settings.general.workspace.only-admin-can-edit") }}+ </span>+ </NTooltip>+ <div class="mb-3 text-sm text-gray-400">+ {{+ $t(+ "settings.general.workspace.restrict-issue-creation-for-sql-review.description"+ )+ }}+ </div>+ </div>+</template>++<script setup lang="ts">+import { NTooltip, NCheckbox } from "naive-ui";+import { computed, watchEffect } from "vue";+import { useI18n } from "vue-i18n";+import { pushNotification, usePolicyV1Store } from "@/store";+import {+ PolicyResourceType,+ PolicyType,+} from "@/types/proto/v1/org_policy_service";++const props = defineProps<{+ resource: string;+ allowEdit: boolean;+}>();++const { t } = useI18n();+const policyV1Store = usePolicyV1Store();++watchEffect(async () => {+ await policyV1Store.getOrFetchPolicyByParentAndType({+ parentPath: props.resource,+ policyType: PolicyType.RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW,+ });+});++const restrictIssueCreationForSQLReview = computed((): boolean => {+ return (+ policyV1Store.getPolicyByParentAndType({+ parentPath: props.resource,+ policyType: PolicyType.RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW,+ })?.restrictIssueCreationForSqlReviewPolicy?.disallow ?? false+ );+});++const handleRestrictIssueCreationForSQLReviewToggle = async (on: boolean) => {+ await policyV1Store.createPolicy(props.resource, {+ type: PolicyType.RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW,+ resourceType: PolicyResourceType.PROJECT,+ restrictIssueCreationForSqlReviewPolicy: {+ disallow: on,+ },+ });++ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: t("settings.general.workspace.config-updated"),+ });+};+</script>diff --git a/frontend/src/components/GeneralSetting/SecuritySetting.vue b/frontend/src/components/GeneralSetting/SecuritySetting.vueindex 9deeb3c7e6..a6b551980c 100644--- a/frontend/src/components/GeneralSetting/SecuritySetting.vue+++ b/frontend/src/components/GeneralSetting/SecuritySetting.vue@@ -82,37 +82,11 @@{{ $t("settings.general.workspace.require-2fa.description") }}</div></div>- <div class="mb-7 mt-4 lg:mt-0">- <NTooltip placement="top-start" :disabled="allowEdit">- <template #trigger>- <label- class="flex items-center gap-x-2"- :class="[allowEdit ? 'cursor-pointer' : 'cursor-not-allowed']"- >- <NCheckbox- :disabled="!allowEdit"- :checked="restrictIssueCreationForSQLReview"- :label="- $t(- 'settings.general.workspace.restrict-issue-creation-for-sql-review.title'- )- "- @update:checked="handleRestrictIssueCreationForSQLReviewToggle"- />- </label>- </template>- <span class="text-sm text-gray-400 -translate-y-2">- {{ $t("settings.general.workspace.only-admin-can-edit") }}- </span>- </NTooltip>- <div class="mb-3 text-sm text-gray-400">- {{- $t(- "settings.general.workspace.restrict-issue-creation-for-sql-review.description"- )- }}- </div>- </div>+ <RestrictIssueCreationConfigure+ class="mb-7 mt-4 lg:mt-0"+ :resource="''"+ :allow-edit="allowEdit"+ /><SignInFrequencySetting :allow-edit="allowEdit" /><MaximumRoleExpirationSetting :allow-edit="allowEdit" /><DomainRestrictionSetting :allow-edit="allowEdit" />@@ -129,20 +103,11 @@<script lang="ts" setup>import { NCheckbox } from "naive-ui";import { storeToRefs } from "pinia";-import { computed, onMounted, reactive } from "vue";+import { computed, reactive } from "vue";import { useI18n } from "vue-i18n";-import {- featureToRef,- pushNotification,- useActuatorV1Store,- usePolicyV1Store,-} from "@/store";+import { featureToRef, pushNotification, useActuatorV1Store } from "@/store";import { useSettingV1Store } from "@/store/modules/v1/setting";import type { FeatureType } from "@/types";-import {- PolicyResourceType,- PolicyType,-} from "@/types/proto/v1/org_policy_service";import DomainRestrictionSetting from "./DomainRestrictionSetting.vue";import MaximumRoleExpirationSetting from "./MaximumRoleExpirationSetting.vue";import SignInFrequencySetting from "./SignInFrequencySetting.vue";@@ -159,7 +124,6 @@ const state = reactive<LocalState>({});const { t } = useI18n();const settingV1Store = useSettingV1Store();const actuatorStore = useActuatorV1Store();-const policyV1Store = usePolicyV1Store();const { isSaaSMode } = storeToRefs(actuatorStore);const hasWatermarkFeature = featureToRef("bb.feature.branding");@@ -178,25 +142,6 @@ const disallowSignupEnabled = computed((): boolean => {const require2FAEnabled = computed((): boolean => {return settingV1Store.workspaceProfileSetting?.require2fa ?? false;});-const restrictIssueCreationForSQLReview = computed((): boolean => {- return (- policyV1Store.getPolicyByParentAndType({- parentPath: "",- policyType: PolicyType.RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW,- })?.restrictIssueCreationForSqlReviewPolicy?.disallow ?? false- );-});--onMounted(async () => {- await prepareOrgPolicy();-});--const prepareOrgPolicy = async () => {- await policyV1Store.getOrFetchPolicyByParentAndType({- parentPath: "",- policyType: PolicyType.RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW,- });-};const handleDisallowSignupToggle = async (on: boolean) => {if (!hasDisallowSignupFeature.value && on) {@@ -253,20 +198,4 @@ const handleWatermarkToggle = async (on: boolean) => {title: t("settings.general.workspace.watermark.update-success"),});};--const handleRestrictIssueCreationForSQLReviewToggle = async (on: boolean) => {- await policyV1Store.createPolicy("", {- type: PolicyType.RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW,- resourceType: PolicyResourceType.WORKSPACE,- restrictIssueCreationForSqlReviewPolicy: {- disallow: on,- },- });-- pushNotification({- module: "bytebase",- style: "SUCCESS",- title: t("settings.general.workspace.config-updated"),- });-};</script>diff --git a/frontend/src/components/Project/ProjectSecuritySettingPanel.vue b/frontend/src/components/Project/ProjectSecuritySettingPanel.vueindex a18655ed61..7b3500fbf3 100644--- a/frontend/src/components/Project/ProjectSecuritySettingPanel.vue+++ b/frontend/src/components/Project/ProjectSecuritySettingPanel.vue@@ -4,88 +4,19 @@{{ $t("settings.sidebar.security-and-policy") }}</h3><SQLReviewForResource :resource="project.name" :allow-edit="allowEdit" />- <div class="mt-2">- <NTooltip placement="top-start" :disabled="allowEdit">- <template #trigger>- <label- class="flex items-center gap-x-2"- :class="[allowEdit ? 'cursor-pointer' : 'cursor-not-allowed']"- >- <NCheckbox- :disabled="!allowEdit"- :checked="restrictIssueCreationForSQLReview"- :label="- $t(- 'settings.general.workspace.restrict-issue-creation-for-sql-review.title'- )- "- @update:checked="handleRestrictIssueCreationForSQLReviewToggle"- />- </label>- </template>- <span class="text-sm text-gray-400 -translate-y-2">- {{ $t("settings.general.workspace.only-admin-can-edit") }}- </span>- </NTooltip>- <div class="mb-3 text-sm text-gray-400">- {{- $t(- "settings.general.workspace.restrict-issue-creation-for-sql-review.description"- )- }}- </div>- </div>+ <RestrictIssueCreationConfigure+ :resource="project.name"+ :allow-edit="allowEdit"+ />+ <AccessControlConfigure :resource="project.name" :allow-edit="allowEdit" /></div></template><script setup lang="ts">-import { NTooltip, NCheckbox } from "naive-ui";-import { computed, watchEffect } from "vue";-import { useI18n } from "vue-i18n";-import { pushNotification, usePolicyV1Store } from "@/store";import type { ComposedProject } from "@/types";-import {- PolicyResourceType,- PolicyType,-} from "@/types/proto/v1/org_policy_service";-const props = defineProps<{+defineProps<{project: ComposedProject;allowEdit: boolean;}>();--const { t } = useI18n();-const policyV1Store = usePolicyV1Store();--watchEffect(async () => {- await policyV1Store.getOrFetchPolicyByParentAndType({- parentPath: props.project.name,- policyType: PolicyType.RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW,- });-});--const restrictIssueCreationForSQLReview = computed((): boolean => {- return (- policyV1Store.getPolicyByParentAndType({- parentPath: props.project.name,- policyType: PolicyType.RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW,- })?.restrictIssueCreationForSqlReviewPolicy?.disallow ?? false- );-});--const handleRestrictIssueCreationForSQLReviewToggle = async (on: boolean) => {- await policyV1Store.createPolicy(props.project.name, {- type: PolicyType.RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW,- resourceType: PolicyResourceType.PROJECT,- restrictIssueCreationForSqlReviewPolicy: {- disallow: on,- },- });-- pushNotification({- module: "bytebase",- style: "SUCCESS",- title: t("settings.general.workspace.config-updated"),- });-};</script>diff --git a/frontend/src/layouts/SQLEditorLayout.vue b/frontend/src/layouts/SQLEditorLayout.vueindex 5b4f56366e..03b907054f 100644--- a/frontend/src/layouts/SQLEditorLayout.vue+++ b/frontend/src/layouts/SQLEditorLayout.vue@@ -28,10 +28,7 @@ import {useRoleStore,useSettingV1Store,} from "@/store";-import {- PolicyResourceType,- PolicyType,-} from "@/types/proto/v1/org_policy_service";+import { PolicyResourceType } from "@/types/proto/v1/org_policy_service";import { provideSheetContext } from "@/views/sql-editor/Sheet";import { provideSQLEditorContext } from "@/views/sql-editor/context";@@ -71,7 +68,9 @@ const prepare = async () => {}),policyV1Store.fetchPolicies({resourceType: PolicyResourceType.ENVIRONMENT,- policyType: PolicyType.DISABLE_COPY_DATA,+ }),+ policyV1Store.fetchPolicies({+ resourceType: PolicyResourceType.PROJECT,}),]);ready.value = true;diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vueindex 694f7bddce..f4b0f9ca9b 100644--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue@@ -199,9 +199,18 @@ const disallowCopyingData = computed(() => {return false;}- const environment = instance.value.environment;+ if (props.database) {+ const projectLevelPolicy = policyStore.getPolicyByParentAndType({+ parentPath: props.database?.project,+ policyType: PolicyType.DISABLE_COPY_DATA,+ });+ if (projectLevelPolicy?.disableCopyDataPolicy?.active) {+ return true;+ }+ }+const policy = policyStore.getPolicyByParentAndType({- parentPath: environment,+ parentPath: instance.value.environment,policyType: PolicyType.DISABLE_COPY_DATA,});if (policy?.disableCopyDataPolicy?.active) {