Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
docs & tests
Dimitris Staratzisc274382236c0
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.tsnew file mode 100644index 0000000000..ab24bdc08e--- /dev/null+++ b/backend/src/services/secret-sync/cloudflare-secrets-store/cloudflare-secrets-store-sync-fns.test.ts@@ -0,0 +1,113 @@+import { beforeEach, describe, expect, it, vi } from "vitest";++import { TSecretSyncPayload } from "../secret-sync-payload";+import { CloudflareSecretsStoreSyncFns } from "./cloudflare-secrets-store-sync-fns";+import {+ TCloudflareSecretsStoreSecret,+ TCloudflareSecretsStoreSyncWithCredentials+} from "./cloudflare-secrets-store-sync-types";++vi.mock("@app/lib/config/env", () => ({ getConfig: () => ({}) }));++const { get, post, patch, del } = vi.hoisted(() => ({+ get: vi.fn(),+ post: vi.fn().mockResolvedValue({}),+ patch: vi.fn().mockResolvedValue({}),+ del: vi.fn().mockResolvedValue({})+}));+vi.mock("@app/lib/validator", async (importOriginal) => ({+ ...(await importOriginal<object>()),+ safeRequest: { get, post, patch, delete: del }+}));++const SECRETS_URL = "https://api.cloudflare.com/client/v4/accounts/account-id/secrets_store/stores/store-id/secrets";++const syncWith = (syncOptions: Record<string, unknown> = {}) =>+ ({+ destination: "cloudflare-secrets-store",+ destinationConfig: { storeId: "store-id", scopes: ["workers"] },+ environment: { slug: "prod" },+ syncOptions: { disableSecretDeletion: false, ...syncOptions },+ connection: { credentials: { apiToken: "token", accountId: "account-id" } }+ }) as unknown as TCloudflareSecretsStoreSyncWithCredentials;++const payloadOf = (keys: string[]) =>+ ({+ flatten: () => Object.fromEntries(keys.map((key) => [key, { value: `${key}-value` }]))+ }) as unknown as TSecretSyncPayload;++// Cloudflare's Secrets Store list endpoints report `total_count` but never `total_pages`.+const stubCloudflare = (+ pages: TCloudflareSecretsStoreSecret[][],+ { quota = 100, usage = 0, totalCount = pages.flat().length } = {}+) =>+ get.mockImplementation(async (url: string, config?: { params?: { page: number } }) =>+ url.endsWith("/quota")+ ? { data: { result: { secrets: { quota, usage } } } }+ : { data: { result: pages[(config?.params?.page ?? 1) - 1] ?? [], result_info: { total_count: totalCount } } }+ );++describe("CloudflareSecretsStoreSyncFns", () => {+ beforeEach(() => {+ vi.clearAllMocks();+ });++ it("rejects names Cloudflare would refuse before sending any request", async () => {+ await expect(+ CloudflareSecretsStoreSyncFns.syncSecrets(syncWith(), payloadOf(["VALID", "my-key.v2"]))+ ).rejects.toThrow("not a valid Cloudflare Secrets Store secret name: my-key.v2");++ expect(get).not.toHaveBeenCalled();+ });++ it("refuses a sync that would exceed the quota without writing anything", async () => {+ stubCloudflare([[]], { usage: 100 });++ await expect(CloudflareSecretsStoreSyncFns.syncSecrets(syncWith(), payloadOf(["NEW"]))).rejects.toThrow(+ "exceeds the Cloudflare account's limit of 100"+ );++ expect(post).not.toHaveBeenCalled();+ expect(del).not.toHaveBeenCalled();+ });++ it("writes with the sync's scopes, then deletes only stale secrets the key schema owns", async () => {+ stubCloudflare([+ [+ { id: "keep", name: "INF_KEEP" },+ { id: "stale", name: "INF_STALE" },+ { id: "manual", name: "MANUAL" }+ ]+ ]);++ await CloudflareSecretsStoreSyncFns.syncSecrets(+ syncWith({ keySchema: "INF_{{secretKey}}" }),+ payloadOf(["INF_KEEP", "INF_NEW"])+ );++ expect(patch).toHaveBeenCalledWith(+ `${SECRETS_URL}/keep`,+ { value: "INF_KEEP-value", scopes: ["workers"] },+ expect.anything()+ );+ expect(post).toHaveBeenCalledWith(+ SECRETS_URL,+ [{ name: "INF_NEW", value: "INF_NEW-value", scopes: ["workers"] }],+ expect.anything()+ );+ expect(del).toHaveBeenCalledTimes(1);+ expect(del).toHaveBeenCalledWith(`${SECRETS_URL}/stale`, expect.anything());+ expect(del.mock.invocationCallOrder[0]).toBeGreaterThan(+ Math.max(post.mock.invocationCallOrder[0], patch.mock.invocationCallOrder[0])+ );+ });++ it("reads every page when Cloudflare reports only total_count", async () => {+ stubCloudflare([[{ id: "first", name: "FIRST" }], [{ id: "second", name: "SECOND" }]], { totalCount: 51 });++ await CloudflareSecretsStoreSyncFns.removeSecrets(syncWith(), payloadOf(["FIRST", "SECOND"]));++ expect(del).toHaveBeenCalledWith(`${SECRETS_URL}/first`, expect.anything());+ expect(del).toHaveBeenCalledWith(`${SECRETS_URL}/second`, expect.anything());+ });+});diff --git a/backend/src/services/secret-sync/cloudflare-secrets-store/cloudflare-secrets-store-sync-fns.ts b/backend/src/services/secret-sync/cloudflare-secrets-store/cloudflare-secrets-store-sync-fns.tsindex 183c01f00d..b5fc1adcf2 100644--- a/backend/src/services/secret-sync/cloudflare-secrets-store/cloudflare-secrets-store-sync-fns.ts+++ b/backend/src/services/secret-sync/cloudflare-secrets-store/cloudflare-secrets-store-sync-fns.ts@@ -98,7 +98,9 @@ export const CloudflareSecretsStoreSyncFns = {if (usage + newSecretCount > quota) {throw new SecretSyncError({shouldRetry: false,- message: `This sync would create ${newSecretCount} secrets, which exceeds the Cloudflare account's limit of ${quota} Secrets Store secrets (${usage} in use). Secrets this sync removes are deleted only after the new ones are created, so they still count toward the limit. Delete unused secrets from the store or sync fewer secrets.`+ message: `This sync would create ${newSecretCount} ${+ newSecretCount === 1 ? "secret" : "secrets"+ }, which exceeds the Cloudflare account's limit of ${quota} Secrets Store secrets (${usage} in use). Secrets this sync removes are deleted only after the new ones are created, so they still count toward the limit. Delete unused secrets from the store or sync fewer secrets.`});}}diff --git a/docs/.vale/styles/config/vocabularies/Infisical/canonical/accept.txt b/docs/.vale/styles/config/vocabularies/Infisical/canonical/accept.txtindex 78f10c432b..fddaf94409 100644--- a/docs/.vale/styles/config/vocabularies/Infisical/canonical/accept.txt+++ b/docs/.vale/styles/config/vocabularies/Infisical/canonical/accept.txt@@ -199,6 +199,7 @@ Fly.ioDigitalOceanCloudflareCloudflare Pages+Cloudflare Secrets StoreCloudflare WorkersWindmillHumanitecdiff --git a/docs/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/create.mdx b/docs/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/create.mdxnew file mode 100644index 0000000000..ecca87cbbf--- /dev/null+++ b/docs/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/create.mdx@@ -0,0 +1,4 @@+---+title: "Create"+openapi: "POST /api/v1/secret-syncs/cloudflare-secrets-store"+---diff --git a/docs/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/delete.mdx b/docs/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/delete.mdxnew file mode 100644index 0000000000..c94e48fe26--- /dev/null+++ b/docs/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/delete.mdx@@ -0,0 +1,4 @@+---+title: "Delete"+openapi: "DELETE /api/v1/secret-syncs/cloudflare-secrets-store/{syncId}"+---diff --git a/docs/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/get-by-id.mdx b/docs/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/get-by-id.mdxnew file mode 100644index 0000000000..4704d4fa62--- /dev/null+++ b/docs/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/get-by-id.mdx@@ -0,0 +1,4 @@+---+title: "Get by ID"+openapi: "GET /api/v1/secret-syncs/cloudflare-secrets-store/{syncId}"+---diff --git a/docs/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/get-by-name.mdx b/docs/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/get-by-name.mdxnew file mode 100644index 0000000000..2ad202bbca--- /dev/null+++ b/docs/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/get-by-name.mdx@@ -0,0 +1,4 @@+---+title: "Get by name"+openapi: "GET /api/v1/secret-syncs/cloudflare-secrets-store/sync-name/{syncName}"+---diff --git a/docs/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/list.mdx b/docs/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/list.mdxnew file mode 100644index 0000000000..e4f702633d--- /dev/null+++ b/docs/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/list.mdx@@ -0,0 +1,4 @@+---+title: "List"+openapi: "GET /api/v1/secret-syncs/cloudflare-secrets-store"+---diff --git a/docs/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/remove-secrets.mdx b/docs/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/remove-secrets.mdxnew file mode 100644index 0000000000..c1bf9aaf18--- /dev/null+++ b/docs/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/remove-secrets.mdx@@ -0,0 +1,4 @@+---+title: "Remove secrets"+openapi: "POST /api/v1/secret-syncs/cloudflare-secrets-store/{syncId}/remove-secrets"+---diff --git a/docs/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/sync-secrets.mdx b/docs/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/sync-secrets.mdxnew file mode 100644index 0000000000..51b5af098f--- /dev/null+++ b/docs/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/sync-secrets.mdx@@ -0,0 +1,4 @@+---+title: "Sync secrets"+openapi: "POST /api/v1/secret-syncs/cloudflare-secrets-store/{syncId}/sync-secrets"+---diff --git a/docs/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/update.mdx b/docs/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/update.mdxnew file mode 100644index 0000000000..8d6fb7ec02--- /dev/null+++ b/docs/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/update.mdx@@ -0,0 +1,4 @@+---+title: "Update"+openapi: "PATCH /api/v1/secret-syncs/cloudflare-secrets-store/{syncId}"+---diff --git a/docs/docs.json b/docs/docs.jsonindex 39e18f1a06..d7907f1f8e 100644--- a/docs/docs.json+++ b/docs/docs.json@@ -252,6 +252,7 @@"integrations/secret-syncs/circleci","integrations/secret-syncs/cloud-66","integrations/secret-syncs/cloudflare-pages",+ "integrations/secret-syncs/cloudflare-secrets-store","integrations/secret-syncs/cloudflare-workers","integrations/secret-syncs/databricks","integrations/secret-syncs/daytona",@@ -3400,6 +3401,19 @@"api-reference/endpoints/secret-syncs/cloudflare-pages/remove-secrets"]},+ {+ "group": "Cloudflare Secrets Store",+ "pages": [+ "api-reference/endpoints/secret-syncs/cloudflare-secrets-store/list",+ "api-reference/endpoints/secret-syncs/cloudflare-secrets-store/get-by-id",+ "api-reference/endpoints/secret-syncs/cloudflare-secrets-store/get-by-name",+ "api-reference/endpoints/secret-syncs/cloudflare-secrets-store/create",+ "api-reference/endpoints/secret-syncs/cloudflare-secrets-store/update",+ "api-reference/endpoints/secret-syncs/cloudflare-secrets-store/delete",+ "api-reference/endpoints/secret-syncs/cloudflare-secrets-store/sync-secrets",+ "api-reference/endpoints/secret-syncs/cloudflare-secrets-store/remove-secrets"+ ]+ },{"group": "Cloudflare Workers","pages": [diff --git a/docs/integrations/app-connections/cloudflare.mdx b/docs/integrations/app-connections/cloudflare.mdxindex f4dc010d34..e861276779 100644--- a/docs/integrations/app-connections/cloudflare.mdx+++ b/docs/integrations/app-connections/cloudflare.mdx@@ -38,6 +38,17 @@ Infisical supports connecting to Cloudflare using API tokens and Account ID forAdd these permissions to your API token and click **Continue to summary**, then **Create Token** to generate your API token.</Accordion>+ <Accordion title="Cloudflare Secrets Store">+ Use the following permissions to grant Infisical access to sync secrets to Cloudflare Secrets Store:++ ++ **Required Permissions:**+ - **Account** - **Secrets Store** - **Edit**+ - **Account** - **Account Settings** - **Read**++ Add these permissions to your API token and select **Continue to summary**, then **Create Token** to generate your API token.+ </Accordion><Accordion title="Cloudflare Workers">Use the following permissions to grant Infisical access to sync secrets to Cloudflare Workers:diff --git a/docs/integrations/secret-syncs/cloudflare-secrets-store.mdx b/docs/integrations/secret-syncs/cloudflare-secrets-store.mdxnew file mode 100644index 0000000000..b6eaabf9d9--- /dev/null+++ b/docs/integrations/secret-syncs/cloudflare-secrets-store.mdx@@ -0,0 +1,156 @@+---+title: "Cloudflare Secrets Store sync"+sidebarTitle: "Cloudflare Secrets Store"+description: "Learn how to configure a Cloudflare Secrets Store sync for Infisical."+---++A Cloudflare Secrets Store Sync pushes secrets from Infisical into your Cloudflare account's [Secrets Store](https://developers.cloudflare.com/secrets-store/), where Workers, AI Gateway, and Containers can use them. Each Infisical secret becomes a Secrets Store secret, with the same name unless you customize key names to add a prefix or suffix.++## Prerequisites++- A [project with secrets configured](/documentation/platform/secrets-mgmt/quick-starts/deliver-first-secret)+- A [Cloudflare app connection](/integrations/app-connections/cloudflare) whose API token has the **Account** > **Secrets Store** > **Edit** and **Account** > **Account Settings** > **Read** permissions+- A store in your Cloudflare account (Cloudflare creates it the first time a Super Administrator or Secrets Store Admin opens **Secrets Store** in the Cloudflare dashboard)++## Step 1: Set up the sync in Infisical++<Tip>+ To create the sync using the API, use the [Create Cloudflare Secrets Store Sync](/api-reference/endpoints/secret-syncs/cloudflare-secrets-store/create) endpoint.+</Tip>++<Steps>+ <Step>+ In your project, go to **Integrations** and open the **Secret Syncs** tab. Select **+ Add Sync**.++ ++ Then, select the **Cloudflare Secrets Store** sync.++ + </Step>+ <Step>+ Under **Source**, choose which secrets to sync from Infisical:++ - **Environment**: The project environment to retrieve secrets from+ - **Secret Path**: The folder path to retrieve secrets from+ - **Include secrets from all subfolders**: Also syncs the secrets in every folder beneath the path (secret names must be unique across all of them)++ <Note>+ Secrets Store secret names can contain only letters, digits, hyphens, and underscores, and so can the prefix or suffix you add when you customize key names. If any secret at this path has a name Cloudflare rejects, the sync fails without writing any secrets, and the error names each rejected key.+ </Note>++ <Tip>+ If you need to sync secrets from multiple folder locations, use [secret imports](/documentation/platform/secret-reference#secret-imports).+ </Tip>++ Then select **Continue**.+ </Step>+ <Step>+ Under **Destination**, select the Cloudflare app connection the sync will use, then choose where secrets go in Cloudflare. To create a connection here, select **Create Connection** in the **Cloudflare Connection** dropdown and fill in the fields described in the [Cloudflare app connection guide](/integrations/app-connections/cloudflare).++ - **Secrets Store**: The store to sync secrets to+ - **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.+ </Note>++ ++ Then select **Continue**.+ </Step>+ <Step>+ Under **Initial Sync Behavior**, select **Overwrite Cloudflare Secrets Store**, then select **Continue**.++ <Note>+ Cloudflare never returns a secret's value, so this sync can't import existing Secrets Store secrets into Infisical. **Overwrite Cloudflare Secrets Store** is the only option.+ </Note>++ + </Step>+ <Step>+ Under **Sync Options**, choose how secrets are synced:++ - **Prevent secret deletion**: When enabled, Infisical adds and updates secrets in Cloudflare but never deletes them; enable this if you manage some Secrets Store secrets outside of Infisical+ - **Auto-sync on changes**: When enabled, secrets sync to Cloudflare automatically as the source changes; turn it off to sync manually only+ - **Customize key names**: Adds a prefix or suffix to every synced name, using `{{secretKey}}` for the original name and `{{environment}}` for the environment slug++ <Warning>+ Secrets Store secrets belong to the whole Cloudflare account, so a sync can change secrets that were created outside Infisical. If you don't customize key names, the sync treats every secret in the store as one it manages:++ - If a Secrets Store secret has the same name as an Infisical secret, the sync overwrites the Secrets Store secret's value and scopes+ - If **Prevent secret deletion** is off, every Secrets Store secret that isn't in Infisical is deleted++ With customized key names, the sync writes only names with your prefix or suffix, and deletes only Secrets Store secrets whose names match it.++ Before the first sync, customize key names or keep **Prevent secret deletion** on. **Prevent secret deletion** is on by default when you create the sync in the UI, but off unless you set `disableSecretDeletion` when you create it through the API.+ </Warning>++ ++ Then select **Continue**.+ </Step>+ <Step>+ Give the sync a **Name** and an optional **Description**. The name must be slug-friendly.++ ++ Then select **Continue**.+ </Step>+ <Step>+ Review your Cloudflare Secrets Store Sync configuration, then select **Create Sync**.++ ++ <Check>+ The sync is created. If **Auto-sync on changes** is enabled, it begins syncing secrets to your Secrets Store right away.+ </Check>+ </Step>+</Steps>++## Step 2: Use the secrets in Cloudflare Workers++A Worker can read a Secrets Store secret only through a binding in the Worker's configuration, and Infisical doesn't create bindings. After the first sync creates your secrets, add a binding for each secret the Worker uses. The secret must have the **Workers** scope, or Cloudflare rejects the binding when you deploy the Worker.++<Steps>+ <Step>+ In the Cloudflare dashboard, open **Secrets Store** and copy the store ID.+ </Step>+ <Step>+ In the Worker's Wrangler configuration file, add an entry to `secrets_store_secrets` for each secret, then deploy the Worker:++ ```jsonc+ {+ "secrets_store_secrets": [+ { "binding": "API_KEY", "store_id": "<store-id>", "secret_name": "API_KEY" }+ ]+ }+ ```++ In the Worker's code, read the value with `await env.API_KEY.get()`.+ </Step>+</Steps>++To use the secrets with AI Gateway or Containers, see Cloudflare's [Secrets Store documentation](https://developers.cloudflare.com/secrets-store/).++## FAQ++<AccordionGroup>+ <Accordion title="How many secrets can a sync write?">+ While Secrets Store is in open beta, a Cloudflare account can hold 100 Secrets Store secrets in total, including secrets that other syncs and tools created. Before writing anything, the sync checks whether its new secrets fit. If they don't fit, the sync fails without writing any secrets. Secrets that the sync removes are deleted only after the new secrets are created, so they still count toward the limit during that sync.+ </Accordion>+ <Accordion title="What happens when I rename a secret in Infisical?">+ Cloudflare can't rename a secret, so the sync creates a secret with the new name. If **Prevent secret deletion** is off, the sync then deletes the secret with the old name. Update the `secret_name` in any Worker binding that used the old name.+ </Accordion>+</AccordionGroup>++## Next steps++<CardGroup cols={2}>+ <Card title="Cloudflare" icon="plug" href="/integrations/app-connections/cloudflare">+ Manage the API token and permissions the sync uses.+ </Card>+ <Card title="Secret syncs overview" icon="refresh-cw" href="/integrations/secret-syncs/overview">+ Learn how syncs run, how key schemas work, and how to sync subfolders.+ </Card>+</CardGroup>diff --git a/docs/snippets/catalogs/integrations.jsx b/docs/snippets/catalogs/integrations.jsxindex 9266201f09..a948a8d753 100644--- a/docs/snippets/catalogs/integrations.jsx+++ b/docs/snippets/catalogs/integrations.jsx@@ -99,6 +99,7 @@ export const integrations = [{ name: "Spacelift", path: "/integrations/secret-syncs/spacelift", description: "Learn how to sync secrets from Infisical to Spacelift.", type: "Secret Sync", tag: "DevOps Tools" },{ name: "Cloudflare Pages", path: "/integrations/secret-syncs/cloudflare-pages", description: "Learn how to sync secrets from Infisical to Cloudflare Pages.", type: "Secret Sync", tag: "Hosting" },{ name: "Cloudflare Workers", path: "/integrations/secret-syncs/cloudflare-workers", description: "Learn how to sync secrets from Infisical to Cloudflare Workers.", type: "Secret Sync", tag: "Cloud Providers" },+ { name: "Cloudflare Secrets Store", path: "/integrations/secret-syncs/cloudflare-secrets-store", description: "Learn how to sync secrets from Infisical to Cloudflare Secrets Store.", type: "Secret Sync", tag: "Cloud Providers" },{ name: "Databricks", path: "/integrations/secret-syncs/databricks", description: "Learn how to sync secrets from Infisical to Databricks.", type: "Secret Sync", tag: "Data Analytics" },{ name: "Windmill", path: "/integrations/secret-syncs/windmill", description: "Learn how to sync secrets from Infisical to Windmill.", type: "Secret Sync", tag: "DevOps Tools" },{ name: "Camunda", path: "/integrations/secret-syncs/camunda", description: "Learn how to sync secrets from Infisical to Camunda.", type: "Secret Sync", tag: "DevOps Tools" },