Merge pull request #4685 from Infisical/ENG-3925

feat(pam): account credential rotation
This commit is contained in:
Sheen
2025-10-22 20:26:46 +08:00
committed by GitHub
45 changed files with 950 additions and 93 deletions
@@ -0,0 +1,61 @@
import { TPamAccountServiceFactory } from "@app/ee/services/pam-account/pam-account-service";
import { getConfig } from "@app/lib/config/env";
import { logger } from "@app/lib/logger";
import { QueueJobs, QueueName, TQueueServiceFactory } from "@app/queue";
type TPamAccountRotationServiceFactoryDep = {
queueService: TQueueServiceFactory;
pamAccountService: Pick<TPamAccountServiceFactory, "rotateAllDueAccounts">;
};
export type TPamAccountRotationServiceFactory = ReturnType<typeof pamAccountRotationServiceFactory>;
export const pamAccountRotationServiceFactory = ({
queueService,
pamAccountService
}: TPamAccountRotationServiceFactoryDep) => {
const appCfg = getConfig();
const init = async () => {
if (appCfg.isSecondaryInstance) {
return;
}
await queueService.stopRepeatableJob(
QueueName.PamAccountRotation,
QueueJobs.PamAccountRotation,
{ pattern: "0 * * * *", utc: true },
QueueName.PamAccountRotation // job id
);
await queueService.startPg<QueueName.PamAccountRotation>(
QueueJobs.PamAccountRotation,
async () => {
try {
logger.info(`${QueueName.PamAccountRotation}: pam account rotation task started`);
await pamAccountService.rotateAllDueAccounts();
logger.info(`${QueueName.PamAccountRotation}: pam account rotation task completed`);
} catch (error) {
logger.error(error, `${QueueName.PamAccountRotation}: pam account rotation failed`);
throw error;
}
},
{
batchSize: 1,
workerCount: 1,
pollingIntervalSeconds: 5 * 60
}
);
await queueService.schedulePg(
QueueJobs.PamAccountRotation,
"0 * * * *", // Schedule to run every hour
undefined,
{ tz: "UTC" }
);
};
return {
init
};
};