Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat: added enforceMfa toggle for orgs
Sheen Capadnganbd1ed2614e8b
diff --git a/backend/src/db/migrations/20241016183616_add-org-enforce-mfa.ts b/backend/src/db/migrations/20241016183616_add-org-enforce-mfa.tsnew file mode 100644index 0000000000..d01f1698e5--- /dev/null+++ b/backend/src/db/migrations/20241016183616_add-org-enforce-mfa.ts@@ -0,0 +1,19 @@+import { Knex } from "knex";++import { TableName } from "../schemas";++export async function up(knex: Knex): Promise<void> {+ if (!(await knex.schema.hasColumn(TableName.Organization, "enforceMfa"))) {+ await knex.schema.alterTable(TableName.Organization, (tb) => {+ tb.boolean("enforceMfa").defaultTo(false).notNullable();+ });+ }+}++export async function down(knex: Knex): Promise<void> {+ if (await knex.schema.hasColumn(TableName.Organization, "enforceMfa")) {+ await knex.schema.alterTable(TableName.Organization, (t) => {+ t.dropColumn("enforceMfa");+ });+ }+}diff --git a/backend/src/db/schemas/organizations.ts b/backend/src/db/schemas/organizations.tsindex 7bd20d94da..31de98168f 100644--- a/backend/src/db/schemas/organizations.ts+++ b/backend/src/db/schemas/organizations.ts@@ -20,7 +20,8 @@ export const OrganizationsSchema = z.object({scimEnabled: z.boolean().default(false).nullable().optional(),kmsDefaultKeyId: z.string().uuid().nullable().optional(),kmsEncryptedDataKey: zodBuffer.nullable().optional(),- defaultMembershipRole: z.string().default("member")+ defaultMembershipRole: z.string().default("member"),+ enforceMfa: z.boolean().default(false)});export type TOrganizations = z.infer<typeof OrganizationsSchema>;diff --git a/backend/src/ee/services/license/license-fns.ts b/backend/src/ee/services/license/license-fns.tsindex fa67b72d16..031c9f1a28 100644--- a/backend/src/ee/services/license/license-fns.ts+++ b/backend/src/ee/services/license/license-fns.ts@@ -46,7 +46,8 @@ export const getDefaultOnPremFeatures = (): TFeatureSet => ({writeLimit: 200,secretsLimit: 40},- pkiEst: false+ pkiEst: false,+ enforceMfa: false});export const setupLicenseRequestWithStore = (baseURL: string, refreshUrl: string, licenseKey: string) => {diff --git a/backend/src/ee/services/license/license-types.ts b/backend/src/ee/services/license/license-types.tsindex 6e671c26fd..c331679b55 100644--- a/backend/src/ee/services/license/license-types.ts+++ b/backend/src/ee/services/license/license-types.ts@@ -64,6 +64,7 @@ export type TFeatureSet = {secretsLimit: number;};pkiEst: boolean;+ enforceMfa: boolean;};export type TOrgPlansTableDTO = {diff --git a/backend/src/server/routes/v1/organization-router.ts b/backend/src/server/routes/v1/organization-router.tsindex 00f0397232..f6d5cacef8 100644--- a/backend/src/server/routes/v1/organization-router.ts+++ b/backend/src/server/routes/v1/organization-router.ts@@ -226,7 +226,8 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => {.refine((v) => slugify(v) === v, {message: "Membership role must be a valid slug"})- .optional()+ .optional(),+ enforceMfa: z.boolean().optional()}),response: {200: z.object({diff --git a/backend/src/services/org/org-service.ts b/backend/src/services/org/org-service.tsindex b4b8775f00..f5e15bbdae 100644--- a/backend/src/services/org/org-service.ts+++ b/backend/src/services/org/org-service.ts@@ -268,7 +268,7 @@ export const orgServiceFactory = ({actorOrgId,actorAuthMethod,orgId,- data: { name, slug, authEnforced, scimEnabled, defaultMembershipRoleSlug }+ data: { name, slug, authEnforced, scimEnabled, defaultMembershipRoleSlug, enforceMfa }}: TUpdateOrgDTO) => {const { permission } = await permissionService.getOrgPermission(actor, actorId, orgId, actorAuthMethod, actorOrgId);ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Edit, OrgPermissionSubjects.Settings);@@ -317,7 +317,8 @@ export const orgServiceFactory = ({slug: slug ? slugify(slug) : undefined,authEnforced,scimEnabled,- defaultMembershipRole+ defaultMembershipRole,+ enforceMfa});if (!org) throw new NotFoundError({ message: "Organization not found" });return org;diff --git a/backend/src/services/org/org-types.ts b/backend/src/services/org/org-types.tsindex d62a2c25b1..5b44eeea5d 100644--- a/backend/src/services/org/org-types.ts+++ b/backend/src/services/org/org-types.ts@@ -64,6 +64,7 @@ export type TUpdateOrgDTO = {authEnforced: boolean;scimEnabled: boolean;defaultMembershipRoleSlug: string;+ enforceMfa: boolean;}>;} & TOrgPermission;diff --git a/frontend/src/hooks/api/organization/queries.tsx b/frontend/src/hooks/api/organization/queries.tsxindex 1de64e058b..caab2408d5 100644--- a/frontend/src/hooks/api/organization/queries.tsx+++ b/frontend/src/hooks/api/organization/queries.tsx@@ -82,13 +82,22 @@ export const useCreateOrg = (options: { invalidate: boolean } = { invalidate: trexport const useUpdateOrg = () => {const queryClient = useQueryClient();return useMutation<{}, {}, UpdateOrgDTO>({- mutationFn: ({ name, authEnforced, scimEnabled, slug, orgId, defaultMembershipRoleSlug }) => {+ mutationFn: ({+ name,+ authEnforced,+ scimEnabled,+ slug,+ orgId,+ defaultMembershipRoleSlug,+ enforceMfa+ }) => {return apiRequest.patch(`/api/v1/organization/${orgId}`, {name,authEnforced,scimEnabled,slug,- defaultMembershipRoleSlug+ defaultMembershipRoleSlug,+ enforceMfa});},onSuccess: () => {diff --git a/frontend/src/hooks/api/organization/types.ts b/frontend/src/hooks/api/organization/types.tsindex 3d8d5474b1..b644cb3259 100644--- a/frontend/src/hooks/api/organization/types.ts+++ b/frontend/src/hooks/api/organization/types.ts@@ -11,6 +11,7 @@ export type Organization = {scimEnabled: boolean;slug: string;defaultMembershipRole: string;+ enforceMfa: boolean;};export type UpdateOrgDTO = {@@ -20,6 +21,7 @@ export type UpdateOrgDTO = {scimEnabled?: boolean;slug?: string;defaultMembershipRoleSlug?: string;+ enforceMfa?: boolean;};export type BillingDetails = {diff --git a/frontend/src/hooks/api/subscriptions/types.ts b/frontend/src/hooks/api/subscriptions/types.tsindex 6ee571d938..3506295fa4 100644--- a/frontend/src/hooks/api/subscriptions/types.ts+++ b/frontend/src/hooks/api/subscriptions/types.ts@@ -42,4 +42,5 @@ export type SubscriptionPlan = {instanceUserManagement: boolean;externalKms: boolean;pkiEst: boolean;+ enforceMfa: boolean;};diff --git a/frontend/src/views/Settings/OrgSettingsPage/components/OrgAuthTab/OrgAuthTab.tsx b/frontend/src/views/Settings/OrgSettingsPage/components/OrgAuthTab/OrgAuthTab.tsxindex f4c4c0c5d8..c0ff17ae6d 100644--- a/frontend/src/views/Settings/OrgSettingsPage/components/OrgAuthTab/OrgAuthTab.tsx+++ b/frontend/src/views/Settings/OrgSettingsPage/components/OrgAuthTab/OrgAuthTab.tsx@@ -16,6 +16,7 @@ import { LoginMethod } from "@app/hooks/api/admin/types";import { LDAPModal } from "./LDAPModal";import { OIDCModal } from "./OIDCModal";import { OrgGeneralAuthSection } from "./OrgGeneralAuthSection";+import { OrgGenericAuthSection } from "./OrgGenericAuthSection";import { OrgLDAPSection } from "./OrgLDAPSection";import { OrgOIDCSection } from "./OrgOIDCSection";import { OrgScimSection } from "./OrgSCIMSection";@@ -161,6 +162,7 @@ export const OrgAuthTab = withPermission(return (<>+ <OrgGenericAuthSection />{shouldShowCreateIdentityProviderView ? (createIdentityProviderView) : (diff --git a/frontend/src/views/Settings/OrgSettingsPage/components/OrgAuthTab/OrgGenericAuthSection.tsx b/frontend/src/views/Settings/OrgSettingsPage/components/OrgAuthTab/OrgGenericAuthSection.tsxnew file mode 100644index 0000000000..3a6663ddec--- /dev/null+++ b/frontend/src/views/Settings/OrgSettingsPage/components/OrgAuthTab/OrgGenericAuthSection.tsx@@ -0,0 +1,73 @@+import { createNotification } from "@app/components/notifications";+import { OrgPermissionCan } from "@app/components/permissions";+import { Switch, UpgradePlanModal } from "@app/components/v2";+import {+ OrgPermissionActions,+ OrgPermissionSubjects,+ useOrganization,+ useSubscription+} from "@app/context";+import { useUpdateOrg } from "@app/hooks/api";+import { usePopUp } from "@app/hooks/usePopUp";++export const OrgGenericAuthSection = () => {+ const { currentOrg } = useOrganization();+ const { subscription } = useSubscription();+ const { popUp, handlePopUpOpen, handlePopUpToggle } = usePopUp(["upgradePlan"] as const);++ const { mutateAsync } = useUpdateOrg();++ const handleEnforceMfaToggle = async (value: boolean) => {+ try {+ if (!currentOrg?.id) return;+ if (!subscription?.enforceMfa) {+ handlePopUpOpen("upgradePlan");+ return;+ }++ await mutateAsync({+ orgId: currentOrg?.id,+ enforceMfa: value+ });++ createNotification({+ text: `Successfully ${value ? "enforced" : "un-enforced"} MFA`,+ type: "success"+ });+ } catch (err) {+ console.error(err);+ createNotification({+ text: (err as { response: { data: { message: string } } }).response.data.message,+ type: "error"+ });+ }+ };++ return (+ <div className="mb-4 rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-6">+ <div className="py-4">+ <div className="mb-2 flex justify-between">+ <h3 className="text-md text-mineshaft-100">Enforce Multi-factor Authentication</h3>+ <OrgPermissionCan I={OrgPermissionActions.Edit} a={OrgPermissionSubjects.Sso}>+ {(isAllowed) => (+ <Switch+ id="enforce-org-mfa"+ onCheckedChange={(value) => handleEnforceMfaToggle(value)}+ isChecked={currentOrg?.enforceMfa ?? false}+ isDisabled={!isAllowed}+ />+ )}+ </OrgPermissionCan>+ </div>+ <p className="text-sm text-mineshaft-300">+ Enforce members to authenticate with MFA in order to access the organization+ </p>+ </div>+ <UpgradePlanModal+ isOpen={popUp.upgradePlan.isOpen}+ onOpenChange={(isOpen) => handlePopUpToggle("upgradePlan", isOpen)}+ text="You can enforce user MFA if you switch to Infisical's Pro plan."+ />+ </div>+ );+};