Skip to content

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

Address greptile comments

Carlos Monastyrski2ccc29f489ed
diff --git a/backend/src/ee/services/pam-account-rotation/pam-account-rotation-service.ts b/backend/src/ee/services/pam-account-rotation/pam-account-rotation-service.ts
index 9a3a5776d4..c0445dff2f 100644
--- a/backend/src/ee/services/pam-account-rotation/pam-account-rotation-service.ts
+++ b/backend/src/ee/services/pam-account-rotation/pam-account-rotation-service.ts
@@ -371,23 +371,42 @@ export const pamAccountRotationServiceFactory = (deps: TPamAccountRotationServic
throw new BadRequestError({ message: "Credential rotation is not supported for this account type" });
}
- if (rotationAccountId && rotationAccountId !== accountId) {
- const rotator = await pamAccountDAL.findByIdWithDetails(rotationAccountId);
- if (!rotator || rotator.projectId !== projectId) {
- throw new BadRequestError({ message: "Rotation account not found in this project" });
+ if (rotationAccountId) {
+ if (account.credentialConfigured) {
+ const targetCredentials = await decryptSqlCredentials(
+ projectId,
+ account.accountType,
+ account.encryptedCredentials
+ );
+ PAM_ROTATION_FACTORY_MAP[account.accountType].validateTarget({
+ accountType: account.accountType,
+ authMethod: targetCredentials.authMethod
+ });
}
- if (rotator.accountType !== account.accountType) {
- throw new BadRequestError({ message: "Rotation account must be the same type as this account" });
+
+ if (rotationAccountId !== accountId) {
+ const rotator = await pamAccountDAL.findByIdWithDetails(rotationAccountId);
+ if (!rotator || rotator.projectId !== projectId) {
+ throw new BadRequestError({ message: "Rotation account not found in this project" });
+ }
+ if (rotator.accountType !== account.accountType) {
+ throw new BadRequestError({ message: "Rotation account must be the same type as this account" });
+ }
+ // A delegated rotator authenticates with its own stored password, so it must have one, else every rotation
+ // fails in resolveAuthCredential and the account is scheduled into a permanent failure state.
+ if (!rotator.credentialConfigured) {
+ throw new BadRequestError({ message: "Rotation account has no stored credential to perform rotations" });
+ }
+ // Binding a rotator causes its credential to be used to authenticate rotations, so require credential access
+ // to it (not just metadata read): otherwise a caller could leverage a privileged account they can only see.
+ await checkAccount(
+ rotationAccountId,
+ rotator.folderId,
+ projectId,
+ ResourcePermissionPamResourceActions.ViewCredentials,
+ ctx
+ );
}
- // Binding a rotator causes its credential to be used to authenticate rotations, so require credential access
- // to it (not just metadata read): otherwise a caller could leverage a privileged account they can only see.
- await checkAccount(
- rotationAccountId,
- rotator.folderId,
- projectId,
- ResourcePermissionPamResourceActions.ViewCredentials,
- ctx
- );
}
// Set the rotation account and re-derive the schedule atomically, so a crash can't leave the account bound
diff --git a/backend/src/ee/services/pam-account-template/pam-account-template-service.ts b/backend/src/ee/services/pam-account-template/pam-account-template-service.ts
index db21c17d8f..30fa605f20 100644
--- a/backend/src/ee/services/pam-account-template/pam-account-template-service.ts
+++ b/backend/src/ee/services/pam-account-template/pam-account-template-service.ts
@@ -124,7 +124,9 @@ export const pamAccountTemplateServiceFactory = (deps: TPamAccountTemplateServic
throw new NotFoundError({ message: `Account template with ID '${templateId}' not found` });
}
- const { accountCount, ...rotationImpact } = await pamAccountTemplateDAL.getTemplateRotationStats(templateId);
+ const { accountCount, ...stats } = await pamAccountTemplateDAL.getTemplateRotationStats(templateId);
+ // rotationImpact only means something for rotatable types; a non-rotatable template rotates nothing regardless.
+ const rotationImpact = isRotatableAccountType(template.type) ? stats : { willRotate: 0, needsRotationAccount: 0 };
return { ...template, accountCount, rotationImpact };
};
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 f5775a3d94..175eb7ca80 100644
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@ -448,6 +448,8 @@ export const pamAccountServiceFactory = (deps: TPamAccountServiceFactoryDep) =>
await membershipDAL.delete({ $in: { id: ids } }, tx);
}
+ await pamAccountDAL.updateById(accountId, { rotationAccountId: null }, tx);
+
return pamAccountDAL.deleteById(accountId, tx);
});
} catch (err) {