Skip to content

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

enhance Cloudflare Secrets Store integration with error handling and improved documentation

Dimitris Staratzis277262c65bf8
diff --git a/backend/src/services/app-connection/cloudflare/cloudflare-connection-service.ts b/backend/src/services/app-connection/cloudflare/cloudflare-connection-service.ts
index aa4bd53114..ab2dfcf9d3 100644
--- a/backend/src/services/app-connection/cloudflare/cloudflare-connection-service.ts
+++ b/backend/src/services/app-connection/cloudflare/cloudflare-connection-service.ts
@@ -1,8 +1,10 @@
+import { BadRequestError } from "@app/lib/errors";
import { logger } from "@app/lib/logger";
import { OrgServiceActor } from "@app/lib/types";
import { AppConnection } from "../app-connection-enums";
import {
+ getCloudflareErrorMessage,
listCloudflarePagesProjects,
listCloudflarePermissionGroups,
listCloudflareR2Buckets,
@@ -57,7 +59,9 @@ export const cloudflareConnectionService = (getAppConnection: TGetAppConnectionF
error,
`Failed to list Cloudflare Secrets Stores for Cloudflare connection [connectionId=${connectionId}]`
);
- return [];
+ throw new BadRequestError({
+ message: `Failed to list Cloudflare Secrets Stores: ${getCloudflareErrorMessage(error)}`
+ });
}
};
diff --git a/backend/src/services/secret-sync/cloudflare-secrets-store/cloudflare-secrets-store-sync-fns.test.ts b/backend/src/services/secret-sync/cloudflare-secrets-store/cloudflare-secrets-store-sync-fns.test.ts
index ab24bdc08e..31eb0a6f32 100644
--- a/backend/src/services/secret-sync/cloudflare-secrets-store/cloudflare-secrets-store-sync-fns.test.ts
+++ b/backend/src/services/secret-sync/cloudflare-secrets-store/cloudflare-secrets-store-sync-fns.test.ts
@@ -102,6 +102,24 @@ describe("CloudflareSecretsStoreSyncFns", () => {
);
});
+ it.each([
+ ["create", post, ["KEEP", "NEW"]],
+ ["update", patch, ["NEW", "KEEP"]]
+ ])("deletes nothing when a %s fails after an earlier write succeeded", async (_, failingWrite, keys) => {
+ stubCloudflare([
+ [
+ { id: "keep", name: "KEEP" },
+ { id: "stale", name: "STALE" }
+ ]
+ ]);
+ failingWrite.mockRejectedValueOnce(new Error("Cloudflare is unavailable"));
+
+ await expect(CloudflareSecretsStoreSyncFns.syncSecrets(syncWith(), payloadOf(keys))).rejects.toThrow();
+
+ expect(post.mock.calls.length + patch.mock.calls.length).toBe(2);
+ expect(del).not.toHaveBeenCalled();
+ });
+
it("reads every page when Cloudflare reports only total_count", async () => {
stubCloudflare([[{ id: "first", name: "FIRST" }], [{ id: "second", name: "SECOND" }]], { totalCount: 51 });
diff --git a/docs/integrations/secret-syncs/cloudflare-secrets-store.mdx b/docs/integrations/secret-syncs/cloudflare-secrets-store.mdx
index b6eaabf9d9..6252f7a1aa 100644
--- a/docs/integrations/secret-syncs/cloudflare-secrets-store.mdx
+++ b/docs/integrations/secret-syncs/cloudflare-secrets-store.mdx
@@ -52,7 +52,7 @@ A Cloudflare Secrets Store Sync pushes secrets from Infisical into your Cloudfla
- **Scopes**: The Cloudflare products allowed to use the synced secrets: **Workers**, **AI Gateway**, or **Containers** (defaults to **Workers**)
<Note>
- Infisical sets these scopes on every secret it writes, each time the sync runs. If you change a synced secret's scopes in Cloudflare, the next sync changes them back, and if you remove a scope from the sync, every secret the sync manages loses that scope. To give some secrets different scopes, sync them from a separate folder with their own sync.
+ Infisical sets these scopes on every secret it writes, each time the sync runs. If you change a synced secret's scopes in Cloudflare, the next sync changes them back, and if you remove a scope from the sync, every secret the sync manages loses that scope. To give some secrets different scopes, sync them from another folder with a second sync, and customize key names on both syncs with prefixes that don't overlap, such as `WORKERS_{{secretKey}}` and `GATEWAY_{{secretKey}}`. Without separate prefixes, each sync treats the other's secrets as its own, and deletes them if **Prevent secret deletion** is off. If your organization has **Unique Secret Sync Destination Policy** turned on, Infisical rejects the second sync, because both syncs write to the same store.
</Note>
![Configure Destination](/images/secret-syncs/cloudflare-secrets-store/configure-destination.png)
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/CloudflareSecretsStoreSyncFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/CloudflareSecretsStoreSyncFields.tsx
index 7f7242f9d5..e6ad4fcfc3 100644
--- a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/CloudflareSecretsStoreSyncFields.tsx
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/CloudflareSecretsStoreSyncFields.tsx
@@ -26,12 +26,13 @@ export const CloudflareSecretsStoreSyncFields = () => {
const connectionId = useWatch({ name: "connection.id", control });
- const { data: stores, isLoading: isStoresLoading } = useCloudflareConnectionListSecretsStores(
- connectionId,
- {
- enabled: Boolean(connectionId)
- }
- );
+ const {
+ data: stores,
+ isLoading: isStoresLoading,
+ error: storesError
+ } = useCloudflareConnectionListSecretsStores(connectionId, {
+ enabled: Boolean(connectionId)
+ });
return (
<FieldGroup>
@@ -70,6 +71,11 @@ export const CloudflareSecretsStoreSyncFields = () => {
}}
options={stores ?? []}
placeholder="Select a store..."
+ emptyMessage={
+ storesError
+ ? "Unable to load Cloudflare Secrets Stores. Check that the connection's API token has the Secrets Store Edit permission."
+ : undefined
+ }
getOptionLabel={(option) => option.name}
getOptionValue={(option) => option.id}
getOptionKeywords={(option) => [option.id]}