Skip to content

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

clear cached secret reads when a project is deleted or restored

DimitrisStaratzis8de7ec4dc4f2
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index ac8574ac4c..4dfb8cd352 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -2560,7 +2560,8 @@ export const registerRoutes = async (
projectAccessRequestDAL,
usageMeteringService,
dynamicSecretLeaseDAL,
- dynamicSecretQueueService
+ dynamicSecretQueueService,
+ secretV2BridgeDAL
});
const projectEnvQueue = projectEnvQueueFactory({
diff --git a/backend/src/services/project/project-service.ts b/backend/src/services/project/project-service.ts
index 8324c23c9c..d4f2835010 100644
--- a/backend/src/services/project/project-service.ts
+++ b/backend/src/services/project/project-service.ts
@@ -69,6 +69,7 @@ import { OrgServiceActor, TProjectPermission } from "@app/lib/types";
import { AgentVaultIdentities, PamIdentities, SecretIdentities } from "@app/services/license-client";
import { TUsageMeteringServiceFactory } from "@app/services/license-client/usage";
import { TPkiSubscriberDALFactory } from "@app/services/pki-subscriber/pki-subscriber-dal";
+import { TSecretV2BridgeDALFactory } from "@app/services/secret-v2-bridge/secret-v2-bridge-dal";
import { TGroupDALFactory } from "../../ee/services/group/group-dal";
import { ActorAuthMethod, ActorType } from "../auth/auth-type";
@@ -215,6 +216,7 @@ type TProjectServiceFactoryDep = {
TDynamicSecretLeaseQueueServiceFactory,
"setLeaseRevocation" | "unsetRestoredLeaseRevocation"
>;
+ secretV2BridgeDAL: Pick<TSecretV2BridgeDALFactory, "invalidateSecretCacheByProjectId">;
};
export type TProjectServiceFactory = ReturnType<typeof projectServiceFactory>;
@@ -267,7 +269,8 @@ export const projectServiceFactory = ({
projectAccessRequestDAL,
usageMeteringService,
dynamicSecretLeaseDAL,
- dynamicSecretQueueService
+ dynamicSecretQueueService,
+ secretV2BridgeDAL
}: TProjectServiceFactoryDep) => {
// The (orgId, slug) unique index already refuses a taken slug; this only names the cause when the holder is
// a project pending deletion.
@@ -931,6 +934,8 @@ export const projectServiceFactory = ({
// refresh the cached plan so the freed workspace slot is reflected immediately
// (countOfOrgProjects now excludes soft-deleted projects)
await keyStore.deleteItem(KeyStorePrefixes.LicenseCloudPlan(actorOrgId));
+ // Cached reads of this project and of the projects it shares with would keep serving its secrets.
+ await secretV2BridgeDAL.invalidateSecretCacheByProjectId(project.id);
// The soft-deleted project drops out of the meters' counts, so its members no longer count.
usageMeteringService.emit(project.orgId, SecretIdentities.key);
usageMeteringService.emit(project.orgId, PamIdentities.key);
@@ -1055,6 +1060,8 @@ export const projectServiceFactory = ({
}
await keyStore.deleteItem(KeyStorePrefixes.LicenseCloudPlan(project.orgId));
+ // Cached reads from before the deletion can hold imports from projects deleted since.
+ await secretV2BridgeDAL.invalidateSecretCacheByProjectId(project.id);
usageMeteringService.emit(project.orgId, SecretIdentities.key);
usageMeteringService.emit(project.orgId, PamIdentities.key);
usageMeteringService.emit(project.orgId, AgentVaultIdentities.key);