Skip to content

cf deploy drops existing Worker secrets #70

Closed
cloudflare/workers-sdk
#15964

Description

@mauricekleine

cf deploy uploads a new Worker version without the Worker's existing secrets. Wrangler keeps them in the same sequence.

I hit this migrating my personal site with cf migrate. Workers Builds ran cf deploy --prebuilt on merge, the new version went live, and the four secrets behind the newsletter signup were gone. A rollback got production working again. The secrets are still missing from the latest version though, so every later upload inherits nothing.

Repro

cf 1.0.0-beta.5, Node 24, macOS. Fresh cf init template, only renamed:

cf init repro-cf --package-manager bun
cd repro-cf
cf deploy
cf workers secrets update FOO --worker repro-cf --type secret_text --text dummy
cf workers secrets list --worker repro-cf   # [FOO]
cf deploy
cf workers secrets list --worker repro-cf   # []

A project converted with cf migrate --bundler wrangler shows the same result, as does a Vite project deployed with cf deploy --prebuilt.

The same steps with [email protected] (wrangler deploy, wrangler secret put FOO, wrangler deploy) keep FOO.

Expected

cf deploy keeps the secrets already set on the Worker, like wrangler deploy does. cf workers versions create keeps them.

What I found

createSharedProps in packages/cli/src/lib/deploy-input.ts passes keepVars: config.keep_vars ?? false and secretsFile to @cloudflare/deploy-helpers. The deploy there sets keepSecrets: keepVars || !!props.secretsFile, so keep_bindings never includes secret_text and the versions API gets no instruction to inherit secrets. cloudflare.config.ts has no keepVars equivalent and cf deploy has no --keep-vars flag, so a cf project can't opt in either.

Wrangler 4.141 contains the same keepSecrets expression, so the difference probably lies elsewhere in how Wrangler calls deploy. I didn't track that down.

Workaround

Declare each secret with bindings.secret() in cloudflare.config.ts. cf deploy then fails with "required secrets have not been set" instead of silently dropping them. That at least fails closed. It doesn't help once the latest version has already lost the secrets, because inheritance reads from the latest version, not the deployed one.

Setting them again by hand works, provided you still have the values. I don't have all of mine.

Activity

  1. a1local commented on Sep 29, 2026

    @a1local

    Same here on 1.0.0-beta.5 after cf migrate (Wrangler bundler): first cf deploy shipped a production version with 0 of 3 secrets; rolled back with wrangler rollback. One more gap: neither cf deploy --dry-run nor the deploy output lists secret names, so there's no signal before it goes live. Showing secret names (not values), and warning when they differ from the live version, would have caught it.

  2. neotan commented on Sep 29, 2026

    @neotan

    Candidate fix and analysis: #72 (comment). In short: deploy always sends secret keep_bindings, the same thing --secrets-file already triggers.

  3. added 2 commits that reference this issue on Sep 29, 2026
    925d5c9
    3b8b44e
  4. added theissue type on Sep 30, 2026
  5. added a commit that references this issue on Sep 30, 2026
    45c6813
  6. karanbalaji commented on Sep 30, 2026

    @karanbalaji

    Confirming this independently — hit it migrating a production Worker (cf migrate wrangler.json, first cf deploy afterward silently dropped all 8 existing secrets, wrangler secret list → []). The bindings.secret() fail-closed workaround described above works and is what we landed on, but it surfaced a follow-up gap worth flagging here since it's directly downstream of the same root cause:

    bindings.secret() has no "optional" mode, so it can't protect a secret that's genuinely optional in the application (in our case, an optional QA_GOAL env var the Worker reads with a fallback if unset). Declaring it as bindings.secret() makes cf deploy refuse to deploy at all until it's set — not appropriate for something meant to be opt-in. Leaving it undeclared to avoid that means it's back to being silently wiped by the next unrelated deploy if a user ever does set it. There doesn't currently seem to be a way to say "if this secret is set, keep it; if not, that's fine" — which the pre-cf behavior (secrets just persist until explicitly deleted) supported for free.

    Also separately filed #96 for a related-but-distinct bug: cf workers secrets update (a single named secret) also replaces the entire secret set rather than patching, via a PUT to /secrets instead of bulk's PATCH to /secrets-bulk — hit it a second time mid-recovery from this exact issue.

  7. jamesopstad commented on Sep 30, 2026

    @jamesopstad
    Contributor
  8. mauricekleine commented on Sep 30, 2026

    @mauricekleine
    Author

    Thanks @jamesopstad!

  9. added a commit that references this issue on Nov 10, 2026
    1eedfea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions