Skip to content

[wrangler] Add --secrets-file and --var flags to wrangler preview - #15256

Open
theoephraim wants to merge 5 commits into
cloudflare:mainfrom
theoephraim:preview-secrets-file-var-flags
Open

[wrangler] Add --secrets-file and --var flags to wrangler preview#15256
theoephraim wants to merge 5 commits into
cloudflare:mainfrom
theoephraim:preview-secrets-file-var-flags

Conversation

@theoephraim

@theoephraim theoephraim commented Aug 18, 2026

Copy link
Copy Markdown

Adds --secrets-file and --var flags to the wrangler preview command [private beta], matching the equivalent flags on wrangler deploy and wrangler versions upload.

  • --secrets-file <path> is parsed with the shared parseBulkInputToObject helper (JSON or .env format) and the secrets are sent as secret_text bindings on the Preview deployment.
  • --var KEY:VALUE pairs are parsed with collectKeyValues and sent as plain_text bindings.
  • Precedence: config previews vars → --var--secrets-file, matching how wrangler deploy layers these sources.

Note: this deliberately does not add --define and --alias (which deploy/versions also support) — the preview command currently reads those only from config. They can be added later if needed.

Motivation: these flags let env/secret management tooling inject values into Preview deployments the same way it already can for deploy and versions upload, without writing them into the Wrangler config file. Concretely, varlock's wrangler integration uses them to pass non-sensitive values via --var and sensitive values via --secrets-file — see the companion PR: dmno-dev/varlock#1018.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: wrangler preview is in private beta and not yet publicly documented.

Devin Review

@changeset-bot

changeset-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a96bda4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@cloudflare/deploy-helpers Minor
wrangler Minor
@cloudflare/remote-bindings Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Aug 18, 2026
@workers-devprod
workers-devprod requested review from a team and penalosa and removed request for a team August 18, 2026 18:42
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/preview-secrets-file-flag.md: [@cloudflare/wrangler]
  • packages/deploy-helpers/src/preview/preview.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/preview.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/preview/preview.ts: [@cloudflare/wrangler]

@pkg-pr-new

pkg-pr-new Bot commented Aug 18, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@15256

@cloudflare/build-output-utils

npm i https://pkg.pr.new/@cloudflare/build-output-utils@15256

@cloudflare/codemods

npm i https://pkg.pr.new/@cloudflare/codemods@15256

@cloudflare/config

npm i https://pkg.pr.new/@cloudflare/config@15256

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@15256

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@15256

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@15256

miniflare

npm i https://pkg.pr.new/miniflare@15256

@cloudflare/pages-functions

npm i https://pkg.pr.new/@cloudflare/pages-functions@15256

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@15256

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@15256

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@15256

@cloudflare/vitest-plugin

npm i https://pkg.pr.new/@cloudflare/vitest-plugin@15256

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@15256

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@15256

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@15256

wrangler

npm i https://pkg.pr.new/wrangler@15256

commit: a96bda4

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 potential issues.

View 2 additional findings in Devin Review.

Open in Devin Review

Comment thread packages/deploy-helpers/src/preview/preview.ts Outdated
Comment on lines +288 to +291
// Vars from the CLI (--var) override same-named vars from the previews config
for (const [varName, varValue] of Object.entries(options.cliVars ?? {})) {
env[varName] = { type: "plain_text", text: varValue };
}

@devin-ai-integration devin-ai-integration Bot Aug 18, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟨 CLI-provided variables are sent to the preview API without the marker used elsewhere to keep values out of logs

The deploy and versions-upload paths tag --var values with hidden: true specifically so their values are never printed (packages/deploy-helpers/src/deploy/deploy.ts:246-252, packages/deploy-helpers/src/deploy/versions-upload.ts:102-108, consumed at packages/deploy-helpers/src/deploy/helpers/print-bindings.ts:737-744). The new preview path adds the same CLI-supplied values as plain { type: "plain_text", text } bindings with no hidden marker, so if any current or future preview output path renders binding values (e.g. preview settings display, or --json, which prints the API's echoed deployment env at packages/deploy-helpers/src/preview/preview.ts:470-473), values passed on the command line could be written to the terminal or output file.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hidden marker is client-side display metadata only — even in the deploy path it's stripped before upload (create-worker-upload-form.ts sends just {name, type: "plain_text", text}) and it's consumed solely by print-bindings.ts, which the preview command doesn't use. Preview's human-readable output never prints binding values, so there's no output path for the marker to guard, and the previews API has no such field. --json intentionally echoes the API's deployment resource verbatim — the same data any deployment GET returns. Per the flag docs, sensitive values should go through --secrets-file, which sends them as secret_text.

Comment thread packages/deploy-helpers/src/preview/preview.ts
Comment thread packages/deploy-helpers/src/preview/preview.ts
devin-ai-integration[bot]

This comment was marked as resolved.

@theoephraim
theoephraim force-pushed the preview-secrets-file-var-flags branch from e26b989 to db1443c Compare August 19, 2026 04:41
@WillTaylorDev

Copy link
Copy Markdown
Contributor

Changes LGTM, though we do have merge conflicts which we'll want to fix up before approvals :)

@theoephraim
theoephraim force-pushed the preview-secrets-file-var-flags branch from db1443c to d039273 Compare August 24, 2026 19:27
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/preview-secrets-file-flag.md: [@cloudflare/wrangler]
  • packages/deploy-helpers/src/preview/preview.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/preview.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/preview/preview.ts: [@cloudflare/wrangler]

@theoephraim
theoephraim force-pushed the preview-secrets-file-var-flags branch from d039273 to 8c280ed Compare August 24, 2026 19:42
theoephraim added a commit to theoephraim/workers-sdk that referenced this pull request Aug 25, 2026
Extend --secrets-file-mode to the private beta preview surface, on top of
the base --secrets-file/--var support for wrangler preview added in the
preview-secrets-file-var-flags branch (PR cloudflare#15256). With
--secrets-file-mode replace, wrangler preview converges the new Preview
deployment's secret set to the file by reading the effective env off the
create response and cutting one follow-up deployment that deletes the
unlisted secrets (the server-side merge of base config and carried-over
secrets cannot be suppressed in the create request); the secret-value
redaction now runs after that convergence so the follow-up deployment's
echoed env is redacted too. wrangler preview secret bulk accepts
--secrets-file-mode replace as well, deleting existing secrets not
present in the input within the same patch. secrets.required names are
never dropped, the deletion warning is always logged, and behavior
without the new flag is unchanged.
A bad file path or malformed contents now fails before the preview
resource is created or assets are uploaded, instead of leaving a
half-finished preview behind.
The API may echo the uploaded env on the deployment response; strip
secret_text values as soon as it is received so --json output can never
print them, matching how preview secret list only outputs names/types.
The diverged-config warning compared top-level bindings against config
preview bindings only, so names supplied via --var or --secrets-file
were reported as missing even though they were uploaded. Compare against
the env that was actually sent with the deployment instead.
…tests

Preview deployments are now uploaded as multipart form data (cloudflare#15375), so
the secrets/vars test mocks read the request via the shared
readPreviewDeploymentRequest helper instead of request.json().
@theoephraim
theoephraim force-pushed the preview-secrets-file-var-flags branch from c3ee1ae to a96bda4 Compare August 28, 2026 18:42
@theoephraim

Copy link
Copy Markdown
Author

@WillTaylorDev - let me know if there is anything else I can help with to get this over the finish line! Your time is much appreciated.

Also fyi - somewhat related discussions over in #15122

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

3 participants