Skip to content

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

address claude review

Andreydc0a4ec0444a
diff --git a/backend/src/ee/routes/v1/pam-routers/pam-discovery-router.ts b/backend/src/ee/routes/v1/pam-routers/pam-discovery-router.ts
index 21deafca4a..1b92b307a5 100644
--- a/backend/src/ee/routes/v1/pam-routers/pam-discovery-router.ts
+++ b/backend/src/ee/routes/v1/pam-routers/pam-discovery-router.ts
@@ -12,6 +12,7 @@ import {
DISCOVERY_TYPE_CONFIGS,
PamDiscoveryTypeMetadataSchema
} from "@app/ee/services/pam-discovery/pam-discovery-schemas";
+import { MAX_ROTATIONS_PER_IMPORT } from "@app/ee/services/pam-discovery/pam-discovery-source-service";
import { PamAccountType } from "@app/ee/services/pam/pam-enums";
import { ApiDocsTags } from "@app/lib/api-docs/constants";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
@@ -466,7 +467,7 @@ export const registerPamDiscoveryRouter = async (server: FastifyZodProvider) =>
.uuid()
.optional()
.describe(
- "Account that rotates this account's password. When set, it becomes the account's rotation account and the password is rotated right after import"
+ `Account that rotates this account's password. When set, it becomes the account's rotation account and the password is rotated right after import. At most ${MAX_ROTATIONS_PER_IMPORT} accounts per request can set it`
)
})
.array()
diff --git a/backend/src/ee/services/pam-discovery/pam-discovery-source-service.ts b/backend/src/ee/services/pam-discovery/pam-discovery-source-service.ts
index 5f6ad54959..9b709c7cb4 100644
--- a/backend/src/ee/services/pam-discovery/pam-discovery-source-service.ts
+++ b/backend/src/ee/services/pam-discovery/pam-discovery-source-service.ts
@@ -95,6 +95,8 @@ const DISCOVERED_UPSERT_CONCURRENCY = 8;
const IMPORT_ROTATION_CONCURRENCY = 5;
+export const MAX_ROTATIONS_PER_IMPORT = 50;
+
const toResultMessage = (err: unknown, fallback: string) =>
err instanceof BadRequestError ||
err instanceof NotFoundError ||
@@ -757,6 +759,11 @@ export const pamDiscoverySourceServiceFactory = (deps: TPamDiscoverySourceServic
...ctx
}: TImportDiscoveredDTO) => {
await verifyAdmin(projectId, ctx);
+ if (accounts.filter((a) => a.rotationAccountId).length > MAX_ROTATIONS_PER_IMPORT) {
+ throw new BadRequestError({
+ message: `An import can rotate at most ${MAX_ROTATIONS_PER_IMPORT} accounts. Split the accounts into smaller imports.`
+ });
+ }
const source = await pamDiscoverySourceDAL.findById(sourceId);
if (!source || source.projectId !== projectId) {
throw new NotFoundError({ message: `Discovery source with ID '${sourceId}' not found` });
diff --git a/frontend/src/pages/pam/PamDiscoveryPage/components/ImportDiscoveredModal.tsx b/frontend/src/pages/pam/PamDiscoveryPage/components/ImportDiscoveredModal.tsx
index 8c9645030e..12b0df9949 100644
--- a/frontend/src/pages/pam/PamDiscoveryPage/components/ImportDiscoveredModal.tsx
+++ b/frontend/src/pages/pam/PamDiscoveryPage/components/ImportDiscoveredModal.tsx
@@ -24,6 +24,7 @@ import {
PamAccountAccessibilityIssue,
PamAccountType,
PamRotationStatus,
+ TImportPamDiscoveredAccountResult,
TPamDiscoveredAccount,
useImportPamDiscoveredAccounts,
useListPamAccounts,
@@ -32,6 +33,8 @@ import {
usePamAccountTypeMap
} from "@app/hooks/api/pam";
+const MAX_ROTATIONS_PER_IMPORT = 50;
+
type Props = {
isOpen: boolean;
onOpenChange: (open: boolean) => void;
@@ -53,6 +56,7 @@ export const ImportDiscoveredModal = ({
const [templateByType, setTemplateByType] = useState<Record<string, string>>({});
const [rotateOnImport, setRotateOnImport] = useState(false);
+ const [isImporting, setIsImporting] = useState(false);
// null is a cleared selection; a type with no entry falls back to the source's credential account
const [rotationAccountByType, setRotationAccountByType] = useState<Record<string, string | null>>(
{}
@@ -94,51 +98,64 @@ export const ImportDiscoveredModal = ({
setRotationAccountByType({});
};
- const handleImport = () => {
- importAccounts.mutate(
- {
- sourceId,
- folderId,
- accounts: accounts.map((a) => {
- const rotationAccountId =
- isRotating && isRotatablePamAccountType(a.accountType)
- ? rotationAccountIdFor(a.accountType)
- : null;
- return {
- discoveredAccountId: a.id,
- templateId: templateByType[a.accountType],
- ...(rotationAccountId ? { rotationAccountId } : {})
- };
- })
- },
- {
- onSuccess: (results) => {
- const imported = results.filter((r) => r.status === "imported").length;
- const failed = results.length - imported;
- const rotationFailures = results.filter(
- (r) => r.rotationStatus === PamRotationStatus.Failed
- );
- const rotationNote =
- rotationFailures.length > 0
- ? `. ${rotationFailures.length} could not be rotated: ${rotationFailures[0].rotationMessage}`
- : "";
- createNotification({
- type: failed > 0 || rotationFailures.length > 0 ? "info" : "success",
- text: `Imported ${imported} account${imported === 1 ? "" : "s"}${failed > 0 ? `, ${failed} failed` : ""}${rotationNote}`
- });
- reset();
- onImported();
- onOpenChange(false);
- }
+ const handleImport = async () => {
+ const items = accounts.map((a) => {
+ const rotationAccountId =
+ isRotating && isRotatablePamAccountType(a.accountType)
+ ? rotationAccountIdFor(a.accountType)
+ : null;
+ return {
+ discoveredAccountId: a.id,
+ templateId: templateByType[a.accountType],
+ ...(rotationAccountId ? { rotationAccountId } : {})
+ };
+ });
+ const batches = isRotating
+ ? Array.from({ length: Math.ceil(items.length / MAX_ROTATIONS_PER_IMPORT) }, (_, i) =>
+ items.slice(i * MAX_ROTATIONS_PER_IMPORT, (i + 1) * MAX_ROTATIONS_PER_IMPORT)
+ )
+ : [items];
+
+ const results: TImportPamDiscoveredAccountResult[] = [];
+ setIsImporting(true);
+ try {
+ for (const batch of batches) {
+ // eslint-disable-next-line no-await-in-loop
+ const batchResults = await importAccounts.mutateAsync({
+ sourceId,
+ folderId,
+ accounts: batch
+ });
+ results.push(...batchResults);
}
- );
+ } catch {
+ // A failed request returns a 4xx that the global request handler surfaces as a toast
+ return;
+ } finally {
+ setIsImporting(false);
+ }
+
+ const imported = results.filter((r) => r.status === "imported").length;
+ const failed = results.length - imported;
+ const rotationFailures = results.filter((r) => r.rotationStatus === PamRotationStatus.Failed);
+ const rotationNote =
+ rotationFailures.length > 0
+ ? `. ${rotationFailures.length} could not be rotated: ${rotationFailures[0].rotationMessage}`
+ : "";
+ createNotification({
+ type: failed > 0 || rotationFailures.length > 0 ? "info" : "success",
+ text: `Imported ${imported} account${imported === 1 ? "" : "s"}${failed > 0 ? `, ${failed} failed` : ""}${rotationNote}`
+ });
+ reset();
+ onImported();
+ onOpenChange(false);
};
const canImport = Boolean(folderId) && accountTypes.every((type) => templateByType[type]);
return (
<Dialog open={isOpen} onOpenChange={onOpenChange}>
- <DialogContent className="max-w-xl">
+ <DialogContent className="max-w-xl" isPending={isImporting}>
<DialogHeader>
<DialogTitle>
Import {accounts.length} Account{accounts.length === 1 ? "" : "s"}
@@ -252,7 +269,7 @@ export const ImportDiscoveredModal = ({
type="button"
variant="pam"
isDisabled={!canImport}
- isPending={importAccounts.isPending}
+ isPending={isImporting}
onClick={handleImport}
>
Import