Skip to content

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

add toggle

Matheus Nogueira030c8a300751
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index 88d55b8c29..1b4580a6ff 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -3071,6 +3071,10 @@ export const SecretSyncs = {
AZURE_KEY_VAULT: {
disableCertificateImport:
"Whether Infisical should skip importing certificate objects from Azure Key Vault when syncing secrets."
+ },
+ CLOUDFLARE_WORKERS: {
+ syncNonSecretBindings:
+ "Whether Infisical should also sync plaintext and JSON variable bindings in addition to secret bindings."
}
},
DESTINATION_CONFIG: {
diff --git a/backend/src/services/secret-sync/cloudflare-workers/cloudflare-workers-fns.ts b/backend/src/services/secret-sync/cloudflare-workers/cloudflare-workers-fns.ts
index 0273aa733e..855cbb301a 100644
--- a/backend/src/services/secret-sync/cloudflare-workers/cloudflare-workers-fns.ts
+++ b/backend/src/services/secret-sync/cloudflare-workers/cloudflare-workers-fns.ts
@@ -60,9 +60,14 @@ const throwOnUndeployedVersionError = (err: unknown) => {
throw err;
};
-const getSecretKeys = async (
+type TCloudflareBindings = {
+ secrets: TCloudflareSecretMetadata[];
+ nonSecretBindings: TCloudflareSecretMetadata[];
+};
+
+const getCloudflareBindings = async (
secretSync: TCloudflareWorkersSyncWithCredentials
-): Promise<TCloudflareSecretMetadata[]> => {
+): Promise<TCloudflareBindings> => {
const {
destinationConfig,
connection: {
@@ -94,14 +99,14 @@ const getSecretKeys = async (
const SYNCABLE_BINDING_TYPES = new Set(["plain_text", "json"]);
+ const secretKeySet = new Set(secrets.map((s) => s.key));
const nonSecretBindings = (settingsResponse.data.result.bindings || [])
- .filter((b) => SYNCABLE_BINDING_TYPES.has(b.type))
+ .filter((b) => SYNCABLE_BINDING_TYPES.has(b.type) && !secretKeySet.has(b.name))
.map((b) => ({ key: b.name, type: b.type }));
- const secretKeySet = new Set(secrets.map((s) => s.key));
- const uniqueNonSecretBindings = nonSecretBindings.filter((v) => !secretKeySet.has(v.key));
-
- return [...secrets, ...uniqueNonSecretBindings];
+ // We need to know both types because cloudflare prevents secrets and variables (plaintext or JSON)
+ // to have the same name.
+ return { secrets, nonSecretBindings };
};
export const CloudflareWorkersSyncFns = {
@@ -113,16 +118,31 @@ export const CloudflareWorkersSyncFns = {
destinationConfig: { scriptId }
} = secretSync;
- const existingSecrets = await getSecretKeys(secretSync);
+ const shouldSyncNonSecretBindings = Boolean(secretSync.syncOptions.syncNonSecretBindings);
+ const { secrets: existingSecretBindings, nonSecretBindings } = await getCloudflareBindings(secretSync);
+
+ const existingSecrets = shouldSyncNonSecretBindings
+ ? [...existingSecretBindings, ...nonSecretBindings]
+ : existingSecretBindings;
+
+ const nonSecretBindingKeys = new Set(nonSecretBindings.map((b) => b.key));
const existingSecretsMap = Object.fromEntries(existingSecrets.map(({ key, type }) => [key, type]));
const secretMapKeys = new Set(Object.keys(secretMap));
+ // We cannot sync secrets that have the same name as a non-secret
+ // if shouldSyncNonSecretBindings = false. This happens because
+ // Cloudflare will reject the request due to name conflicts. A secret
+ // cannot have the same name as a non-secret variable.
+ const syncableEntries = Object.entries(secretMap).filter(
+ ([key]) => shouldSyncNonSecretBindings || !nonSecretBindingKeys.has(key)
+ );
+
const bindingEntries: Array<[string, { value: string }]> = [];
const secretEntries: Array<[string, { value: string }]> = [];
- for (const [key, val] of Object.entries(secretMap)) {
+ for (const [key, val] of syncableEntries) {
const existingType = existingSecretsMap[key];
- if (existingType && existingType !== CLOUDFLARE_SECRET_TYPE) {
+ if (existingType && existingType !== CLOUDFLARE_SECRET_TYPE) {
bindingEntries.push([key, val]);
} else {
secretEntries.push([key, val]);
@@ -148,7 +168,7 @@ export const CloudflareWorkersSyncFns = {
$validateJsonBindings(settingsData.result.bindings, updatedBindingMap);
const updatedBindings = settingsData.result.bindings.map((binding) => {
- if (binding.type !== CLOUDFLARE_SECRET_TYPE && updatedBindingMap[binding.name] !== undefined) {
+ if (binding.type !== CLOUDFLARE_SECRET_TYPE && updatedBindingMap[binding.name] !== undefined) {
const newValue = updatedBindingMap[binding.name].value;
if (binding.type === "json") {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
@@ -181,7 +201,7 @@ export const CloudflareWorkersSyncFns = {
await delayMs(Math.max(0, applyJitter(100, 200)));
await request.put(
`${IntegrationUrls.CLOUDFLARE_WORKERS_API_URL}/client/v4/accounts/${accountId}/workers/scripts/${scriptId}/secrets`,
- { name: key, text: val.value, type: CLOUDFLARE_SECRET_TYPE },
+ { name: key, text: val.value, type: CLOUDFLARE_SECRET_TYPE },
{
headers: {
Authorization: `Bearer ${apiToken}`,
@@ -206,8 +226,8 @@ export const CloudflareWorkersSyncFns = {
return !isInNewSecretMap && isManagedBySchema;
});
- const secretTypeToDelete = secretsToDelete.filter((s) => s.type === CLOUDFLARE_SECRET_TYPE);
- const bindingTypeToDelete = secretsToDelete.filter((s) => s.type !== CLOUDFLARE_SECRET_TYPE);
+ const secretTypeToDelete = secretsToDelete.filter((s) => s.type === CLOUDFLARE_SECRET_TYPE);
+ const bindingTypeToDelete = secretsToDelete.filter((s) => s.type !== CLOUDFLARE_SECRET_TYPE);
try {
/* eslint-disable no-await-in-loop */
@@ -277,7 +297,13 @@ export const CloudflareWorkersSyncFns = {
destinationConfig: { scriptId }
} = secretSync;
- const existingSecretNames = await getSecretKeys(secretSync);
+ const shouldSyncNonSecretBindings = Boolean(secretSync.syncOptions.syncNonSecretBindings);
+ const { secrets: existingSecretBindings, nonSecretBindings } = await getCloudflareBindings(secretSync);
+
+ const existingSecretNames = shouldSyncNonSecretBindings
+ ? [...existingSecretBindings, ...nonSecretBindings]
+ : existingSecretBindings;
+
const secretMapToRemoveKeys = new Set(Object.keys(secretMap));
const secretsToRemove = existingSecretNames.filter((existingSecret) => {
@@ -289,8 +315,8 @@ export const CloudflareWorkersSyncFns = {
return secretMapToRemoveKeys.has(existingSecret.key) && isManagedBySchema;
});
- const secretTypeToRemove = secretsToRemove.filter((s) => s.type === CLOUDFLARE_SECRET_TYPE);
- const bindingTypeToRemove = secretsToRemove.filter((s) => s.type !== CLOUDFLARE_SECRET_TYPE);
+ const secretTypeToRemove = secretsToRemove.filter((s) => s.type === CLOUDFLARE_SECRET_TYPE);
+ const bindingTypeToRemove = secretsToRemove.filter((s) => s.type !== CLOUDFLARE_SECRET_TYPE);
try {
/* eslint-disable no-await-in-loop */
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 bd9640d9d8..1b88651d4c 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
@@ -25,11 +25,19 @@ const CloudflareWorkersSyncDestinationConfigSchema = z.object({
.describe(SecretSyncs.DESTINATION_CONFIG.CLOUDFLARE_WORKERS.scriptId)
});
+const CloudflareWorkersSyncAdditionalOptionsSchema = z.object({
+ syncNonSecretBindings: z
+ .boolean()
+ .optional()
+ .describe(SecretSyncs.ADDITIONAL_SYNC_OPTIONS.CLOUDFLARE_WORKERS.syncNonSecretBindings)
+});
+
const CloudflareWorkersSyncOptionsConfig: TSyncOptionsConfig = { canImportSecrets: false };
export const CloudflareWorkersSyncSchema = BaseSecretSyncSchema(
SecretSync.CloudflareWorkers,
- CloudflareWorkersSyncOptionsConfig
+ CloudflareWorkersSyncOptionsConfig,
+ CloudflareWorkersSyncAdditionalOptionsSchema
)
.extend({
destination: z.literal(SecretSync.CloudflareWorkers),
@@ -39,14 +47,16 @@ export const CloudflareWorkersSyncSchema = BaseSecretSyncSchema(
export const CreateCloudflareWorkersSyncSchema = GenericCreateSecretSyncFieldsSchema(
SecretSync.CloudflareWorkers,
- CloudflareWorkersSyncOptionsConfig
+ CloudflareWorkersSyncOptionsConfig,
+ CloudflareWorkersSyncAdditionalOptionsSchema
).extend({
destinationConfig: CloudflareWorkersSyncDestinationConfigSchema
});
export const UpdateCloudflareWorkersSyncSchema = GenericUpdateSecretSyncFieldsSchema(
SecretSync.CloudflareWorkers,
- CloudflareWorkersSyncOptionsConfig
+ CloudflareWorkersSyncOptionsConfig,
+ CloudflareWorkersSyncAdditionalOptionsSchema
).extend({
destinationConfig: CloudflareWorkersSyncDestinationConfigSchema.optional()
});
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/CloudflareWorkersSyncFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/CloudflareWorkersSyncFields.tsx
index 20b750d4d7..cc8cd7b437 100644
--- a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/CloudflareWorkersSyncFields.tsx
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/CloudflareWorkersSyncFields.tsx
@@ -1,12 +1,8 @@
import { Controller, useFormContext, useWatch } from "react-hook-form";
import { SingleValue } from "react-select";
-import { Info } from "lucide-react";
import { SecretSyncConnectionField } from "@app/components/secret-syncs/forms/SecretSyncConnectionField";
import {
- Alert,
- AlertDescription,
- AlertTitle,
Field,
FieldContent,
FieldError,
@@ -65,15 +61,6 @@ export const CloudflareWorkersSyncFields = () => {
</Field>
)}
/>
- <Alert variant="info">
- <Info />
- <AlertTitle>Binding types are preserved</AlertTitle>
- <AlertDescription>
- Cloudflare Workers supports secret text, plain text, and JSON bindings. If a binding
- already exists on the worker, its type will not be changed during sync. New bindings
- created by Infisical will default to secret text.
- </AlertDescription>
- </Alert>
</FieldGroup>
);
};
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/CloudflareWorkersSyncOptionsFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/CloudflareWorkersSyncOptionsFields.tsx
new file mode 100644
index 0000000000..56a77ca9ef
--- /dev/null
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/CloudflareWorkersSyncOptionsFields.tsx
@@ -0,0 +1,66 @@
+import { Controller, useFormContext } from "react-hook-form";
+import { TriangleAlert } from "lucide-react";
+
+import {
+ Alert,
+ AlertDescription,
+ AlertTitle,
+ Field,
+ FieldContent,
+ FieldDescription,
+ FieldError,
+ Label,
+ Switch
+} from "@app/components/v3";
+import { SecretSync } from "@app/hooks/api/secretSyncs";
+
+import { TSecretSyncForm } from "../schemas";
+
+export const CloudflareWorkersSyncOptionsFields = () => {
+ const { control, watch } = useFormContext<
+ TSecretSyncForm & { destination: SecretSync.CloudflareWorkers }
+ >();
+
+ const disableSecretDeletion = watch("syncOptions.disableSecretDeletion");
+ const syncNonSecretBindings = watch("syncOptions.syncNonSecretBindings");
+
+ return (
+ <>
+ <Controller
+ name="syncOptions.syncNonSecretBindings"
+ control={control}
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <Field className="mb-4">
+ <Field orientation="horizontal">
+ <FieldContent>
+ <Label htmlFor="sync-non-secret-bindings">Sync plaintext and JSON variables</Label>
+ <FieldDescription>
+ When enabled, Infisical will also sync plaintext and JSON variable bindings in
+ addition to secret bindings.
+ </FieldDescription>
+ </FieldContent>
+ <Switch
+ id="sync-non-secret-bindings"
+ variant="project"
+ checked={value}
+ onCheckedChange={onChange}
+ />
+ </Field>
+ <FieldError errors={[error]} />
+ </Field>
+ )}
+ />
+ {syncNonSecretBindings && !disableSecretDeletion && (
+ <Alert variant="warning" className="mb-4">
+ <TriangleAlert />
+ <AlertTitle>Plaintext and JSON variables may be deleted</AlertTitle>
+ <AlertDescription>
+ With secret deletion enabled and non-secret binding sync turned on, any plaintext or
+ JSON variables in Cloudflare Workers that are not present in Infisical will be removed
+ during a sync. Toggle &quot;Disable secret deletion&quot; above to prevent this.
+ </AlertDescription>
+ </Alert>
+ )}
+ </>
+ );
+};
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/SecretSyncOptionsFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/SecretSyncOptionsFields.tsx
index 687f4df42b..181facdbf5 100644
--- a/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/SecretSyncOptionsFields.tsx
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/SecretSyncOptionsFields.tsx
@@ -31,6 +31,7 @@ import { InitialSyncAlerts } from "../SecretSyncInitialSyncBehaviorFields";
import { AwsParameterStoreSyncOptionsFields } from "./AwsParameterStoreSyncOptionsFields";
import { AwsSecretsManagerSyncOptionsFields } from "./AwsSecretsManagerSyncOptionsFields";
import { AzureKeyVaultSyncOptionsFields } from "./AzureKeyVaultSyncOptionsFields";
+import { CloudflareWorkersSyncOptionsFields } from "./CloudflareWorkersSyncOptionsFields";
import { FlyioSyncOptionsFields } from "./FlyioSyncOptionsFields";
import { QoverySyncOptionsFields } from "./QoverySyncOptionsFields";
import { RenderSyncOptionsFields } from "./RenderSyncOptionsFields";
@@ -115,8 +116,10 @@ export const SecretSyncOptionsFields = ({ hideInitialSync, children }: Props) =>
case SecretSync.OCIVault:
case SecretSync.Heroku:
case SecretSync.GitLab:
- case SecretSync.CloudflarePages:
case SecretSync.CloudflareWorkers:
+ AdditionalSyncOptionsFieldsComponent = <CloudflareWorkersSyncOptionsFields />;
+ break;
+ case SecretSync.CloudflarePages:
case SecretSync.Zabbix:
case SecretSync.Railway:
case SecretSync.Checkly:
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/CloudflareWorkersReviewFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/CloudflareWorkersReviewFields.tsx
index 181c1e75ff..dcb2508733 100644
--- a/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/CloudflareWorkersReviewFields.tsx
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/CloudflareWorkersReviewFields.tsx
@@ -1,9 +1,28 @@
import { useFormContext } from "react-hook-form";
import { TSecretSyncForm } from "@app/components/secret-syncs/forms/schemas";
-import { Detail, DetailLabel, DetailValue } from "@app/components/v3";
+import { Badge, Detail, DetailLabel, DetailValue } from "@app/components/v3";
import { SecretSync } from "@app/hooks/api/secretSyncs";
+export const CloudflareWorkersSyncOptionsReviewFields = () => {
+ const { watch } = useFormContext<
+ TSecretSyncForm & { destination: SecretSync.CloudflareWorkers }
+ >();
+
+ const [{ syncNonSecretBindings }] = watch(["syncOptions"]);
+
+ return (
+ <Detail>
+ <DetailLabel>Sync Plaintext and JSON Variables</DetailLabel>
+ <DetailValue>
+ <Badge variant={syncNonSecretBindings ? "success" : "danger"}>
+ {syncNonSecretBindings ? "Enabled" : "Disabled"}
+ </Badge>
+ </DetailValue>
+ </Detail>
+ );
+};
+
export const CloudflareWorkersSyncReviewFields = () => {
const { watch } = useFormContext<
TSecretSyncForm & { destination: SecretSync.CloudflareWorkers }
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/SecretSyncReviewFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/SecretSyncReviewFields.tsx
index d7c141fd76..60bf0902d3 100644
--- a/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/SecretSyncReviewFields.tsx
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/SecretSyncReviewFields.tsx
@@ -37,7 +37,10 @@ import { ChefSyncReviewFields } from "./ChefSyncReviewFields";
import { CircleCISyncReviewFields } from "./CircleCISyncReviewFields";
import { Cloud66SyncReviewFields } from "./Cloud66SyncReviewFields";
import { CloudflarePagesSyncReviewFields } from "./CloudflarePagesReviewFields";
-import { CloudflareWorkersSyncReviewFields } from "./CloudflareWorkersReviewFields";
+import {
+ CloudflareWorkersSyncOptionsReviewFields,
+ CloudflareWorkersSyncReviewFields
+} from "./CloudflareWorkersReviewFields";
import { DatabricksSyncReviewFields } from "./DatabricksSyncReviewFields";
import { DevinSyncReviewFields } from "./DevinSyncReviewFields";
import { DigitalOceanAppPlatformSyncReviewFields } from "./DigitalOceanAppPlatformSyncReviewFields";
@@ -176,6 +179,7 @@ export const SecretSyncReviewFields = () => {
break;
case SecretSync.CloudflareWorkers:
DestinationFieldsComponent = <CloudflareWorkersSyncReviewFields />;
+ AdditionalSyncOptionsFieldsComponent = <CloudflareWorkersSyncOptionsReviewFields />;
break;
case SecretSync.Zabbix:
DestinationFieldsComponent = <ZabbixSyncReviewFields />;
diff --git a/frontend/src/components/secret-syncs/forms/schemas/cloudflare-workers-sync-destination-schema.ts b/frontend/src/components/secret-syncs/forms/schemas/cloudflare-workers-sync-destination-schema.ts
index 5e4c16d090..5c73e4cb4b 100644
--- a/frontend/src/components/secret-syncs/forms/schemas/cloudflare-workers-sync-destination-schema.ts
+++ b/frontend/src/components/secret-syncs/forms/schemas/cloudflare-workers-sync-destination-schema.ts
@@ -3,7 +3,11 @@ import { z } from "zod";
import { BaseSecretSyncSchema } from "@app/components/secret-syncs/forms/schemas/base-secret-sync-schema";
import { SecretSync } from "@app/hooks/api/secretSyncs";
-export const CloudflareWorkersSyncDestinationSchema = BaseSecretSyncSchema().merge(
+export const CloudflareWorkersSyncDestinationSchema = BaseSecretSyncSchema(
+ z.object({
+ syncNonSecretBindings: z.boolean().optional().default(false)
+ })
+).merge(
z.object({
destination: z.literal(SecretSync.CloudflareWorkers),
destinationConfig: z.object({
diff --git a/frontend/src/hooks/api/secretSyncs/types/cloudflare-workers-sync.ts b/frontend/src/hooks/api/secretSyncs/types/cloudflare-workers-sync.ts
index 224fe8938e..d75de9d713 100644
--- a/frontend/src/hooks/api/secretSyncs/types/cloudflare-workers-sync.ts
+++ b/frontend/src/hooks/api/secretSyncs/types/cloudflare-workers-sync.ts
@@ -1,6 +1,6 @@
import { AppConnection } from "@app/hooks/api/appConnections/enums";
import { SecretSync } from "@app/hooks/api/secretSyncs";
-import { TRootSecretSync } from "@app/hooks/api/secretSyncs/types/root-sync";
+import { RootSyncOptions, TRootSecretSync } from "@app/hooks/api/secretSyncs/types/root-sync";
export type TCloudflareWorkersSync = TRootSecretSync & {
destination: SecretSync.CloudflareWorkers;
@@ -12,4 +12,7 @@ export type TCloudflareWorkersSync = TRootSecretSync & {
name: string;
id: string;
};
+ syncOptions: RootSyncOptions & {
+ syncNonSecretBindings?: boolean;
+ };
};