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 exec ddl/dml environment policy (#14029)
ecmadaoe7b272bd8b90
diff --git a/backend/api/v1/org_policy_service.go b/backend/api/v1/org_policy_service.goindex 66f14aeb5e..569c3df164 100644--- a/backend/api/v1/org_policy_service.go+++ b/backend/api/v1/org_policy_service.go@@ -1080,9 +1080,12 @@ func convertToV1PBDataSourceQueryPolicy(payloadStr string) (*v1pb.Policy_DataSouif err := common.ProtojsonUnmarshaler.Unmarshal([]byte(payloadStr), payload); err != nil {return nil, err}+return &v1pb.Policy_DataSourceQueryPolicy{DataSourceQueryPolicy: &v1pb.DataSourceQueryPolicy{AdminDataSourceRestriction: v1pb.DataSourceQueryPolicy_Restriction(payload.AdminDataSourceRestriction),+ EnableDdl: payload.EnableDdl,+ EnableDml: payload.EnableDml,},}, nil}@@ -1090,6 +1093,8 @@ func convertToV1PBDataSourceQueryPolicy(payloadStr string) (*v1pb.Policy_DataSoufunc convertToDataSourceQueryPayload(policy *v1pb.DataSourceQueryPolicy) (*storepb.DataSourceQueryPolicy, error) {return &storepb.DataSourceQueryPolicy{AdminDataSourceRestriction: storepb.DataSourceQueryPolicy_Restriction(policy.AdminDataSourceRestriction),+ EnableDdl: policy.EnableDdl,+ EnableDml: policy.EnableDml,}, nil}diff --git a/frontend/src/components/EnvironmentForm/AccessControlConfigure.vue b/frontend/src/components/EnvironmentForm/AccessControlConfigure.vueindex e0cbf4504d..58251a43bb 100644--- a/frontend/src/components/EnvironmentForm/AccessControlConfigure.vue+++ b/frontend/src/components/EnvironmentForm/AccessControlConfigure.vue@@ -11,7 +11,7 @@<Switch:value="disableCopyDataPolicy":text="true"- :disabled="!allowUpdatePolicy"+ :disabled="!allowUpdatePolicy || !hasAccessControlFeature"@update:value="updateDisableCopyDataPolicy"/><span class="textlabel">{{@@ -23,7 +23,7 @@<Switch:value="adminDataSourceQueruRestrictionEnabled":text="true"- :disabled="!allowUpdatePolicy"+ :disabled="!allowUpdatePolicy || !hasAccessControlFeature"@update:value="switchDataSourceQueryPolicyEnabled"/><span class="textlabel">{{@@ -33,7 +33,7 @@<div v-if="adminDataSourceQueruRestrictionEnabled" class="ml-12"><NRadioGroup:value="adminDataSourceQueruRestriction"- :disabled="!allowUpdatePolicy"+ :disabled="!allowUpdatePolicy || !hasAccessControlFeature"@update:value="updateAdminDataSourceQueryRestrctionPolicy"><NRadio@@ -61,6 +61,43 @@</div></div></div>+ <div v-if="isDev()" class="flex flex-col gap-y-2">+ <div class="textlabel flex items-center space-x-2">+ <label> Statement execution </label>+ </div>+ <div>+ <div class="w-full inline-flex items-center gap-x-2">+ <Switch+ :value="dataSourceQueryPolicy?.enableDdl"+ :text="true"+ :disabled="!allowUpdatePolicy"+ @update:value="+ (on: boolean) => {+ updateAdminDataSourceQueryRestrctionPolicy({ enableDdl: on });+ }+ "+ />+ <span class="textlabel">+ Allow running DDL statements in the SQL editor+ </span>+ </div>+ <div class="w-full inline-flex items-center gap-x-2">+ <Switch+ :value="dataSourceQueryPolicy?.enableDml"+ :text="true"+ :disabled="!allowUpdatePolicy"+ @update:value="+ (on: boolean) => {+ updateAdminDataSourceQueryRestrctionPolicy({ enableDml: on });+ }+ "+ />+ <span class="textlabel">+ Allow running DML statements in the SQL editor+ </span>+ </div>+ </div>+ </div></template><script setup lang="ts">@@ -73,7 +110,7 @@ import {DataSourceQueryPolicy_Restriction,PolicyType,} from "@/types/proto/v1/org_policy_service";-import { hasWorkspacePermissionV2 } from "@/utils";+import { hasWorkspacePermissionV2, isDev } from "@/utils";import { FeatureBadge } from "../FeatureGuard";import { Switch } from "../v2";@@ -126,12 +163,12 @@ const adminDataSourceQueruRestrictionEnabled = computed(() => {);});+const hasAccessControlFeature = computed(() =>+ hasFeature("bb.feature.access-control")+);+const allowUpdatePolicy = computed(() => {- return (- props.allowEdit &&- hasWorkspacePermissionV2("bb.policies.update") &&- hasFeature("bb.feature.access-control")- );+ return props.allowEdit && hasWorkspacePermissionV2("bb.policies.update");});const updateDisableCopyDataPolicy = async (on: boolean) => {@@ -149,25 +186,26 @@ const updateDisableCopyDataPolicy = async (on: boolean) => {};const switchDataSourceQueryPolicyEnabled = async (on: boolean) => {- await updateAdminDataSourceQueryRestrctionPolicy(- on+ await updateAdminDataSourceQueryRestrctionPolicy({+ adminDataSourceRestriction: on? DataSourceQueryPolicy_Restriction.DISALLOW- : DataSourceQueryPolicy_Restriction.RESTRICTION_UNSPECIFIED- );+ : DataSourceQueryPolicy_Restriction.RESTRICTION_UNSPECIFIED,+ });};const updateAdminDataSourceQueryRestrctionPolicy = async (- restrction: DataSourceQueryPolicy_Restriction+ policy: Partial<DataSourceQueryPolicy>) => {await policyStore.upsertPolicy({parentPath: props.resource,policy: {type: PolicyType.DATA_SOURCE_QUERY,dataSourceQueryPolicy: DataSourceQueryPolicy.fromPartial({- adminDataSourceRestriction: restrction,+ ...(dataSourceQueryPolicy.value ?? {}),+ ...policy,}),},- updateMask: [],+ updateMask: ["payload"],});pushNotification({module: "bytebase",diff --git a/frontend/src/composables/useExecuteSQL.ts b/frontend/src/composables/useExecuteSQL.tsindex 0edfef2b61..4b92bad575 100644--- a/frontend/src/composables/useExecuteSQL.ts+++ b/frontend/src/composables/useExecuteSQL.ts@@ -13,6 +13,7 @@ import {useSQLStore,useSQLEditorQueryHistoryStore,useAppFeature,+ usePolicyV1Store,} from "@/store";import type {ComposedDatabase,@@ -22,6 +23,7 @@ import type {SQLEditorTab,} from "@/types";import { isValidDatabaseName } from "@/types";+import { PolicyType } from "@/types/proto/v1/org_policy_service";import {Advice,Advice_Status,@@ -56,7 +58,9 @@ const useExecuteSQL = () => {const databaseStore = useDatabaseV1Store();const tabStore = useSQLEditorTabStore();const sqlEditorStore = useSQLEditorStore();+ const policyStore = usePolicyV1Store();const sqlCheckStyle = useAppFeature("bb.feature.sql-editor.sql-check-style");+const changeMode =useAppFeature("bb.feature.database-change-mode").value === "EDITOR"? "RW"@@ -307,9 +311,18 @@ const useExecuteSQL = () => {continue;}+ const policy = await policyStore.getOrFetchPolicyByParentAndType({+ parentPath: database.effectiveEnvironment,+ policyType: PolicyType.DATA_SOURCE_QUERY,+ });+try {let resultSet: SQLResultSetV1;- if (changeMode === "RO") {+ if (+ changeMode === "RO" &&+ !policy?.dataSourceQueryPolicy?.enableDdl &&+ !policy?.dataSourceQueryPolicy?.enableDml+ ) {const instance = isValidDatabaseName(database.name)? database.instance: params.connection.instance;@@ -358,10 +371,12 @@ const useExecuteSQL = () => {const database = databaseStore.getDatabaseByName(params.connection.database);+// Show a tips to navigate to issue creation// if the user is allowed to create issue in the project.if (hasPermissionToCreateChangeDatabaseIssue(database)) {sqlEditorStore.isShowExecutingHint = true;+ sqlEditorStore.executingHintDatabase = database;cleanup();}fail(database, resultSet);diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 1a548c63f3..24ff68f994 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -2370,6 +2370,7 @@"no-data-available": "No data available","download-as-file": "Download as {file}","only-select-allowed": "Only {select} statements are allowed to execute.",+ "enable-ddl-for-environment": "You can enable the DDL/DML statement for the environment {environment}.","want-to-action": "If you want to {want}, click the {action} button {reaction}.","and-submit-an-issue": "and submit an issue","to-enable-admin-mode": "to enable the admin mode",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 1683f6527a..3d1c63faa9 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -2370,6 +2370,7 @@"no-data-available": "No hay datos disponibles","download-as-file": "Descargar como {file}","only-select-allowed": "Solo se permiten declaraciones {select} para ejecutar.",+ "enable-ddl-for-environment": "Puede habilitar la declaración DDL/DML para el entorno {environment}.","want-to-action": "Si desea {want}, haga clic en el botón {action} {reaction}.","and-submit-an-issue": "y enviar un problema","to-enable-admin-mode": "para habilitar el modo administrador",diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex c55813d40c..5c2b91991e 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -2370,6 +2370,7 @@"no-data-available": "データなし","download-as-file": "{file} 形式でダウンロード","only-select-allowed": "{select} ステートメントのみが実行を許可されます",+ "enable-ddl-for-environment": "環境 {environment} に対して DDL/DML ステートメントを有効にすることができます。","want-to-action": "{want} が必要な場合は、「{action}」ボタン {reaction} をクリックしてください。","and-submit-an-issue": "そしてチケットを提出してください","to-enable-admin-mode": "管理者モードを有効にするには",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 687970a5d7..481099ee90 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -2370,6 +2370,7 @@"no-data-available": "暂无数据","download-as-file": "下载为 {file} 格式","only-select-allowed": "只允许执行 {select} 语句",+ "enable-ddl-for-environment": "您可以为环境 {environment} 启用 DDL/DML 语句。","want-to-action": "如果您想要{want},点击“{action}”按钮{reaction}。","and-submit-an-issue": "并提交一个工单","to-enable-admin-mode": "来开启管理员模式",diff --git a/frontend/src/store/modules/sqlEditor/editor.ts b/frontend/src/store/modules/sqlEditor/editor.tsindex d3e8bc12a9..2fe2a3d489 100644--- a/frontend/src/store/modules/sqlEditor/editor.ts+++ b/frontend/src/store/modules/sqlEditor/editor.ts@@ -34,6 +34,7 @@ export const useSQLEditorStore = defineStore("sqlEditor", () => {});const isShowExecutingHint = ref(false);+ const executingHintDatabase = ref<ComposedDatabase | undefined>();return {resultRowsLimit,@@ -44,5 +45,6 @@ export const useSQLEditorStore = defineStore("sqlEditor", () => {allowViewALLProjects,databaseList,isShowExecutingHint,+ executingHintDatabase,};});diff --git a/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue b/frontend/src/views/SettingWorkspaceSQLReviewDetail.vueindex b5874c8aa0..f12bb2cdec 100644--- a/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue+++ b/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue@@ -17,7 +17,7 @@class="flex flex-col gap-y-2 items-start md:items-center gap-x-2 justify-center md:flex-row"><BBTextField- class="flex-1 !text-xl md:!text-2xl py-0.5 px-0.5 font-bold truncate"+ class="flex-1 !text-xl md:!text-2xl py-0.5 !pl-0 px-0.5 font-bold truncate sql-review-title":disabled="!hasPermission":required="true":focus-on-mount="false"@@ -365,3 +365,9 @@ const onRemove = () => {useTitle(computed(() => reviewPolicy.value.name));</script>++<style lang="postcss" scoped>+.sql-review-title :deep(.n-input-wrapper) {+ padding-left: 0.3rem !important;+}+</style>diff --git a/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue b/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vueindex eaa08d9277..43b1c48a4a 100644--- a/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue+++ b/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue@@ -12,6 +12,15 @@</template></i18n-t></p>+ <p v-if="database">+ <i18n-t keypath="sql-editor.enable-ddl-for-environment">+ <template #environment>+ <EnvironmentV1Name+ :environment="database.effectiveEnvironmentEntity"+ />+ </template>+ </i18n-t>+ </p><p v-if="descriptions.action && descriptions.reaction"><i18n-t keypath="sql-editor.want-to-action"><template #want>@@ -60,6 +69,7 @@ import { computed } from "vue";import { useI18n } from "vue-i18n";import { useRouter } from "vue-router";import { parseSQL, isDDLStatement } from "@/components/MonacoEditor/sqlParser";+import { EnvironmentV1Name } from "@/components/v2";import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";import {pushNotification,@@ -67,9 +77,17 @@ import {useDatabaseV1Store,useSQLEditorTabStore,} from "@/store";+import type { ComposedDatabase } from "@/types";import { extractProjectResourceName, hasWorkspacePermissionV2 } from "@/utils";import AdminModeButton from "./AdminModeButton.vue";+withDefaults(+ defineProps<{+ database?: ComposedDatabase | undefined;+ }>(),+ { database: undefined }+);+const emit = defineEmits<{(e: "close"): void;}>();diff --git a/frontend/src/views/sql-editor/EditorCommon/ExecutingHintModal.vue b/frontend/src/views/sql-editor/EditorCommon/ExecutingHintModal.vueindex 0df82e3f83..902f0e6766 100644--- a/frontend/src/views/sql-editor/EditorCommon/ExecutingHintModal.vue+++ b/frontend/src/views/sql-editor/EditorCommon/ExecutingHintModal.vue@@ -4,7 +4,10 @@:title="$t('common.tips')"@close="handleClose">- <ExecuteHint @close="handleClose" />+ <ExecuteHint+ :database="sqlEditorStore.executingHintDatabase"+ @close="handleClose"+ /></BBModal></template>