Skip to content

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

fix(secret-sync): keep cloudflare duplicate check strict

DimitrisStaratzisa4bb8f49e2cc
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index b54063da6d..b7371d31a6 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -3509,7 +3509,7 @@ export const SecretSyncs = {
CLOUDFLARE_WORKERS: {
scriptId: "The ID of the Cloudflare Workers script to sync secrets to.",
variableType:
- "The type of variable to sync secrets as: secret_text, plain_text or json. Infisical replaces any secret or variable of the same name with this type and only deletes variables of this type. If omitted, secrets are synced as secret_text but keys that already exist as plaintext or JSON variables are skipped."
+ "The type of variable to sync secrets as: secret_text (the default for new syncs), plain_text or json. Infisical converts a secret or variable of the same name to this type, except that with syncNonSecretBindings on, existing plaintext and JSON variables keep their type. Infisical only deletes variables of this type. Syncs created before this option existed have no type and skip keys that already exist as plaintext or JSON variables."
},
CLOUDFLARE_SECRETS_STORE: {
storeId: "The ID of the Cloudflare Secrets Store to sync secrets to.",
diff --git a/backend/src/server/routes/v1/secret-sync-routers/secret-sync-endpoints.ts b/backend/src/server/routes/v1/secret-sync-routers/secret-sync-endpoints.ts
index 835bda2696..0da1899d4b 100644
--- a/backend/src/server/routes/v1/secret-sync-routers/secret-sync-endpoints.ts
+++ b/backend/src/server/routes/v1/secret-sync-routers/secret-sync-endpoints.ts
@@ -527,12 +527,11 @@ export const registerSyncSecretsEndpoints = <T extends TSecretSync, I extends TS
},
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN, AuthMode.OAUTH]),
handler: async (req) => {
- const { destinationConfig, syncOptions, connectionId, excludeSyncId, projectId } = req.body;
+ const { destinationConfig, connectionId, excludeSyncId, projectId } = req.body;
const result = await server.services.secretSync.checkDuplicateDestination(
{
destinationConfig: destinationConfig as Record<string, unknown>,
- syncOptions,
destination,
connectionId,
excludeSyncId,
diff --git a/backend/src/services/secret-sync/cloudflare-workers/cloudflare-workers-schemas.ts b/backend/src/services/secret-sync/cloudflare-workers/cloudflare-workers-schemas.ts
index da9e2a94a9..f962f462b7 100644
--- a/backend/src/services/secret-sync/cloudflare-workers/cloudflare-workers-schemas.ts
+++ b/backend/src/services/secret-sync/cloudflare-workers/cloudflare-workers-schemas.ts
@@ -55,7 +55,14 @@ export const CreateCloudflareWorkersSyncSchema = GenericCreateSecretSyncFieldsSc
CloudflareWorkersSyncOptionsConfig,
CloudflareWorkersSyncAdditionalOptionsSchema
).extend({
- destinationConfig: CloudflareWorkersSyncDestinationConfigSchema
+ // New syncs default to Secret. The type stays optional elsewhere because syncs created before it existed
+ // have none, and they keep skipping same-name plaintext and JSON variables.
+ destinationConfig: CloudflareWorkersSyncDestinationConfigSchema.extend({
+ variableType: z
+ .nativeEnum(CloudflareWorkersVariableType)
+ .default(CloudflareWorkersVariableType.Secret)
+ .describe(SecretSyncs.DESTINATION_CONFIG.CLOUDFLARE_WORKERS.variableType)
+ })
});
export const UpdateCloudflareWorkersSyncSchema = GenericUpdateSecretSyncFieldsSchema(
diff --git a/backend/src/services/secret-sync/secret-sync-duplicate-check.test.ts b/backend/src/services/secret-sync/secret-sync-duplicate-check.test.ts
index 3a0820c727..8aba2f3214 100644
--- a/backend/src/services/secret-sync/secret-sync-duplicate-check.test.ts
+++ b/backend/src/services/secret-sync/secret-sync-duplicate-check.test.ts
@@ -1,7 +1,6 @@
-import { CloudflareWorkersVariableType } from "./cloudflare-workers/cloudflare-workers-constants";
import { areSecretSyncDestinationConfigsEqual } from "./secret-sync-duplicate-check";
import { SecretSync } from "./secret-sync-enums";
-import { DESTINATION_DUPLICATE_CHECK_MAP } from "./secret-sync-maps";
+import { SECRET_SYNC_SKIP_FIELDS_MAP } from "./secret-sync-maps";
describe("secret sync destination comparison", () => {
test.each([
@@ -54,6 +53,31 @@ describe("secret sync destination comparison", () => {
).toBe(true);
});
+ test.each([
+ [SecretSync.CloudflarePages, { projectName: "site", environment: "production" }],
+ [SecretSync.CloudflareWorkers, { scriptId: "worker" }]
+ ] as const)(
+ "treats %s syncs to the same target as duplicates whatever their variable type",
+ (destination, config) => {
+ expect(
+ areSecretSyncDestinationConfigsEqual(
+ destination,
+ { ...config, variableType: "secret_text" },
+ { ...config, variableType: "plain_text" },
+ SECRET_SYNC_SKIP_FIELDS_MAP[destination]
+ )
+ ).toBe(true);
+ expect(
+ areSecretSyncDestinationConfigsEqual(
+ destination,
+ config,
+ { ...config, variableType: "plain_text" },
+ SECRET_SYNC_SKIP_FIELDS_MAP[destination]
+ )
+ ).toBe(true);
+ }
+ );
+
test("does not strip empty values in other providers", () => {
expect(
areSecretSyncDestinationConfigsEqual(
@@ -65,52 +89,3 @@ describe("secret sync destination comparison", () => {
).toBe(false);
});
});
-
-describe("Cloudflare Workers duplicate check", () => {
- const workersSync = (variableType?: CloudflareWorkersVariableType, syncNonSecretBindings?: boolean) => ({
- connectionId: null,
- destinationConfig: { scriptId: "worker", variableType },
- syncOptions: { syncNonSecretBindings }
- });
-
- test.each([
- [
- "a Secret and a Text sync",
- workersSync(CloudflareWorkersVariableType.Secret),
- workersSync(CloudflareWorkersVariableType.Text),
- false
- ],
- [
- "two Text syncs",
- workersSync(CloudflareWorkersVariableType.Text),
- workersSync(CloudflareWorkersVariableType.Text),
- true
- ],
- [
- "a sync saved without a type and a Secret sync",
- workersSync(),
- workersSync(CloudflareWorkersVariableType.Secret),
- true
- ],
- [
- "a Secret sync that also syncs plaintext and JSON variables and a Text sync",
- workersSync(CloudflareWorkersVariableType.Secret, true),
- workersSync(CloudflareWorkersVariableType.Text),
- true
- ],
- [
- "a JSON sync and a sync saved without a type that also syncs plaintext and JSON variables",
- workersSync(CloudflareWorkersVariableType.Json),
- workersSync(undefined, true),
- true
- ]
- ])("%s: duplicate is %s", async (_, existingSync, newSync, isDuplicate) => {
- await expect(
- DESTINATION_DUPLICATE_CHECK_MAP[SecretSync.CloudflareWorkers]({
- existingSync,
- newSync,
- decryptConnection: vi.fn()
- })
- ).resolves.toBe(isDuplicate);
- });
-});
diff --git a/backend/src/services/secret-sync/secret-sync-maps.ts b/backend/src/services/secret-sync/secret-sync-maps.ts
index a50b51e83d..8b546f32fa 100644
--- a/backend/src/services/secret-sync/secret-sync-maps.ts
+++ b/backend/src/services/secret-sync/secret-sync-maps.ts
@@ -4,11 +4,9 @@ import { TAwsConnection } from "@app/services/app-connection/aws/aws-connection-
import { TDaytonaConnection } from "@app/services/app-connection/daytona";
import { getPortainerInstanceUrl } from "@app/services/app-connection/portainer/portainer-connection-fns";
import { TPortainerConnection } from "@app/services/app-connection/portainer/portainer-connection-types";
-import { CloudflarePagesVariableType } from "@app/services/secret-sync/cloudflare-pages/cloudflare-pages-constants";
-import { CloudflareWorkersVariableType } from "@app/services/secret-sync/cloudflare-workers/cloudflare-workers-constants";
import { GcpSyncScope } from "@app/services/secret-sync/gcp/gcp-sync-enums";
import { SecretSync, SecretSyncPlanType } from "@app/services/secret-sync/secret-sync-enums";
-import { DestinationDuplicateCheckFn, DuplicateCheckSyncFields } from "@app/services/secret-sync/secret-sync-types";
+import { DestinationDuplicateCheckFn } from "@app/services/secret-sync/secret-sync-types";
export const SECRET_SYNC_NAME_MAP: Record<SecretSync, string> = {
[SecretSync.AWSParameterStore]: "AWS Parameter Store",
@@ -207,6 +205,8 @@ export const SECRET_SYNC_SKIP_FIELDS_MAP: Record<SecretSync, string[]> = {
"groupId",
"projectId"
],
+ // Syncs of any variable type write to the same variables, so blocking duplicate destinations has to
+ // cover them all or one project could overwrite another project's variables.
[SecretSync.CloudflarePages]: ["variableType"],
[SecretSync.CloudflareWorkers]: ["variableType"],
[SecretSync.CloudflareSecretsStore]: ["storeName", "scopes"],
@@ -318,25 +318,6 @@ const daytonaDuplicateCheck: DestinationDuplicateCheckFn = async ({ existingSync
return existingOrgId === newOrgId;
};
-// Syncs of different variable types own different variables, so they can share a destination. Syncs saved
-// before the type could be chosen have none and sync as secrets.
-const cloudflareVariableTypeDuplicateCheck =
- (defaultVariableType: string): DestinationDuplicateCheckFn =>
- async ({ existingSync, newSync }) =>
- (existingSync.destinationConfig.variableType ?? defaultVariableType) ===
- (newSync.destinationConfig.variableType ?? defaultVariableType);
-
-// A Secret sync with syncNonSecretBindings also deletes plaintext and JSON variables that it doesn't sync,
-// so it can't share a Worker with any other sync.
-const ownsEveryWorkerVariable = ({ destinationConfig, syncOptions }: DuplicateCheckSyncFields) =>
- (destinationConfig.variableType ?? CloudflareWorkersVariableType.Secret) === CloudflareWorkersVariableType.Secret &&
- Boolean(syncOptions?.syncNonSecretBindings);
-
-const cloudflareWorkersDuplicateCheck: DestinationDuplicateCheckFn = async (params) =>
- ownsEveryWorkerVariable(params.existingSync) ||
- ownsEveryWorkerVariable(params.newSync) ||
- cloudflareVariableTypeDuplicateCheck(CloudflareWorkersVariableType.Secret)(params);
-
const gcpDuplicateCheck: DestinationDuplicateCheckFn = async ({ existingSync, newSync }) => {
const existingConfig = existingSync.destinationConfig;
const newConfig = newSync.destinationConfig;
@@ -400,8 +381,8 @@ export const DESTINATION_DUPLICATE_CHECK_MAP: Record<SecretSync, DestinationDupl
return existingTargetEnv === newTargetEnv;
},
- [SecretSync.CloudflarePages]: cloudflareVariableTypeDuplicateCheck(CloudflarePagesVariableType.Secret),
- [SecretSync.CloudflareWorkers]: cloudflareWorkersDuplicateCheck,
+ [SecretSync.CloudflarePages]: defaultDuplicateCheck,
+ [SecretSync.CloudflareWorkers]: defaultDuplicateCheck,
[SecretSync.CloudflareSecretsStore]: defaultDuplicateCheck,
[SecretSync.Supabase]: defaultDuplicateCheck,
[SecretSync.Rundeck]: defaultDuplicateCheck,
diff --git a/backend/src/services/secret-sync/secret-sync-service.ts b/backend/src/services/secret-sync/secret-sync-service.ts
index 9764e0ea3e..aa825f2f21 100644
--- a/backend/src/services/secret-sync/secret-sync-service.ts
+++ b/backend/src/services/secret-sync/secret-sync-service.ts
@@ -499,14 +499,7 @@ export const secretSyncServiceFactory = ({
};
const checkDuplicateDestination = async (
- {
- destination,
- destinationConfig,
- syncOptions,
- connectionId,
- excludeSyncId,
- projectId
- }: TCheckDuplicateDestinationDTO,
+ { destination, destinationConfig, connectionId, excludeSyncId, projectId }: TCheckDuplicateDestinationDTO,
actor: OrgServiceActor
) => {
const skipFields = SECRET_SYNC_SKIP_FIELDS_MAP[destination];
@@ -568,13 +561,11 @@ export const secretSyncServiceFactory = ({
const isDuplicate = await DESTINATION_DUPLICATE_CHECK_MAP[destination]({
existingSync: {
connectionId: sync.connectionId,
- destinationConfig: sync.destinationConfig as Record<string, unknown>,
- syncOptions: sync.syncOptions as Record<string, unknown>
+ destinationConfig: sync.destinationConfig as Record<string, unknown>
},
newSync: {
connectionId: connectionId ?? null,
- destinationConfig,
- syncOptions
+ destinationConfig
},
decryptConnection
});
@@ -707,7 +698,6 @@ export const secretSyncServiceFactory = ({
{
destination: params.destination,
destinationConfig: params.destinationConfig,
- syncOptions: params.syncOptions,
connectionId: params.connectionId,
projectId
},
@@ -845,7 +835,6 @@ export const secretSyncServiceFactory = ({
{
destination,
destinationConfig: params.destinationConfig ?? (secretSync.destinationConfig as Record<string, unknown>),
- syncOptions: params.syncOptions ?? (secretSync.syncOptions as Record<string, unknown>),
connectionId: params.connectionId ?? connectionId,
projectId: secretSync.projectId,
excludeSyncId: secretSync.id
diff --git a/backend/src/services/secret-sync/secret-sync-types.ts b/backend/src/services/secret-sync/secret-sync-types.ts
index 4197b84914..e119a11029 100644
--- a/backend/src/services/secret-sync/secret-sync-types.ts
+++ b/backend/src/services/secret-sync/secret-sync-types.ts
@@ -524,7 +524,6 @@ export type TDeleteSecretSyncDTO = {
export type TCheckDuplicateDestinationDTO = {
destination: SecretSync;
destinationConfig: Record<string, unknown>;
- syncOptions?: Record<string, unknown>;
connectionId?: string | null;
excludeSyncId?: string;
projectId: string;
@@ -632,7 +631,6 @@ export type TSecretMap = Record<
export type DuplicateCheckSyncFields = {
connectionId: string | null;
destinationConfig: Record<string, unknown>;
- syncOptions?: Record<string, unknown>;
};
export type DestinationDuplicateCheckFn = (opts: {
diff --git a/docs/integrations/secret-syncs/cloudflare-pages.mdx b/docs/integrations/secret-syncs/cloudflare-pages.mdx
index 829920350e..422e8eb177 100644
--- a/docs/integrations/secret-syncs/cloudflare-pages.mdx
+++ b/docs/integrations/secret-syncs/cloudflare-pages.mdx
@@ -47,7 +47,7 @@ description: "Learn how to configure a Cloudflare Pages Sync for Infisical."
- **Text**: Plain text that you can read in the Cloudflare dashboard
<Tip>
- To sync both secrets and text variables to one environment, create one sync of each type from different folders. Each sync only deletes variables of its own type.
+ To sync both secrets and text variables to one environment, create one sync of each type from different folders. Each sync only deletes variables of its own type. When you create the second sync, Infisical warns that the destination is already in use. If your organization blocks duplicate destinations, you can't create the second sync.
</Tip>
6. Configure the **Details** of your Cloudflare Pages Sync, then click **Next**.
diff --git a/frontend/src/components/secret-syncs/forms/CreateSecretSyncForm.tsx b/frontend/src/components/secret-syncs/forms/CreateSecretSyncForm.tsx
index 27cd67a0a9..21ea014735 100644
--- a/frontend/src/components/secret-syncs/forms/CreateSecretSyncForm.tsx
+++ b/frontend/src/components/secret-syncs/forms/CreateSecretSyncForm.tsx
@@ -235,8 +235,7 @@ export const CreateSecretSyncForm = ({
projectId: currentProject?.id || "",
connectionId: watch("connection")?.id,
enabled: true,
- destinationConfig: getSecretSyncDestinationConfig(destination, watch("destinationConfig")),
- syncOptions: watch("syncOptions")
+ destinationConfig: getSecretSyncDestinationConfig(destination, watch("destinationConfig"))
});
const disableSecretDeletion = watch("syncOptions.disableSecretDeletion");
diff --git a/frontend/src/components/secret-syncs/forms/EditSecretSyncForm.tsx b/frontend/src/components/secret-syncs/forms/EditSecretSyncForm.tsx
index 33caad0b0a..10990abde7 100644
--- a/frontend/src/components/secret-syncs/forms/EditSecretSyncForm.tsx
+++ b/frontend/src/components/secret-syncs/forms/EditSecretSyncForm.tsx
@@ -157,7 +157,6 @@ export const EditSecretSyncForm = ({ secretSync, onComplete, onDirtyChange, onCa
secretSync.projectId,
secretSync.id,
formMethods.watch("connection")?.id,
- pendingFormData?.syncOptions,
{ enabled: checkDuplicateEnabled && Boolean(destinationConfigToCheck) }
);
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/SecretSyncReviewFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/SecretSyncReviewFields.tsx
index 72dee21b49..4028a15142 100644
--- a/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/SecretSyncReviewFields.tsx
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/SecretSyncReviewFields.tsx
@@ -117,8 +117,7 @@ export const SecretSyncReviewFields = () => {
projectId: currentProject?.id || "",
connectionId: connection?.id,
enabled: true,
- destinationConfig: getSecretSyncDestinationConfig(destination, watch("destinationConfig")),
- syncOptions: watch("syncOptions")
+ destinationConfig: getSecretSyncDestinationConfig(destination, watch("destinationConfig"))
});
switch (destination) {
diff --git a/frontend/src/hooks/api/secretSyncs/queries.tsx b/frontend/src/hooks/api/secretSyncs/queries.tsx
index ce40ede944..3baa580010 100644
--- a/frontend/src/hooks/api/secretSyncs/queries.tsx
+++ b/frontend/src/hooks/api/secretSyncs/queries.tsx
@@ -20,8 +20,7 @@ export const secretSyncKeys = {
destination: SecretSync,
destinationConfig: unknown,
connectionId?: string,
- excludeSyncId?: string,
- syncOptions?: unknown
+ excludeSyncId?: string
) =>
[
...secretSyncKeys.all,
@@ -29,8 +28,7 @@ export const secretSyncKeys = {
"duplicate-check",
destinationConfig,
connectionId,
- excludeSyncId,
- syncOptions
+ excludeSyncId
] as const,
recursiveConflicts: (
destination: SecretSync,
@@ -151,7 +149,6 @@ export const useCheckDuplicateDestination = (
projectId: string,
excludeSyncId?: string,
connectionId?: string,
- syncOptions?: unknown,
options?: Omit<
UseQueryOptions<
{ hasDuplicate: boolean; duplicateProjectId?: string },
@@ -167,8 +164,7 @@ export const useCheckDuplicateDestination = (
destination,
destinationConfig,
connectionId,
- excludeSyncId,
- syncOptions
+ excludeSyncId
),
queryFn: async () => {
const { data } = await apiRequest.post<{
@@ -176,7 +172,6 @@ export const useCheckDuplicateDestination = (
duplicateProjectId?: string;
}>(`/api/v1/secret-syncs/${destination}/check-destination`, {
destinationConfig,
- syncOptions,
connectionId,
excludeSyncId,
projectId
diff --git a/frontend/src/hooks/api/secretSyncs/useDuplicateDestinationCheck.ts b/frontend/src/hooks/api/secretSyncs/useDuplicateDestinationCheck.ts
index 0821a61aa1..b0c3a4646e 100644
--- a/frontend/src/hooks/api/secretSyncs/useDuplicateDestinationCheck.ts
+++ b/frontend/src/hooks/api/secretSyncs/useDuplicateDestinationCheck.ts
@@ -10,7 +10,6 @@ type UseDuplicateDestinationCheckProps = {
connectionId?: string;
enabled?: boolean;
destinationConfig?: unknown;
- syncOptions?: unknown;
};
export const useDuplicateDestinationCheck = ({
@@ -19,8 +18,7 @@ export const useDuplicateDestinationCheck = ({
excludeSyncId,
connectionId,
enabled = true,
- destinationConfig,
- syncOptions
+ destinationConfig
}: UseDuplicateDestinationCheckProps) => {
const normalizedConfig = useMemo(
() => getSecretSyncDestinationConfig(destination, destinationConfig),
@@ -42,7 +40,6 @@ export const useDuplicateDestinationCheck = ({
projectId,
excludeSyncId,
connectionId,
- syncOptions,
{
enabled: shouldCheck,
staleTime: 0,