You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cf deploy deletes all existing Worker secrets unless --secrets-file is passed #72
cf version: 1.0.0-beta.5 (Wrangler 4.143.0 as the delegated bundler), macOS and Linux CI
What happens
A plain cf deploy of a Worker project removes every secret already set on the Worker. wrangler deploy never did this: its docs say "Wrangler will not delete your secrets unless you run wrangler secret delete <key>". After cf migrate, the first cf deploy in production took our Worker's secret list from ['VIEW_PUBLISH_SECRET'] to [].
Passing --secrets-file with an empty {} file keeps every existing secret. So the keep-behaviour exists; it just isn't the default.
Repro (throwaway Worker, no bindings, workersDev: false)
Secrets were read with GET /accounts/<id>/workers/scripts/<name>/secrets after each step.
Expected
Keep existing secrets on deploy by default, as Wrangler does, or at minimum warn before removing them. cf migrate could also flag this, since a migrated project's first deploy silently drops production secrets.
Standalone reproduction on cf 1.0.0-beta.5, Node 24.4.1, Bun 1.4.2, macOS. This uses a local mock API, dummy credentials, and a tiny prebuilt Worker. No Cloudflare account, existing Worker, or application repository is required. Telemetry is disabled.
Install in a fresh directory:
mkdir cf-72-repro
cd cf-72-repro
printf'{"private":true}\n'> package.json
bun add --exact [email protected]
Save the following as secrets-repro.mjs and run node secrets-repro.mjs. The script asserts the observed beta.5 behavior and removes its temporary Worker output afterward.
The fixture reports an existing EXISTING_SECRET. With no declaration in the config, the actual multipart upload contains neither an inheritance binding for it nor keep_bindings: ["secret_text"]. Declaring it as { type: "secret" } produces the inheritance binding in the second run.
This isolates the request-construction behavior behind this issue; it does not simulate or claim to independently verify the live API's deletion behavior. Both deploys are handled entirely by the loopback server. This also provides a local reproduction relevant to #70.
Expected: preserve existing secrets by default, or refuse the deployment with an explicit explanation before omitting them.
I think I found why this happens, and there's a fix on my fork: neotan/cf@main...neotan:cf:fix/deploy-keep-secrets. This repo doesn't accept pull requests from outside, so feel free to copy it or take it over.
When you deploy a Worker that already exists, cf uploads the new code and has to tell Cloudflare what to carry over from the previous version. It only asks to carry over secrets when you pass --secrets-file or turn on keep_vars. A plain cf deploy never asks, so the new version goes live without them. That's also why step 5 above works: any secrets file, even an empty {}, turns that request on.
The fix is a one-line change to the patch cf already keeps for @cloudflare/deploy-helpers: always ask to keep secrets on deploy. cf workers versions create already does this. I added a test for the exact case here, an existing Worker with no secrets listed in its config. It failed before the change and passes after it, and pnpm check passes.
There's one part I can't explain yet. Wrangler has the same line, and its own tests expect a normal deploy not to send this request. People here still say wrangler deploy keeps their secrets. I compared what the two tools send and found no difference, so Cloudflare's side may be treating them differently. Someone who can see the API side should check that before this goes into workers-sdk.
Heads-up: #93 edits the same patch file and plans to delete it after upgrading deploy-helpers. If that lands first, this change needs to come along with it or be fixed in workers-sdk.
This is now fixed upstream in cloudflare/workers-sdk#15964, which makes the same change in deploy-helpers. That PR also explains the Wrangler difference: the backend was keeping secrets for Wrangler deploys. Once cf picks up the next deploy-helpers release, my fork branch isn't needed.
Activity
matthewbjones commentedon Sep 29, 2026
Standalone reproduction on cf 1.0.0-beta.5, Node 24.4.1, Bun 1.4.2, macOS. This uses a local mock API, dummy credentials, and a tiny prebuilt Worker. No Cloudflare account, existing Worker, or application repository is required. Telemetry is disabled.
Install in a fresh directory:
Save the following as
secrets-repro.mjsand runnode secrets-repro.mjs. The script asserts the observed beta.5 behavior and removes its temporary Worker output afterward.Complete reproduction script
Observed output:
{"declared":false,"exit":0,"secretBinding":null,"keepBindings":null} {"declared":true,"exit":0,"secretBinding":{"name":"EXISTING_SECRET","type":"inherit"},"keepBindings":null}The fixture reports an existing
EXISTING_SECRET. With no declaration in the config, the actual multipart upload contains neither an inheritance binding for it norkeep_bindings: ["secret_text"]. Declaring it as{ type: "secret" }produces the inheritance binding in the second run.This isolates the request-construction behavior behind this issue; it does not simulate or claim to independently verify the live API's deletion behavior. Both deploys are handled entirely by the loopback server. This also provides a local reproduction relevant to #70.
Expected: preserve existing secrets by default, or refuse the deployment with an explicit explanation before omitting them.
neotan commentedon Sep 29, 2026
I think I found why this happens, and there's a fix on my fork: neotan/cf@main...neotan:cf:fix/deploy-keep-secrets. This repo doesn't accept pull requests from outside, so feel free to copy it or take it over.
When you deploy a Worker that already exists, cf uploads the new code and has to tell Cloudflare what to carry over from the previous version. It only asks to carry over secrets when you pass
--secrets-fileor turn onkeep_vars. A plaincf deploynever asks, so the new version goes live without them. That's also why step 5 above works: any secrets file, even an empty{}, turns that request on.The fix is a one-line change to the patch cf already keeps for
@cloudflare/deploy-helpers: always ask to keep secrets on deploy.cf workers versions createalready does this. I added a test for the exact case here, an existing Worker with no secrets listed in its config. It failed before the change and passes after it, andpnpm checkpasses.There's one part I can't explain yet. Wrangler has the same line, and its own tests expect a normal deploy not to send this request. People here still say
wrangler deploykeeps their secrets. I compared what the two tools send and found no difference, so Cloudflare's side may be treating them differently. Someone who can see the API side should check that before this goes into workers-sdk.Heads-up: #93 edits the same patch file and plans to delete it after upgrading deploy-helpers. If that lands first, this change needs to come along with it or be fixed in workers-sdk.
fix: keep existing Worker secrets on cf deploy
fix: keep existing Worker secrets on cf deploy
fix: keep existing Worker secrets on cf deploy
neotan commentedon Sep 30, 2026
This is now fixed upstream in cloudflare/workers-sdk#15964, which makes the same change in deploy-helpers. That PR also explains the Wrangler difference: the backend was keeping secrets for Wrangler deploys. Once cf picks up the next deploy-helpers release, my fork branch isn't needed.
lnv-louis commentedon Oct 3, 2026
I second this.
fix: keep existing Worker secrets on cf deploy