Skip to content

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

fix(secret-sync): address latest review comments

Calvin44fb0985bc9a
diff --git a/backend/src/services/secret-sync/secret-sync-payload.test.ts b/backend/src/services/secret-sync/secret-sync-payload.test.ts
index b7605950e5..c84ea3a97b 100644
--- a/backend/src/services/secret-sync/secret-sync-payload.test.ts
+++ b/backend/src/services/secret-sync/secret-sync-payload.test.ts
@@ -118,6 +118,8 @@ describe("createSecretSyncPayload", () => {
environment: "dev"
});
+ expect(() => payload.flatten()).toThrow(/"DB_URL" in \/backend and \/backend\/api/);
+
const deduped = payload.dedupeConflicts();
expect(() => deduped.flatten()).not.toThrow();
diff --git a/backend/src/services/secret-sync/secret-sync-queue.ts b/backend/src/services/secret-sync/secret-sync-queue.ts
index e30dd39f22..42df37ebe4 100644
--- a/backend/src/services/secret-sync/secret-sync-queue.ts
+++ b/backend/src/services/secret-sync/secret-sync-queue.ts
@@ -839,8 +839,8 @@ export const secretSyncQueueFactory = ({
credentials
}
} as TSecretSyncWithCredentials,
- // A sync that has drifted into a duplicate-name state must still be removable: dedupe
- // before any provider's own flatten() call gets a chance to throw on it.
+ // We don't care about duplicates when removing secrets: a duplicate name still maps to
+ // the same destination key we're deleting either way.
payload.dedupeConflicts(),
{
appConnectionDAL,
diff --git a/backend/src/services/secret-sync/secret-sync-recursive-fns.ts b/backend/src/services/secret-sync/secret-sync-recursive-fns.ts
index d6177a08bf..7d36898a37 100644
--- a/backend/src/services/secret-sync/secret-sync-recursive-fns.ts
+++ b/backend/src/services/secret-sync/secret-sync-recursive-fns.ts
@@ -47,10 +47,6 @@ export const assertWithinSecretLimit = (count: number) => {
});
};
-// A secret path is just a folder's location written as a filesystem-style string, so "folder"
-// and "path" name the same node here; each folder has exactly one path and each path names
-// exactly one folder, so this never returns the same folder twice. Non-recursive: just the
-// source folder. Recursive: the source folder plus every folder beneath it.
export const getSyncedFolders = async ({
folderDAL,
projectEnvDAL,
diff --git a/backend/src/services/secret-sync/secret-sync-schemas.test.ts b/backend/src/services/secret-sync/secret-sync-schemas.test.ts
index 156b1bd55b..d7d42d180d 100644
--- a/backend/src/services/secret-sync/secret-sync-schemas.test.ts
+++ b/backend/src/services/secret-sync/secret-sync-schemas.test.ts
@@ -20,9 +20,7 @@ describe("BaseSyncOptionsSchema recursive", () => {
expect(result.success).toBe(true);
});
- // Importing would need to write each secret back into the subfolder it came from, which isn't
- // supported yet, so allowing this combination would squash every subfolder's secrets into the
- // sync's root folder instead. See RECURSIVE_SYNC_REFINEMENT.
+ // See RECURSIVE_SYNC_REFINEMENT.
test("rejects recursive combined with importing from the destination", () => {
const result = schema.safeParse({
initialSyncBehavior: SecretSyncInitialSyncBehavior.ImportPrioritizeSource,
diff --git a/backend/src/services/secret-sync/secret-sync-schemas.ts b/backend/src/services/secret-sync/secret-sync-schemas.ts
index 7bbd35b5c0..233cce8007 100644
--- a/backend/src/services/secret-sync/secret-sync-schemas.ts
+++ b/backend/src/services/secret-sync/secret-sync-schemas.ts
@@ -9,10 +9,8 @@ import { SecretSync, SecretSyncInitialSyncBehavior } from "@app/services/secret-
import { SECRET_SYNC_CONNECTION_MAP, SECRET_SYNC_NAME_MAP } from "@app/services/secret-sync/secret-sync-maps";
import { TSyncOptionsConfig } from "@app/services/secret-sync/secret-sync-types";
-// Importing would need to write each secret back into the subfolder it came from, which we don't
-// support yet (hierarchical writes to destinations that can represent folders are planned for a
-// later PR). Until then, allowing this combination would silently squash every subfolder's
-// secrets into the sync's root folder, restructuring the user's existing secrets tree.
+// We don't allow initial sync import combined with recursive, because it can change the shape of
+// how secrets are organized in Infisical, which would then influence future syncs.
const RECURSIVE_SYNC_REFINEMENT = {
path: ["recursive"],
message:
@@ -177,10 +175,5 @@ export const GenericUpdateSecretSyncFieldsSchema = <T extends AnyZodObject | und
.optional()
.describe(SecretSyncs.UPDATE(destination).secretPath),
isAutoSyncEnabled: z.boolean().optional().describe(SecretSyncs.UPDATE(destination).isAutoSyncEnabled),
- // Optional like every other field here, so an update can touch just the name or description
- // without resending sync options. This can't be used to sneak past
- // isRecursiveCombinationAllowed: initialSyncBehavior inside BaseSyncOptionsSchema stays
- // required, so a request that includes syncOptions at all must still submit a complete,
- // valid one.
syncOptions: BaseSyncOptionsSchema({ destination, syncOptionsConfig, merge, isUpdateSchema: true }).optional()
});