Skip to content

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

chore: add require 2FA setting in UI (#5439)

boojackdb51fdbfc3fd
diff --git a/frontend/src/bbkit/BBCheckbox.vue b/frontend/src/bbkit/BBCheckbox.vue
index 3c0451c9a1..c9153681ba 100644
--- a/frontend/src/bbkit/BBCheckbox.vue
+++ b/frontend/src/bbkit/BBCheckbox.vue
@@ -7,10 +7,13 @@
:class="[disabled && !value && 'bg-control-bg']"
:disabled="disabled"
:checked="value"
- @input="
+ @click.prevent="
() => {
on = !on;
$emit('toggle', on);
+ // Prevent dirty state.
+ // reference: https://stackoverflow.com/questions/74847997/vue3-controlling-checkbox-checked-state-by-a-component-prop
+ on = value;
}
"
/>
diff --git a/frontend/src/components/GeneralSetting/SecuritySetting.vue b/frontend/src/components/GeneralSetting/SecuritySetting.vue
index e1c58b7336..b2ce10b762 100644
--- a/frontend/src/components/GeneralSetting/SecuritySetting.vue
+++ b/frontend/src/components/GeneralSetting/SecuritySetting.vue
@@ -61,13 +61,39 @@
{{ $t("settings.general.workspace.disallow-signup.description") }}
</div>
</div>
+ <!-- TODO(steven): remove release guard later -->
+ <div v-if="isDev" class="mb-7 mt-5 lg:mt-0">
+ <label
+ class="flex items-center gap-x-2 tooltip-wrapper"
+ :class="[allowEdit ? 'cursor-pointer' : 'cursor-not-allowed']"
+ >
+ <BBCheckbox
+ :disabled="!allowEdit"
+ :value="require2FAEnabled"
+ @toggle="handleRequire2FAToggle"
+ />
+ <span class="font-medium">{{
+ $t("settings.general.workspace.require-2fa.enable")
+ }}</span>
+ <FeatureBadge feature="bb.feature.2fa" class="text-accent" />
+ <span
+ v-if="!allowEdit"
+ class="text-sm text-gray-400 -translate-y-2 tooltip"
+ >
+ {{ $t("settings.general.workspace.only-owner-can-edit") }}
+ </span>
+ </label>
+ <div class="mb-3 text-sm text-gray-400">
+ {{ $t("settings.general.workspace.require-2fa.description") }}
+ </div>
+ </div>
</div>
</div>
<FeatureModal
- v-if="state.showFeatureModal"
- feature="bb.feature.watermark"
- @cancel="state.showFeatureModal = false"
+ v-if="state.featureNameForModal"
+ :feature="state.featureNameForModal"
+ @cancel="state.featureNameForModal = undefined"
/>
</template>
@@ -81,26 +107,29 @@ import {
useSettingByName,
useSettingStore,
useActuatorStore,
+ useUserStore,
} from "@/store";
import { BBCheckbox } from "@/bbkit";
import { hasWorkspacePermission } from "@/utils";
import { useI18n } from "vue-i18n";
import { WorkspaceProfileSetting } from "@/types/proto/store/setting";
+import { FeatureType } from "@/types";
+import { UserType } from "@/types/proto/v1/auth_service";
interface LocalState {
- showFeatureModal: boolean;
+ featureNameForModal?: FeatureType;
}
-const state = reactive<LocalState>({
- showFeatureModal: false,
-});
+const state = reactive<LocalState>({});
const { t } = useI18n();
const settingStore = useSettingStore();
const currentUser = useCurrentUser();
+const userStore = useUserStore();
const actuatorStore = useActuatorStore();
const { isSaaSMode } = storeToRefs(actuatorStore);
const hasWatermarkFeature = featureToRef("bb.feature.branding");
const watermarkSetting = useSettingByName("bb.workspace.watermark");
+const has2FAFeature = featureToRef("bb.feature.2fa");
const allowEdit = computed((): boolean => {
return hasWorkspacePermission(
@@ -114,11 +143,15 @@ const watermarkEnabled = computed((): boolean => {
const disallowSignupEnabled = computed((): boolean => {
return settingStore.workspaceSetting?.disallowSignup ?? false;
});
+const require2FAEnabled = computed((): boolean => {
+ return settingStore.workspaceSetting?.require2fa ?? false;
+});
const handleDisallowSignupToggle = async (on: boolean) => {
const payload: WorkspaceProfileSetting = {
disallowSignup: on,
externalUrl: settingStore.workspaceSetting?.externalUrl ?? "",
+ require2fa: settingStore.workspaceSetting?.require2fa ?? false,
};
await settingStore.updateSettingByName({
@@ -131,9 +164,49 @@ const handleDisallowSignupToggle = async (on: boolean) => {
title: t("settings.general.workspace.config-updated"),
});
};
+
+const handleRequire2FAToggle = async (on: boolean) => {
+ if (!has2FAFeature.value) {
+ state.featureNameForModal = "bb.feature.2fa";
+ return;
+ }
+
+ if (on) {
+ // Only allow to enable this when all users have enabled 2FA.
+ const userList = userStore.userList
+ .filter((user) => user.userType === UserType.USER)
+ .filter((user) => !user.mfaEnabled);
+ if (userList.length > 0) {
+ pushNotification({
+ module: "bytebase",
+ style: "WARN",
+ title: t(
+ "settings.general.workspace.require-2fa.need-all-user-2fa-enabled"
+ ),
+ });
+ return;
+ }
+ }
+
+ const payload: WorkspaceProfileSetting = {
+ disallowSignup: settingStore.workspaceSetting?.disallowSignup || false,
+ externalUrl: settingStore.workspaceSetting?.externalUrl ?? "",
+ require2fa: on,
+ };
+ await settingStore.updateSettingByName({
+ name: "bb.workspace.profile",
+ value: JSON.stringify(payload),
+ });
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("settings.general.workspace.config-updated"),
+ });
+};
+
const handleWatermarkToggle = async (on: boolean) => {
if (!hasWatermarkFeature.value) {
- state.showFeatureModal = true;
+ state.featureNameForModal = "bb.feature.watermark";
return;
}
const value = on ? "1" : "0";
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 170d07ad8f..a405c2c778 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -489,6 +489,11 @@
"enable": "Disable self-service signup",
"description": "Once disabled, users cannot self-service signup and can only be invited by the workspace owner."
},
+ "require-2fa": {
+ "enable": "Require two-factor authentication for all users",
+ "description": "When enabled, users who do not have two-factor authentication enabled for their personal accounts will be forced to configure.",
+ "need-all-user-2fa-enabled": "Requires all users to enable 2FA first"
+ },
"network": "Network",
"external-url": {
"self": "External URL",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index d9a172e50e..d489f82589 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -487,6 +487,11 @@
"enable": "禁用自助注册",
"description": "禁用之后,新用户将无法自助注册,只能通过管理员邀请来创建账户。"
},
+ "require-2fa": {
+ "enable": "要求所有用户配置双重认证",
+ "description": "启用之后,没有配置双重认证的用户将被强制要求进行配置操作。",
+ "need-all-user-2fa-enabled": "需要所有用户都配置 2FA 后才能开启此项"
+ },
"network": "网络",
"external-url": {
"self": "External URL",