Skip to content

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

misc: comments

Sheen Capadngan55bf53544e40
diff --git a/backend/src/ee/routes/v1/pam-account-routers/pam-account-router.ts b/backend/src/ee/routes/v1/pam-account-routers/pam-account-router.ts
index a232a91a0a..69ed9439d8 100644
--- a/backend/src/ee/routes/v1/pam-account-routers/pam-account-router.ts
+++ b/backend/src/ee/routes/v1/pam-account-routers/pam-account-router.ts
@@ -166,18 +166,16 @@ export const registerPamAccountRouter = async (server: FastifyZodProvider) => {
accountId: z.string().uuid()
}),
response: {
- 202: z.object({
- success: z.boolean(),
- accountId: z.string().uuid()
+ 200: z.object({
+ account: SanitizedAccountSchema
})
}
},
onRequest: verifyAuth([AuthMode.JWT]),
- handler: async (req, res) => {
- await server.services.pamAccount.triggerManualRotation(req.params.accountId, req.permission);
+ handler: async (req) => {
+ const account = await server.services.pamAccount.triggerManualRotation(req.params.accountId, req.permission);
- void res.status(202);
- return { success: true, accountId: req.params.accountId };
+ return { account };
}
});
diff --git a/backend/src/ee/services/pam-account/pam-account-service.ts b/backend/src/ee/services/pam-account/pam-account-service.ts
index 36683ff74c..926ba4d8bf 100644
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@ -1346,11 +1346,12 @@ export const pamAccountServiceFactory = ({
throw new BadRequestError({ message: "Account is already being rotated" });
}
- void rotateAccount(account).catch((err) => {
- logger.error(err, `Background rotation failed for account [accountId=${accountId}]`);
- });
+ await rotateAccount(account);
+
+ const updatedAccount = await pamAccountDAL.findById(accountId);
+ if (!updatedAccount) throw new NotFoundError({ message: `Account with ID '${accountId}' not found` });
- return { accountId };
+ return updatedAccount;
};
return {
diff --git a/backend/src/ee/services/pam-resource/shared/dependency-sync-fns.ts b/backend/src/ee/services/pam-resource/shared/dependency-sync-fns.ts
index 2999f1daee..af3780b91b 100644
--- a/backend/src/ee/services/pam-resource/shared/dependency-sync-fns.ts
+++ b/backend/src/ee/services/pam-resource/shared/dependency-sync-fns.ts
@@ -1,3 +1,4 @@
+import pLimit from "p-limit";
import RE2 from "re2";
import { runPowershell } from "winrm-client";
@@ -15,6 +16,8 @@ import { decryptResource } from "../pam-resource-fns";
import { TPostRotateContext } from "../pam-resource-types";
import { TWindowsResourceConnectionDetails } from "../windows-server/windows-server-resource-types";
+const DEPENDENCY_SYNC_RESOURCE_CONCURRENCY = 5;
+
// Sanitize a string for safe use inside PowerShell single-quoted strings:
// - doubles single quotes (PowerShell escape)
// - strips newlines/carriage returns
@@ -110,6 +113,12 @@ type TWinrmConfig = {
winrmTlsServerName?: string;
};
+export type TDependencySyncResult = {
+ total: number;
+ succeeded: number;
+ failed: number;
+};
+
export const syncDependenciesAfterRotation = async ({
accountId,
newCredentials,
@@ -120,10 +129,10 @@ export const syncDependenciesAfterRotation = async ({
gatewayId,
resolveHostname,
formatWinrmUsername
-}: TSyncDependenciesParams) => {
+}: TSyncDependenciesParams): Promise<TDependencySyncResult> => {
const allDeps = await ctx.pamAccountDependenciesDAL.findByAccountId(accountId);
const enabledDeps = allDeps.filter((d) => d.isRotationSyncEnabled);
- if (!enabledDeps.length) return;
+ if (!enabledDeps.length) return { total: 0, succeeded: 0, failed: 0 };
const grouped = groupBy(enabledDeps, (d) => d.resourceId);
@@ -145,6 +154,10 @@ export const syncDependenciesAfterRotation = async ({
return encryptor;
};
+ // Track success/failure counts
+ let succeededCount = 0;
+ let failedCount = 0;
+
const failAllDeps = async (deps: typeof enabledDeps, msg: string) => {
let encryptedMsg: Buffer | null = null;
try {
@@ -161,94 +174,143 @@ export const syncDependenciesAfterRotation = async ({
})
)
);
+ failedCount += deps.length;
};
+ const limit = pLimit(DEPENDENCY_SYNC_RESOURCE_CONCURRENCY);
+
await Promise.all(
- Object.entries(grouped).map(async ([resourceId, deps]) => {
- const resource = resourceMap.get(resourceId);
- if (!resource) {
- const msg = `Resource ${resourceId} not found`;
- logger.warn(`[DependencySync] ${msg}, skipping`);
- await failAllDeps(deps, msg);
- return;
- }
-
- // Get hostname and WinRM config from the target resource's connection details
- let hostname: string | null = null;
- let winrmConfig: TWinrmConfig = {
- winrmPort: 5986,
- useWinrmHttps: true,
- winrmRejectUnauthorized: true
- };
-
- try {
- const decrypted = await decryptResource(resource, projectId, ctx.kmsService);
- const connDetails = decrypted.connectionDetails as TWindowsResourceConnectionDetails;
- hostname = connDetails.hostname;
- winrmConfig = {
- winrmPort: connDetails.winrmPort,
- useWinrmHttps: connDetails.useWinrmHttps,
- winrmRejectUnauthorized: connDetails.winrmRejectUnauthorized,
- winrmCaCert: connDetails.winrmCaCert,
- winrmTlsServerName: connDetails.winrmTlsServerName
+ Object.entries(grouped).map(([resourceId, deps]) =>
+ limit(async () => {
+ const resource = resourceMap.get(resourceId);
+ if (!resource) {
+ const msg = `Resource ${resourceId} not found`;
+ logger.warn(`[DependencySync] ${msg}, skipping`);
+ await failAllDeps(deps, msg);
+ return;
+ }
+
+ // Get hostname and WinRM config from the target resource's connection details
+ let hostname: string | null = null;
+ let winrmConfig: TWinrmConfig = {
+ winrmPort: 5986,
+ useWinrmHttps: true,
+ winrmRejectUnauthorized: true
};
- } catch (err) {
- logger.error(err, `[DependencySync] Failed to decrypt resource ${resourceId}`);
- await failAllDeps(deps, `Failed to decrypt resource connection details`);
- return;
- }
-
- if (!hostname) {
- const msg = `No hostname found for resource ${resourceId}`;
- logger.warn(`[DependencySync] ${msg}, skipping`);
- await failAllDeps(deps, msg);
- return;
- }
-
- const winrmUsername = formatWinrmUsername
- ? formatWinrmUsername(rotationCredentials.username, hostname, resource.resourceType)
- : rotationCredentials.username;
-
- // Resolve hostname — use custom resolver (e.g. DC DNS) if provided, otherwise use as-is
- let resolvedHost = hostname;
- if (resolveHostname) {
+
try {
- resolvedHost = await resolveHostname(hostname);
+ const decrypted = await decryptResource(resource, projectId, ctx.kmsService);
+ const connDetails = decrypted.connectionDetails as TWindowsResourceConnectionDetails;
+ hostname = connDetails.hostname;
+ winrmConfig = {
+ winrmPort: connDetails.winrmPort,
+ useWinrmHttps: connDetails.useWinrmHttps,
+ winrmRejectUnauthorized: connDetails.winrmRejectUnauthorized,
+ winrmCaCert: connDetails.winrmCaCert,
+ winrmTlsServerName: connDetails.winrmTlsServerName
+ };
} catch (err) {
- logger.warn(err, `[DependencySync] Failed to resolve hostname ${hostname}, using original`);
+ logger.error(err, `[DependencySync] Failed to decrypt resource ${resourceId}`);
+ await failAllDeps(deps, `Failed to decrypt resource connection details`);
+ return;
}
- }
- const [targetHost] = await verifyHostInputValidity({
- host: resolvedHost,
- isGateway: true,
- isDynamicSecret: false
- });
+ if (!hostname) {
+ const msg = `No hostname found for resource ${resourceId}`;
+ logger.warn(`[DependencySync] ${msg}, skipping`);
+ await failAllDeps(deps, msg);
+ return;
+ }
- // eslint-disable-next-line no-restricted-syntax
- for (const dep of deps) {
- try {
- // eslint-disable-next-line no-await-in-loop
- await ctx.pamAccountDependenciesDAL.updateById(dep.id, { syncStatus: PamDependencySyncStatus.Pending });
+ const winrmUsername = formatWinrmUsername
+ ? formatWinrmUsername(rotationCredentials.username, hostname, resource.resourceType)
+ : rotationCredentials.username;
+
+ // Resolve hostname — use custom resolver (e.g. DC DNS) if provided, otherwise use as-is
+ let resolvedHost = hostname;
+ if (resolveHostname) {
+ try {
+ resolvedHost = await resolveHostname(hostname);
+ } catch (err) {
+ logger.warn(err, `[DependencySync] Failed to resolve hostname ${hostname}, using original`);
+ }
+ }
+
+ const [targetHost] = await verifyHostInputValidity({
+ host: resolvedHost,
+ isGateway: true,
+ isDynamicSecret: false
+ });
+
+ // Get gateway connection once for all dependencies on this resource
+ const connectionDetails = await gatewayV2Service.getPlatformConnectionDetailsByGatewayId({
+ gatewayId,
+ targetHost,
+ targetPort: winrmConfig.winrmPort
+ });
+
+ if (!connectionDetails) {
+ const msg = "Unable to establish gateway connection for dependency sync";
+ logger.warn(`[DependencySync] ${msg} [resourceId=${resourceId}]`);
+ await failAllDeps(deps, msg);
+ return;
+ }
- const script = buildDependencySyncScript(dep, newCredentials.username, newCredentials.password);
+ // Process dependencies sequentially for this resource (same WinRM connection target)
+ // eslint-disable-next-line no-restricted-syntax
+ for (const dep of deps) {
+ try {
+ // eslint-disable-next-line no-await-in-loop
+ await ctx.pamAccountDependenciesDAL.updateById(dep.id, { syncStatus: PamDependencySyncStatus.Pending });
- // eslint-disable-next-line no-await-in-loop
- const depConnectionDetails = await gatewayV2Service.getPlatformConnectionDetailsByGatewayId({
- gatewayId,
- targetHost,
- targetPort: winrmConfig.winrmPort
- });
+ const script = buildDependencySyncScript(dep, newCredentials.username, newCredentials.password);
- if (!depConnectionDetails) {
- const msg = "Unable to establish gateway connection for dependency sync";
- logger.warn(`[DependencySync] ${msg} [dep=${dep.name}]`);
+ // eslint-disable-next-line no-await-in-loop
+ await withGatewayV2Proxy(
+ async (proxyPort) => {
+ await runPowershell(
+ script,
+ "localhost",
+ winrmUsername,
+ rotationCredentials.password,
+ proxyPort,
+ winrmConfig.useWinrmHttps,
+ winrmConfig.winrmRejectUnauthorized,
+ winrmConfig.winrmCaCert,
+ winrmConfig.winrmTlsServerName
+ );
+ },
+ {
+ protocol: GatewayProxyProtocol.Tcp,
+ relayHost: connectionDetails.relayHost,
+ gateway: connectionDetails.gateway,
+ relay: connectionDetails.relay
+ }
+ );
+
+ // eslint-disable-next-line no-await-in-loop
+ await ctx.pamAccountDependenciesDAL.updateById(dep.id, {
+ syncStatus: PamDependencySyncStatus.Success,
+ lastSyncedAt: new Date(),
+ encryptedLastSyncMessage: null
+ });
+
+ succeededCount += 1;
+ logger.info(`[DependencySync] Synced ${dep.dependencyType} '${dep.name}' on resource ${resourceId}`);
+ } catch (error) {
+ const errorMessage = error instanceof Error ? error.message : String(error);
+ logger.error(
+ error,
+ `[DependencySync] Failed to sync ${dep.dependencyType} '${dep.name}' on resource ${resourceId}`
+ );
let encryptedLastSyncMessage: Buffer | null = null;
try {
// eslint-disable-next-line no-await-in-loop
const enc = await getEncryptor();
- const { cipherTextBlob } = enc({ plainText: Buffer.from(msg) });
+ const { cipherTextBlob } = enc({
+ plainText: Buffer.from(errorMessage)
+ });
encryptedLastSyncMessage = cipherTextBlob;
} catch (err) {
logger.error(err, `[DependencySync] Failed to encrypt error message for [depId=${dep.id}]`);
@@ -260,67 +322,16 @@ export const syncDependenciesAfterRotation = async ({
encryptedLastSyncMessage
});
- // eslint-disable-next-line no-continue
- continue;
- }
-
- // eslint-disable-next-line no-await-in-loop
- await withGatewayV2Proxy(
- async (proxyPort) => {
- await runPowershell(
- script,
- "localhost",
- winrmUsername,
- rotationCredentials.password,
- proxyPort,
- winrmConfig.useWinrmHttps,
- winrmConfig.winrmRejectUnauthorized,
- winrmConfig.winrmCaCert,
- winrmConfig.winrmTlsServerName
- );
- },
- {
- protocol: GatewayProxyProtocol.Tcp,
- relayHost: depConnectionDetails.relayHost,
- gateway: depConnectionDetails.gateway,
- relay: depConnectionDetails.relay
- }
- );
-
- // eslint-disable-next-line no-await-in-loop
- await ctx.pamAccountDependenciesDAL.updateById(dep.id, {
- syncStatus: PamDependencySyncStatus.Success,
- lastSyncedAt: new Date(),
- encryptedLastSyncMessage: null
- });
-
- logger.info(`[DependencySync] Synced ${dep.dependencyType} '${dep.name}' on resource ${resourceId}`);
- } catch (error) {
- const errorMessage = error instanceof Error ? error.message : String(error);
- logger.error(
- error,
- `[DependencySync] Failed to sync ${dep.dependencyType} '${dep.name}' on resource ${resourceId}`
- );
-
- let encryptedLastSyncMessage: Buffer | null = null;
- try {
- // eslint-disable-next-line no-await-in-loop
- const enc = await getEncryptor();
- const { cipherTextBlob } = enc({
- plainText: Buffer.from(errorMessage)
- });
- encryptedLastSyncMessage = cipherTextBlob;
- } catch (err) {
- logger.error(err, `[DependencySync] Failed to encrypt error message for [depId=${dep.id}]`);
+ failedCount += 1;
}
-
- // eslint-disable-next-line no-await-in-loop
- await ctx.pamAccountDependenciesDAL.updateById(dep.id, {
- syncStatus: PamDependencySyncStatus.Failed,
- encryptedLastSyncMessage
- });
}
- }
- })
+ })
+ )
);
+
+ return {
+ total: enabledDeps.length,
+ succeeded: succeededCount,
+ failed: failedCount
+ };
};
diff --git a/backend/src/ee/services/pam-resource/shared/dns-over-dc.ts b/backend/src/ee/services/pam-resource/shared/dns-over-dc.ts
index 250a957260..8e10e35b9a 100644
--- a/backend/src/ee/services/pam-resource/shared/dns-over-dc.ts
+++ b/backend/src/ee/services/pam-resource/shared/dns-over-dc.ts
@@ -30,10 +30,15 @@ export const resolveDnsTcp = (hostname: string, proxyPort: number): Promise<stri
if (responseData.length >= 2) {
const msgLen = responseData.readUInt16BE(0);
if (responseData.length >= 2 + msgLen) {
- const response = dnsPacket.streamDecode(responseData);
- const aRecord = response.answers?.find((a) => a.type === "A");
- socket.destroy();
- resolve(aRecord && "data" in aRecord ? (aRecord.data as string) : null);
+ try {
+ const response = dnsPacket.streamDecode(responseData);
+ const aRecord = response.answers?.find((a) => a.type === "A");
+ socket.destroy();
+ resolve(aRecord && "data" in aRecord ? (aRecord.data as string) : null);
+ } catch {
+ socket.destroy();
+ resolve(null);
+ }
}
}
});
diff --git a/backend/src/ee/services/secret-rotation-v2/shared/utils/index.ts b/backend/src/ee/services/secret-rotation-v2/shared/utils/index.ts
index c050861949..4122abfda2 100644
--- a/backend/src/ee/services/secret-rotation-v2/shared/utils/index.ts
+++ b/backend/src/ee/services/secret-rotation-v2/shared/utils/index.ts
@@ -1,9 +1,5 @@
-import RE2 from "re2";
-
import { crypto } from "@app/lib/crypto/cryptography";
-const DOUBLE_QUOTE_RE = new RE2('"', "g");
-
type TPasswordRequirements = {
length: number;
required: {
@@ -30,14 +26,11 @@ export const generatePassword = (passwordRequirements?: TPasswordRequirements) =
try {
const { length, required, allowedSymbols } = passwordRequirements ?? DEFAULT_PASSWORD_REQUIREMENTS;
- // Strip double quotes from symbols — they break AD unicodePwd encoding and PowerShell string contexts
- const safeSymbols = DOUBLE_QUOTE_RE.replace(allowedSymbols || "-_.~!*", "");
-
const chars = {
lowercase: "abcdefghijklmnopqrstuvwxyz",
uppercase: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
digits: "0123456789",
- symbols: safeSymbols
+ symbols: allowedSymbols || "-_.~!*"
};
const parts: string[] = [];
diff --git a/frontend/src/hooks/api/pam/mutations.tsx b/frontend/src/hooks/api/pam/mutations.tsx
index 85e1f70aba..0a20f02cee 100644
--- a/frontend/src/hooks/api/pam/mutations.tsx
+++ b/frontend/src/hooks/api/pam/mutations.tsx
@@ -346,13 +346,16 @@ export const useManualRotateAccount = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async ({ accountId }: { accountId: string }) => {
- const { data } = await apiRequest.post<{ success: boolean; accountId: string }>(
+ const { data } = await apiRequest.post<{ account: TPamAccount }>(
`/api/v1/pam/accounts/${accountId}/rotate`
);
- return data;
+ return data.account;
},
- onSuccess: (_, { accountId }) => {
- queryClient.invalidateQueries({ queryKey: pamKeys.getAccount(accountId) });
+ onSuccess: (account) => {
+ queryClient.setQueryData(pamKeys.getAccount(account.id), account);
+ queryClient.invalidateQueries({
+ queryKey: pamKeys.listAccounts({ projectId: account.projectId })
+ });
}
});
};
diff --git a/frontend/src/pages/pam/PamAccountByIDPage/PamAccountByIDPage.tsx b/frontend/src/pages/pam/PamAccountByIDPage/PamAccountByIDPage.tsx
index ec57f153c8..e0424959ec 100644
--- a/frontend/src/pages/pam/PamAccountByIDPage/PamAccountByIDPage.tsx
+++ b/frontend/src/pages/pam/PamAccountByIDPage/PamAccountByIDPage.tsx
@@ -170,8 +170,18 @@ const PageContent = () => {
);
try {
- createNotification({ text: "Credential rotation triggered", type: "success" });
- await rotateAccount.mutateAsync({ accountId: account.id });
+ const updatedAccount = await rotateAccount.mutateAsync({ accountId: account.id });
+
+ if (updatedAccount.rotationStatus === PamAccountRotationStatus.Success) {
+ createNotification({ text: "Credential rotation completed successfully", type: "success" });
+ } else if (updatedAccount.rotationStatus === PamAccountRotationStatus.PartialSuccess) {
+ createNotification({
+ text: "Credential rotation completed with warnings",
+ type: "warning"
+ });
+ } else if (updatedAccount.rotationStatus === PamAccountRotationStatus.Failed) {
+ createNotification({ text: "Credential rotation failed", type: "error" });
+ }
} catch {
// Revert optimistic update on failure
queryClient.invalidateQueries({ queryKey: pamKeys.getAccount(account.id) });
diff --git a/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/MetadataFields.tsx b/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/MetadataFields.tsx
index ede16a6a73..e998f4fd04 100644
--- a/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/MetadataFields.tsx
+++ b/frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/MetadataFields.tsx
@@ -4,5 +4,5 @@ import { MetadataForm } from "@app/pages/secret-manager/SecretDashboardPage/comp
export const MetadataFields = () => {
const { control } = useFormContext();
- return <MetadataForm control={control} title={undefined} />;
+ return <MetadataForm control={control} />;
};
diff --git a/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceAccountsSection.tsx b/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceAccountsSection.tsx
index 59538d3108..fae0315184 100644
--- a/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceAccountsSection.tsx
+++ b/frontend/src/pages/pam/PamResourceByIDPage/components/PamResourceAccountsSection.tsx
@@ -209,14 +209,32 @@ export const PamResourceAccountsSection = ({ resource }: Props) => {
const handleRotateAccount = async (accountId: string) => {
try {
setRotatingAccountIds((prev) => new Set(prev).add(accountId));
- await manualRotate.mutateAsync({ accountId });
- createNotification({ text: "Account rotation triggered", type: "success" });
+ const updatedAccount = await manualRotate.mutateAsync({ accountId });
+
+ // Clear from local rotating state since we now have the final status
+ setRotatingAccountIds((prev) => {
+ const next = new Set(prev);
+ next.delete(accountId);
+ return next;
+ });
+
+ if (updatedAccount.rotationStatus === PamAccountRotationStatus.Success) {
+ createNotification({ text: "Credential rotation completed successfully", type: "success" });
+ } else if (updatedAccount.rotationStatus === PamAccountRotationStatus.PartialSuccess) {
+ createNotification({
+ text: "Credential rotation completed with warnings",
+ type: "warning"
+ });
+ } else if (updatedAccount.rotationStatus === PamAccountRotationStatus.Failed) {
+ createNotification({ text: "Credential rotation failed", type: "error" });
+ }
} catch {
setRotatingAccountIds((prev) => {
const next = new Set(prev);
next.delete(accountId);
return next;
});
+ createNotification({ text: "Failed to trigger rotation", type: "error" });
}
};
diff --git a/frontend/src/pages/pam/PamResourceByIDPage/components/rotation-policy/RotationRuleCard.tsx b/frontend/src/pages/pam/PamResourceByIDPage/components/rotation-policy/RotationRuleCard.tsx
index f8d6022732..a920b7db76 100644
--- a/frontend/src/pages/pam/PamResourceByIDPage/components/rotation-policy/RotationRuleCard.tsx
+++ b/frontend/src/pages/pam/PamResourceByIDPage/components/rotation-policy/RotationRuleCard.tsx
@@ -109,7 +109,7 @@ export const RotationRuleCard = ({
</FieldContent>
</Field>
<Field>
- <FieldLabel>Account Pattern</FieldLabel>
+ <FieldLabel>Account Name Pattern</FieldLabel>
<FieldContent>
<UnstableInput
value={localPattern}