Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Merge branch 'ENG-3506' into ENG-3506-LDAP

x032205cbc1d951ac92
diff --cc frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityLdapAuthForm.tsx
index 7449422195,ee0cddc5c1..31f7e56ebe
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityLdapAuthForm.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityLdapAuthForm.tsx
@@@ -3,6 -3,6 +3,7 @@@ import { Controller, useFieldArray, use
import { faPlus, faQuestionCircle, faXmark } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { zodResolver } from "@hookform/resolvers/zod";
++import ms from "ms";
import { z } from "zod";
import { createNotification } from "@app/components/notifications";
@@@ -25,7 -25,6 +26,7 @@@ import
OrgPermissionMachineIdentityAuthTemplateActions,
OrgPermissionSubjects
} from "@app/context/OrgPermissionContext/types";
- import { durationToSeconds, getObjectFromSeconds } from "@app/helpers/datetime";
++import { getObjectFromSeconds } from "@app/helpers/datetime";
import {
MachineIdentityAuthMethod,
useAddIdentityLdapAuth,
@@@ -325,24 -275,9 +326,19 @@@ export const IdentityLdapAuthForm = (
accessTokenTTL,
accessTokenMaxTTL,
accessTokenNumUsesLimit,
- accessTokenTrustedIps
+ accessTokenTrustedIps,
+ lockoutEnabled,
+ lockoutThreshold,
+ lockoutDurationValue,
+ lockoutDurationUnit,
+ lockoutCounterResetValue,
+ lockoutCounterResetUnit
} = formData;
- const lockoutDurationSeconds = durationToSeconds(
- Number(lockoutDurationValue),
- lockoutDurationUnit
- );
- const lockoutCounterResetSeconds = durationToSeconds(
- Number(lockoutCounterResetValue),
- lockoutCounterResetUnit
- );
++ const lockoutDurationSeconds = ms(`${lockoutDurationValue}${lockoutDurationUnit}`) / 1000;
++ const lockoutCounterResetSeconds =
++ ms(`${lockoutCounterResetValue}${lockoutCounterResetUnit}`) / 1000;
+
const basePayload = {
organizationId: orgId,
identityId,
diff --cc frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/lockout/super-refine.ts
index e84989e82d,0000000000..a597f810f0
mode 100644,000000..100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/lockout/super-refine.ts
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/lockout/super-refine.ts
@@@ -1,73 -1,0 +1,67 @@@
++import ms from "ms";
+import { z } from "zod";
+
- import { durationToSeconds } from "@app/helpers/datetime";
-
+export function superRefineLockout(
+ data: {
+ lockoutDurationValue: string;
+ lockoutCounterResetValue: string;
+ lockoutDurationUnit: "s" | "m" | "h" | "d";
+ lockoutCounterResetUnit: "s" | "m" | "h";
+ lockoutEnabled: boolean;
+ },
+ ctx: z.RefinementCtx
+) {
+ const {
+ lockoutDurationValue,
+ lockoutCounterResetValue,
+ lockoutDurationUnit,
+ lockoutCounterResetUnit,
+ lockoutEnabled
+ } = data;
+
+ if (lockoutEnabled) {
+ let isAnyParseError = false;
+
+ const parsedLockoutDuration = parseInt(lockoutDurationValue, 10);
+ if (Number.isNaN(parsedLockoutDuration)) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: "Lockout duration must be a number",
+ path: ["lockoutDurationValue"]
+ });
+ isAnyParseError = true;
+ }
+
+ const parsedLockoutCounterReset = parseInt(lockoutCounterResetValue, 10);
+ if (Number.isNaN(parsedLockoutCounterReset)) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: "Lockout counter reset must be a number",
+ path: ["lockoutCounterResetValue"]
+ });
+ isAnyParseError = true;
+ }
+
+ if (!isAnyParseError) {
- const lockoutDurationInSeconds = durationToSeconds(
- parsedLockoutDuration,
- lockoutDurationUnit
- );
- const lockoutCounterResetInSeconds = durationToSeconds(
- parsedLockoutCounterReset,
- lockoutCounterResetUnit
- );
++ const lockoutDurationInSeconds = ms(`${parsedLockoutDuration}${lockoutDurationUnit}`) / 1000;
++ const lockoutCounterResetInSeconds =
++ ms(`${parsedLockoutCounterReset}${lockoutCounterResetUnit}`) / 1000;
+
+ if (lockoutDurationInSeconds > 86400 || lockoutDurationInSeconds < 30) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: "Lockout duration must be between 30 seconds and 1 day",
+ path: ["lockoutDurationValue"]
+ });
+ }
+
+ if (lockoutCounterResetInSeconds > 3600 || lockoutCounterResetInSeconds < 5) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: "Lockout counter reset must be between 5 seconds and 1 hour",
+ path: ["lockoutCounterResetValue"]
+ });
+ }
+ }
+ }
+}
diff --cc frontend/src/pages/organization/IdentityDetailsByIDPage/components/ViewIdentityAuthModal/IdentityAuthLockoutFields.tsx
index aa55f418e2,0000000000..1a616178e1
mode 100644,000000..100644
--- a/frontend/src/pages/organization/IdentityDetailsByIDPage/components/ViewIdentityAuthModal/IdentityAuthLockoutFields.tsx
+++ b/frontend/src/pages/organization/IdentityDetailsByIDPage/components/ViewIdentityAuthModal/IdentityAuthLockoutFields.tsx
@@@ -1,81 -1,0 +1,84 @@@
+import { useState } from "react";
+import { UseMutationResult } from "@tanstack/react-query";
+import ms from "ms";
+
+import { createNotification } from "@app/components/notifications";
+import { OrgPermissionCan } from "@app/components/permissions";
+import { Button } from "@app/components/v2";
+import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "@app/context";
+
+import { IdentityAuthFieldDisplay } from "./IdentityAuthFieldDisplay";
+
+export const LockoutFields = ({
+ clearLockoutsResult,
+ lockedOut,
+ identityId,
- data
++ data,
++ onResetAllLockouts
+}: {
+ clearLockoutsResult: UseMutationResult<number, object, { identityId: string }, unknown>;
+ lockedOut: boolean;
+ identityId: string;
+ data: {
+ lockoutEnabled: boolean;
+ lockoutThreshold: number;
+ lockoutDurationSeconds: number;
+ lockoutCounterResetSeconds: number;
+ };
++ onResetAllLockouts: () => void;
+}) => {
+ const { mutateAsync, isPending } = clearLockoutsResult;
+
+ const [lockedOutState, setLockedOutState] = useState(lockedOut);
+
+ async function clearLockouts() {
+ try {
+ const deleted = await mutateAsync({ identityId });
+ createNotification({
+ text: `Successfully cleared ${deleted} lockout${deleted === 1 ? "" : "s"}`,
+ type: "success"
+ });
+ setLockedOutState(false);
++ onResetAllLockouts();
+ } catch (error) {
+ console.error(error);
+ createNotification({
+ text: "Failed to clear lockouts. Please try again.",
+ type: "error"
+ });
+ }
+ }
+
+ return (
+ <>
+ <div className="col-span-2 mt-3 flex justify-between border-b border-mineshaft-500 pb-2">
+ <span className="text-bunker-300">Lockout Options</span>
+ <OrgPermissionCan I={OrgPermissionIdentityActions.Edit} a={OrgPermissionSubjects.Identity}>
+ {(isAllowed) => (
+ <Button
+ isDisabled={!isAllowed || !lockedOutState || isPending}
+ size="xs"
+ onClick={() => clearLockouts()}
+ isLoading={isPending}
+ colorSchema="secondary"
+ >
- Clear All Lockouts
++ Reset All Lockouts
+ </Button>
+ )}
+ </OrgPermissionCan>
+ </div>
+ <IdentityAuthFieldDisplay label="Lockout">
+ {data.lockoutEnabled ? "Enabled" : "Disabled"}
+ </IdentityAuthFieldDisplay>
+ <IdentityAuthFieldDisplay label="Lockout Threshold">
+ {data.lockoutThreshold}
+ </IdentityAuthFieldDisplay>
+ <IdentityAuthFieldDisplay label="Lockout Duration">
+ {ms(data.lockoutDurationSeconds * 1000, { long: true })}
+ </IdentityAuthFieldDisplay>
+ <IdentityAuthFieldDisplay label="Lockout Counter Reset">
+ {ms(data.lockoutCounterResetSeconds * 1000, { long: true })}
+ </IdentityAuthFieldDisplay>
+ </>
+ );
+};
diff --cc frontend/src/pages/organization/IdentityDetailsByIDPage/components/ViewIdentityAuthModal/ViewIdentityLdapAuthContent.tsx
index 2d67734846,f732fd5ed0..998073c1de
--- a/frontend/src/pages/organization/IdentityDetailsByIDPage/components/ViewIdentityAuthModal/ViewIdentityLdapAuthContent.tsx
+++ b/frontend/src/pages/organization/IdentityDetailsByIDPage/components/ViewIdentityAuthModal/ViewIdentityLdapAuthContent.tsx
@@@ -15,11 -14,9 +15,12 @@@ export const ViewIdentityLdapAuthConten
handlePopUpToggle,
handlePopUpOpen,
onDelete,
- popUp
+ popUp,
- lockedOut
++ lockedOut,
++ onResetAllLockouts
}: ViewAuthMethodProps) => {
const { data, isPending } = useGetIdentityLdapAuth(identityId);
+ const clearLockoutsResult = useClearIdentityLdapAuthLockouts();
if (isPending) {
return (
@@@ -101,12 -98,6 +102,13 @@@
</Tooltip>
)}
</IdentityAuthFieldDisplay>
+ <LockoutFields
+ identityId={identityId}
+ lockedOut={lockedOut}
+ clearLockoutsResult={clearLockoutsResult}
+ data={data}
++ onResetAllLockouts={onResetAllLockouts}
+ />
</ViewIdentityContentWrapper>
);
};
diff --cc frontend/src/pages/organization/IdentityDetailsByIDPage/components/ViewIdentityAuthModal/ViewIdentityUniversalAuthContent.tsx
index 7ef8790c2c,a9cb5a1d10..9ae5941864
--- a/frontend/src/pages/organization/IdentityDetailsByIDPage/components/ViewIdentityAuthModal/ViewIdentityUniversalAuthContent.tsx
+++ b/frontend/src/pages/organization/IdentityDetailsByIDPage/components/ViewIdentityAuthModal/ViewIdentityUniversalAuthContent.tsx
@@@ -89,12 -115,34 +90,13 @@@ export const ViewIdentityUniversalAuthC
<IdentityAuthFieldDisplay label="Client Secret Trusted IPs">
{data.clientSecretTrustedIps.map((ip) => ip.ipAddress).join(", ")}
</IdentityAuthFieldDisplay>
- <div className="col-span-2 mt-3 flex justify-between border-b border-mineshaft-500 pb-2">
- <span className="text-bunker-300">Lockout Options</span>
- <OrgPermissionCan I={OrgPermissionIdentityActions.Edit} a={OrgPermissionSubjects.Identity}>
- {(isAllowed) => (
- <Button
- isDisabled={!isAllowed || !lockedOutState || isClearLockoutsPending}
- size="xs"
- onClick={() => clearLockouts()}
- isLoading={isClearLockoutsPending}
- colorSchema="secondary"
- >
- Reset All Lockouts
- </Button>
- )}
- </OrgPermissionCan>
- </div>
- <IdentityAuthFieldDisplay label="Lockout">
- {data.lockoutEnabled ? "Enabled" : "Disabled"}
- </IdentityAuthFieldDisplay>
- <IdentityAuthFieldDisplay label="Lockout Threshold">
- {data.lockoutThreshold}
- </IdentityAuthFieldDisplay>
- <IdentityAuthFieldDisplay label="Lockout Duration">
- {ms(data.lockoutDurationSeconds * 1000, { long: true })}
- </IdentityAuthFieldDisplay>
- <IdentityAuthFieldDisplay label="Lockout Counter Reset">
- {ms(data.lockoutCounterResetSeconds * 1000, { long: true })}
- </IdentityAuthFieldDisplay>
+ <LockoutFields
+ identityId={identityId}
+ lockedOut={lockedOut}
+ clearLockoutsResult={clearLockoutsResult}
+ data={data}
++ onResetAllLockouts={onResetAllLockouts}
+ />
<div className="col-span-2 my-3">
<div className="mb-3 border-b border-mineshaft-500 pb-2">
<span className="text-bunker-300">Client ID</span>