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: add require mfa to pam account
Sheen Capadngan6061c8f3aeef
diff --git a/backend/src/db/migrations/20251119124200_add-require-mfa-to-pam-account.ts b/backend/src/db/migrations/20251119124200_add-require-mfa-to-pam-account.tsnew file mode 100644index 0000000000..43460adfae--- /dev/null+++ b/backend/src/db/migrations/20251119124200_add-require-mfa-to-pam-account.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.PamAccount, "requireMfa"))) {+ await knex.schema.alterTable(TableName.PamAccount, (t) => {+ t.boolean("requireMfa").defaultTo(false);+ });+ }+}++export async function down(knex: Knex): Promise<void> {+ if (await knex.schema.hasColumn(TableName.PamAccount, "requireMfa")) {+ await knex.schema.alterTable(TableName.PamAccount, (t) => {+ t.dropColumn("requireMfa");+ });+ }+}diff --git a/backend/src/db/schemas/pam-accounts.ts b/backend/src/db/schemas/pam-accounts.tsindex 4f097a16d8..69d167bfe6 100644--- a/backend/src/db/schemas/pam-accounts.ts+++ b/backend/src/db/schemas/pam-accounts.ts@@ -23,7 +23,8 @@ export const PamAccountsSchema = z.object({rotationIntervalSeconds: z.number().nullable().optional(),lastRotatedAt: z.date().nullable().optional(),rotationStatus: z.string().nullable().optional(),- encryptedLastRotationMessage: zodBuffer.nullable().optional()+ encryptedLastRotationMessage: zodBuffer.nullable().optional(),+ requireMfa: z.boolean().default(false).nullable().optional()});export type TPamAccounts = z.infer<typeof PamAccountsSchema>;diff --git a/backend/src/ee/routes/v1/pam-account-routers/pam-account-endpoints.ts b/backend/src/ee/routes/v1/pam-account-routers/pam-account-endpoints.tsindex 44e2a5ea11..6ded3ece1c 100644--- a/backend/src/ee/routes/v1/pam-account-routers/pam-account-endpoints.ts+++ b/backend/src/ee/routes/v1/pam-account-routers/pam-account-endpoints.ts@@ -24,6 +24,7 @@ export const registerPamResourceEndpoints = <C extends TPamAccount>({description?: C["description"];rotationEnabled: C["rotationEnabled"];rotationIntervalSeconds?: C["rotationIntervalSeconds"];+ requireMfa?: C["requireMfa"];}>;updateAccountSchema: z.ZodType<{credentials?: C["credentials"];@@ -31,6 +32,7 @@ export const registerPamResourceEndpoints = <C extends TPamAccount>({description?: C["description"];rotationEnabled?: C["rotationEnabled"];rotationIntervalSeconds?: C["rotationIntervalSeconds"];+ requireMfa?: C["requireMfa"];}>;accountResponseSchema: z.ZodTypeAny;}) => {@@ -66,7 +68,8 @@ export const registerPamResourceEndpoints = <C extends TPamAccount>({name: req.body.name,description: req.body.description,rotationEnabled: req.body.rotationEnabled,- rotationIntervalSeconds: req.body.rotationIntervalSeconds+ rotationIntervalSeconds: req.body.rotationIntervalSeconds,+ requireMfa: req.body.requireMfa}}});@@ -116,7 +119,8 @@ export const registerPamResourceEndpoints = <C extends TPamAccount>({name: req.body.name,description: req.body.description,rotationEnabled: req.body.rotationEnabled,- rotationIntervalSeconds: req.body.rotationIntervalSeconds+ rotationIntervalSeconds: req.body.rotationIntervalSeconds,+ requireMfa: req.body.requireMfa}}});diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.tsindex ba409a4fba..bfed20f435 100644--- a/backend/src/ee/services/audit-log/audit-log-types.ts+++ b/backend/src/ee/services/audit-log/audit-log-types.ts@@ -3992,6 +3992,7 @@ interface PamAccountCreateEvent {description?: string | null;rotationEnabled: boolean;rotationIntervalSeconds?: number | null;+ requireMfa?: boolean | null;};}@@ -4005,6 +4006,7 @@ interface PamAccountUpdateEvent {description?: string | null;rotationEnabled?: boolean;rotationIntervalSeconds?: number | null;+ requireMfa?: boolean | null;};}diff --git a/backend/src/ee/services/pam-account/pam-account-service.ts b/backend/src/ee/services/pam-account/pam-account-service.tsindex 25b8d6c073..a7672b6001 100644--- a/backend/src/ee/services/pam-account/pam-account-service.ts+++ b/backend/src/ee/services/pam-account/pam-account-service.ts@@ -128,7 +128,8 @@ export const pamAccountServiceFactory = ({description,folderId,rotationEnabled,- rotationIntervalSeconds+ rotationIntervalSeconds,+ requireMfa}: TCreateAccountDTO,actor: OrgServiceActor) => {@@ -205,7 +206,8 @@ export const pamAccountServiceFactory = ({description,folderId,rotationEnabled,- rotationIntervalSeconds+ rotationIntervalSeconds,+ requireMfa});return {@@ -229,7 +231,15 @@ export const pamAccountServiceFactory = ({};const updateById = async (- { accountId, credentials, description, name, rotationEnabled, rotationIntervalSeconds }: TUpdateAccountDTO,+ {+ accountId,+ credentials,+ description,+ name,+ rotationEnabled,+ rotationIntervalSeconds,+ requireMfa+ }: TUpdateAccountDTO,actor: OrgServiceActor) => {const orgLicensePlan = await licenseService.getPlan(actor.orgId);@@ -275,6 +285,10 @@ export const pamAccountServiceFactory = ({updateDoc.name = name;}+ if (requireMfa !== undefined) {+ updateDoc.requireMfa = requireMfa;+ }+if (description !== undefined) {updateDoc.description = description;}@@ -500,7 +514,7 @@ export const pamAccountServiceFactory = ({if (!actorUser) throw new NotFoundError({ message: `User with ID '${actor.id}' not found` });// If no mfaSessionId is provided, create a new MFA session- if (!mfaSessionId) {+ if (!mfaSessionId && account.requireMfa) {// Get organization to check if MFA is enforced at org levelconst org = await orgDAL.findOrgById(project.orgId);if (!org) throw new NotFoundError({ message: `Organization with ID '${project.orgId}' not found` });@@ -534,41 +548,43 @@ export const pamAccountServiceFactory = ({});}- // If mfaSessionId is provided, verify it- const mfaSessionKey = KeyStorePrefixes.MfaSession(mfaSessionId);- const mfaSessionData = await keyStore.getItem(mfaSessionKey);+ if (mfaSessionId && account.requireMfa) {+ // If mfaSessionId is provided, verify it+ const mfaSessionKey = KeyStorePrefixes.MfaSession(mfaSessionId);+ const mfaSessionData = await keyStore.getItem(mfaSessionKey);- if (!mfaSessionData) {- throw new BadRequestError({- message: "MFA session not found or expired"- });- }+ if (!mfaSessionData) {+ throw new BadRequestError({+ message: "MFA session not found or expired"+ });+ }- const mfaSession = JSON.parse(mfaSessionData) as TMfaSession;+ const mfaSession = JSON.parse(mfaSessionData) as TMfaSession;- // Verify the session belongs to the current user- if (mfaSession.userId !== actor.id) {- throw new ForbiddenRequestError({- message: "MFA session does not belong to current user"- });- }+ // Verify the session belongs to the current user+ if (mfaSession.userId !== actor.id) {+ throw new ForbiddenRequestError({+ message: "MFA session does not belong to current user"+ });+ }- // Verify the session is for the same account- if (mfaSession.resourceId !== accountId) {- throw new BadRequestError({- message: "MFA session is for a different resource"- });- }+ // Verify the session is for the same account+ if (mfaSession.resourceId !== accountId) {+ throw new BadRequestError({+ message: "MFA session is for a different resource"+ });+ }- // Check if MFA session is active- if (mfaSession.status !== MfaSessionStatus.ACTIVE) {- throw new BadRequestError({- message: "MFA session is not active. Please complete MFA verification first."- });- }+ // Check if MFA session is active+ if (mfaSession.status !== MfaSessionStatus.ACTIVE) {+ throw new BadRequestError({+ message: "MFA session is not active. Please complete MFA verification first."+ });+ }- // MFA verified successfully, delete the session and proceed with access- await keyStore.deleteItem(mfaSessionKey);+ // MFA verified successfully, delete the session and proceed with access+ await keyStore.deleteItem(mfaSessionKey);+ }const session = await pamSessionDAL.create({accountName: account.name,diff --git a/backend/src/ee/services/pam-account/pam-account-types.ts b/backend/src/ee/services/pam-account/pam-account-types.tsindex 78a45d90c6..c6ba111659 100644--- a/backend/src/ee/services/pam-account/pam-account-types.ts+++ b/backend/src/ee/services/pam-account/pam-account-types.ts@@ -3,7 +3,14 @@ import { TPamAccount } from "../pam-resource/pam-resource-types";// DTOsexport type TCreateAccountDTO = Pick<TPamAccount,- "name" | "description" | "credentials" | "folderId" | "resourceId" | "rotationEnabled" | "rotationIntervalSeconds"+ | "name"+ | "description"+ | "credentials"+ | "folderId"+ | "resourceId"+ | "rotationEnabled"+ | "rotationIntervalSeconds"+ | "requireMfa">;export type TUpdateAccountDTO = Partial<Omit<TCreateAccountDTO, "folderId" | "resourceId">> & {diff --git a/backend/src/ee/services/pam-resource/pam-resource-schemas.ts b/backend/src/ee/services/pam-resource/pam-resource-schemas.tsindex 17ed1ccd19..c5e1afed7f 100644--- a/backend/src/ee/services/pam-resource/pam-resource-schemas.ts+++ b/backend/src/ee/services/pam-resource/pam-resource-schemas.ts@@ -44,12 +44,14 @@ export const BaseCreatePamAccountSchema = z.object({name: slugSchema({ field: "name" }),description: z.string().max(512).nullable().optional(),rotationEnabled: z.boolean(),- rotationIntervalSeconds: z.number().min(3600).nullable().optional()+ rotationIntervalSeconds: z.number().min(3600).nullable().optional(),+ requireMfa: z.boolean().optional().default(false)});export const BaseUpdatePamAccountSchema = z.object({name: slugSchema({ field: "name" }).optional(),description: z.string().max(512).nullable().optional(),rotationEnabled: z.boolean().optional(),- rotationIntervalSeconds: z.number().min(3600).nullable().optional()+ rotationIntervalSeconds: z.number().min(3600).nullable().optional(),+ requireMfa: z.boolean().optional()});diff --git a/frontend/src/hooks/api/pam/types/base-account.ts b/frontend/src/hooks/api/pam/types/base-account.tsindex 286c9389a3..2b9b80df0d 100644--- a/frontend/src/hooks/api/pam/types/base-account.ts+++ b/frontend/src/hooks/api/pam/types/base-account.ts@@ -15,6 +15,7 @@ export interface TBasePamAccount {description?: string | null;rotationEnabled: boolean;rotationIntervalSeconds?: number | null;+ requireMfa?: boolean | null;lastRotatedAt?: string | null;lastRotationMessage?: string | null;rotationStatus?: string | null;diff --git a/frontend/src/hooks/api/pam/types/index.ts b/frontend/src/hooks/api/pam/types/index.tsindex 6f37c97c34..de115f5290 100644--- a/frontend/src/hooks/api/pam/types/index.ts+++ b/frontend/src/hooks/api/pam/types/index.ts@@ -79,13 +79,29 @@ export type TDeletePamResourceDTO = {// Account DTOsexport type TCreatePamAccountDTO = Pick<TPamAccount,- "name" | "description" | "credentials" | "projectId" | "resourceId" | "folderId"+ | "name"+ | "description"+ | "credentials"+ | "projectId"+ | "resourceId"+ | "folderId"+ | "rotationEnabled"+ | "rotationIntervalSeconds"+ | "requireMfa"> & {resourceType: PamResourceType;};export type TUpdatePamAccountDTO = Partial<- Pick<TPamAccount, "name" | "description" | "credentials">+ Pick<+ TPamAccount,+ | "name"+ | "description"+ | "credentials"+ | "rotationEnabled"+ | "rotationIntervalSeconds"+ | "requireMfa"+ >> & {accountId: string;resourceType: PamResourceType;diff --git a/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/MySQLAccountForm.tsx b/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/MySQLAccountForm.tsxindex e30c79e24b..cc3ad96d69 100644--- a/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/MySQLAccountForm.tsx+++ b/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/MySQLAccountForm.tsx@@ -9,6 +9,7 @@ import { UNCHANGED_PASSWORD_SENTINEL } from "@app/hooks/api/pam/constants";import { BaseSqlAccountSchema } from "./shared/sql-account-schemas";import { SqlAccountFields } from "./shared/SqlAccountFields";import { GenericAccountFields, genericAccountFieldsSchema } from "./GenericAccountFields";+import { RequireMfaField } from "./RequireMfaField";type Props = {account?: TMySQLAccount;@@ -21,7 +22,8 @@ const formSchema = genericAccountFieldsSchema.extend({credentials: BaseSqlAccountSchema,// We don't support rotation for now, just feed a false value to// make the schema happy- rotationEnabled: z.boolean().default(false)+ rotationEnabled: z.boolean().default(false),+ requireMfa: z.boolean().nullable().optional()});type FormData = z.infer<typeof formSchema>;@@ -49,13 +51,10 @@ export const MySQLAccountForm = ({ account, onSubmit }: Props) => {return (<FormProvider {...form}>- <form- onSubmit={(e) => {- handleSubmit(onSubmit)(e);- }}- >+ <form onSubmit={handleSubmit(onSubmit)}><GenericAccountFields /><SqlAccountFields isUpdate={isUpdate} />+ <RequireMfaField /><div className="mt-6 flex items-center"><ButtonclassName="mr-4"diff --git a/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/PamAccountForm.tsx b/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/PamAccountForm.tsxindex 0288411b10..f5f2c8e6c6 100644--- a/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/PamAccountForm.tsx+++ b/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/PamAccountForm.tsx@@ -37,7 +37,15 @@ const CreateForm = ({const createPamAccount = useCreatePamAccount();const onSubmit = async (- formData: DiscriminativePick<TPamAccount, "name" | "description" | "credentials">+ formData: DiscriminativePick<+ TPamAccount,+ | "name"+ | "description"+ | "credentials"+ | "rotationEnabled"+ | "rotationIntervalSeconds"+ | "requireMfa"+ >) => {const account = await createPamAccount.mutateAsync({...formData,@@ -79,7 +87,15 @@ const UpdateForm = ({ account, onComplete }: UpdateFormProps) => {const updatePamAccount = useUpdatePamAccount();const onSubmit = async (- formData: DiscriminativePick<TPamAccount, "name" | "description" | "credentials">+ formData: DiscriminativePick<+ TPamAccount,+ | "name"+ | "description"+ | "credentials"+ | "rotationEnabled"+ | "rotationIntervalSeconds"+ | "requireMfa"+ >) => {const updatedAccount = await updatePamAccount.mutateAsync({accountId: account.id,diff --git a/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/PostgresAccountForm.tsx b/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/PostgresAccountForm.tsxindex e7d2d902bf..a641e03aab 100644--- a/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/PostgresAccountForm.tsx+++ b/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/PostgresAccountForm.tsx@@ -15,6 +15,7 @@ import { UNCHANGED_PASSWORD_SENTINEL } from "@app/hooks/api/pam/constants";import { BaseSqlAccountSchema } from "./shared/sql-account-schemas";import { SqlAccountFields } from "./shared/SqlAccountFields";import { GenericAccountFields, genericAccountFieldsSchema } from "./GenericAccountFields";+import { RequireMfaField } from "./RequireMfaField";import { RotateAccountFields, rotateAccountFieldsSchema } from "./RotateAccountFields";type Props = {@@ -25,7 +26,8 @@ type Props = {};const formSchema = genericAccountFieldsSchema.extend(rotateAccountFieldsSchema.shape).extend({- credentials: BaseSqlAccountSchema+ credentials: BaseSqlAccountSchema,+ requireMfa: z.boolean().nullable().optional()});type FormData = z.infer<typeof formSchema>;@@ -69,14 +71,11 @@ export const PostgresAccountForm = ({ account, resourceId, resourceType, onSubmireturn (<FormProvider {...form}>- <form- onSubmit={(e) => {- handleSubmit(onSubmit)(e);- }}- >+ <form onSubmit={handleSubmit(onSubmit)}><GenericAccountFields /><SqlAccountFields isUpdate={isUpdate} />- <RotateAccountFields rotationCredentialsConfigured={rotationCredentialsConfigured} />+ {rotationCredentialsConfigured && <RotateAccountFields />}+ <RequireMfaField /><div className="mt-6 flex items-center"><ButtonclassName="mr-4"diff --git a/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/RequireMfaField.tsx b/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/RequireMfaField.tsxnew file mode 100644index 0000000000..1bd21d2e1c--- /dev/null+++ b/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/RequireMfaField.tsx@@ -0,0 +1,31 @@+import { Controller, useFormContext } from "react-hook-form";++import { FormControl, Switch } from "@app/components/v2";++export const RequireMfaField = () => {+ const { control } = useFormContext<{+ requireMfa?: boolean | null;+ }>();++ return (+ <div className="flex h-9 w-fit items-center gap-3">+ <Controller+ control={control}+ name="requireMfa"+ defaultValue={false}+ render={({ field: { value, onChange }, fieldState: { error } }) => (+ <FormControl isError={Boolean(error)} errorText={error?.message} className="mb-0">+ <Switch+ className="ml-0 bg-mineshaft-400/80 shadow-inner data-[state=checked]:bg-green/80"+ id="require-mfa"+ thumbClassName="bg-mineshaft-800"+ onCheckedChange={onChange}+ isChecked={value ?? false}+ />+ </FormControl>+ )}+ />+ <span className="text-sm">Require MFA for Access</span>+ </div>+ );+};diff --git a/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/RotateAccountFields.tsx b/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/RotateAccountFields.tsxindex a73fad58bb..f33c51c19a 100644--- a/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/RotateAccountFields.tsx+++ b/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/RotateAccountFields.tsx@@ -1,5 +1,4 @@import { Controller, useFormContext } from "react-hook-form";-import { twMerge } from "tailwind-merge";import { z } from "zod";import { FormControl, Select, SelectItem, Switch, Tooltip } from "@app/components/v2";@@ -9,11 +8,7 @@ export const rotateAccountFieldsSchema = z.object({rotationIntervalSeconds: z.number().nullable().optional()});-export const RotateAccountFields = ({- rotationCredentialsConfigured-}: {- rotationCredentialsConfigured: boolean;-}) => {+export const RotateAccountFields = () => {const { control, watch } = useFormContext<{rotationEnabled: boolean;rotationIntervalSeconds?: number | null;@@ -22,16 +17,8 @@ export const RotateAccountFields = ({const rotationEnabled = watch("rotationEnabled");return (- <Tooltip- isDisabled={rotationCredentialsConfigured}- content="The resource which owns this account does not have rotation credentials configured."- >- <div- className={twMerge(- "flex h-9 w-fit items-center gap-3",- !rotationCredentialsConfigured && "opacity-50"- )}- >+ <Tooltip content="The resource which owns this account does not have rotation credentials configured.">+ <div className="flex h-9 w-fit items-center gap-3"><Controllercontrol={control}name="rotationEnabled"@@ -44,7 +31,6 @@ export const RotateAccountFields = ({thumbClassName="bg-mineshaft-800"onCheckedChange={onChange}isChecked={value}- isDisabled={!rotationCredentialsConfigured}/></FormControl>)}@@ -68,7 +54,7 @@ export const RotateAccountFields = ({position="popper"placeholder="Select an interval..."dropdownContainerClassName="max-w-none"- isDisabled={!rotationEnabled || !rotationCredentialsConfigured}+ isDisabled={!rotationEnabled}dropdownContainerStyle={{width: "130px"}}diff --git a/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/SSHAccountForm.tsx b/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/SSHAccountForm.tsxindex 0302e4759a..3671b5b3d1 100644--- a/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/SSHAccountForm.tsx+++ b/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/SSHAccountForm.tsx@@ -1,5 +1,5 @@-import { zodResolver } from "@hookform/resolvers/zod";import { FormProvider, useForm } from "react-hook-form";+import { zodResolver } from "@hookform/resolvers/zod";import { z } from "zod";import { Button, ModalClose } from "@app/components/v2";@@ -7,9 +7,10 @@ import { PamResourceType, TSSHAccount } from "@app/hooks/api/pam";import { UNCHANGED_PASSWORD_SENTINEL } from "@app/hooks/api/pam/constants";import { SSHAuthMethod } from "@app/hooks/api/pam/types/ssh-resource";-import { GenericAccountFields, genericAccountFieldsSchema } from "./GenericAccountFields";import { BaseSshAccountSchema } from "./shared/ssh-account-schemas";import { SshAccountFields } from "./shared/SshAccountFields";+import { GenericAccountFields, genericAccountFieldsSchema } from "./GenericAccountFields";+import { RequireMfaField } from "./RequireMfaField";type Props = {account?: TSSHAccount;@@ -22,7 +23,8 @@ const formSchema = genericAccountFieldsSchema.extend({credentials: BaseSshAccountSchema,// We don't support rotation for now, just feed a false value to// make the schema happy- rotationEnabled: z.boolean().default(false)+ rotationEnabled: z.boolean().default(false),+ requireMfa: z.boolean().nullable().optional()});type FormData = z.infer<typeof formSchema>;@@ -60,6 +62,8 @@ export const SSHAccountForm = ({ account, onSubmit }: Props) => {: {name: "",description: "",+ requireMfa: false,+ rotationEnabled: false,credentials: {authMethod: SSHAuthMethod.Password,username: "",@@ -75,13 +79,10 @@ export const SSHAccountForm = ({ account, onSubmit }: Props) => {return (<FormProvider {...form}>- <form- onSubmit={(e) => {- handleSubmit(onSubmit)(e);- }}- >+ <form onSubmit={handleSubmit(onSubmit)}><GenericAccountFields /><SshAccountFields isUpdate={isUpdate} />+ <RequireMfaField /><div className="mt-6 flex items-center"><ButtonclassName="mr-4"