Skip to content

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

cancel a lease's restore revocation when it is renewed or revoked

DimitrisStaratzisb5c39936075e
diff --git a/backend/src/ee/services/dynamic-secret-lease/dynamic-secret-lease-queue.ts b/backend/src/ee/services/dynamic-secret-lease/dynamic-secret-lease-queue.ts
index 7e4e87be8d..001aee17f3 100644
--- a/backend/src/ee/services/dynamic-secret-lease/dynamic-secret-lease-queue.ts
+++ b/backend/src/ee/services/dynamic-secret-lease/dynamic-secret-lease-queue.ts
@@ -47,6 +47,10 @@ export type TDynamicSecretLeaseQueueServiceFactory = {
const MAX_REVOCATION_RETRY_COUNT = 3;
+// Restoring a project re-queues revocation of its expired leases under this id, so an older retry, which stops the
+// job under the lease id when it gives up, can't cancel it.
+export const getRestoredLeaseRevocationJobId = (leaseId: string) => `${leaseId}-restore`;
+
export const dynamicSecretLeaseQueueServiceFactory = ({
queueService,
dynamicSecretDAL,
@@ -93,6 +97,7 @@ export const dynamicSecretLeaseQueueServiceFactory = ({
const unsetLeaseRevocation = async (leaseId: string) => {
await queueService.stopJobById(QueueName.DynamicSecretRevocation, leaseId);
+ await queueService.stopJobById(QueueName.DynamicSecretRevocation, getRestoredLeaseRevocationJobId(leaseId));
};
const queueFailedRevocation = async (leaseId: string, dynamicSecretId: string) => {
diff --git a/backend/src/services/project/project-service.ts b/backend/src/services/project/project-service.ts
index 76465012a8..5849a0b16c 100644
--- a/backend/src/services/project/project-service.ts
+++ b/backend/src/services/project/project-service.ts
@@ -18,7 +18,10 @@ import {
} from "@app/db/schemas";
import { isWithinPlanAuditLogRetention } from "@app/ee/services/audit-log/audit-log-retention-fns";
import { TDynamicSecretLeaseDALFactory } from "@app/ee/services/dynamic-secret-lease/dynamic-secret-lease-dal";
-import { TDynamicSecretLeaseQueueServiceFactory } from "@app/ee/services/dynamic-secret-lease/dynamic-secret-lease-queue";
+import {
+ getRestoredLeaseRevocationJobId,
+ TDynamicSecretLeaseQueueServiceFactory
+} from "@app/ee/services/dynamic-secret-lease/dynamic-secret-lease-queue";
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
import {
OrgPermissionActions,
@@ -969,8 +972,7 @@ export const projectServiceFactory = ({
// Revoking a lease that expired while the project was deleted fails because the project can't be
// resolved, and its retries may have run out, so queue those revocations again. They're queued
// before the restore so a queue failure leaves the project deleted and the restore retryable, and
- // delayed so they run after it commits. Their own job id keeps an older retry, which stops the job
- // under the lease id when it gives up, from cancelling them.
+ // delayed so they run after it commits.
const expiredLeases = await dynamicSecretLeaseDAL.findExpiredByProjectId(project.id);
const revokeAt = new Date(Date.now() + 60_000);
await Promise.all(
@@ -979,7 +981,7 @@ export const projectServiceFactory = ({
lease.id,
lease.dynamicSecretId,
revokeAt,
- `${lease.id}-restore`
+ getRestoredLeaseRevocationJobId(lease.id)
)
)
);