Repository navigation
RFC: letting a config or tool own a Worker's runtime env (vars + secrets) #16328
theoephraim
started this conversation in
RFCs
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This pulls together #15343, discussion #15122, and a handful of
cfissues into one place. I maintain varlock and our Cloudflare integration, which is how I keep running into these edges, but none of this is specific to it. Any config-as-code or secrets-manager workflow (Doppler, Infisical, 1Password, Vault, a homegrown script) hits the same gaps, and some of this is just related to workers env var DX more generally.It's all somewhat connected, so the goal here is to get the problems written down coherently and make sure we think about it holistically.
Constraints I am taking as given
cloudflare.config.ts. (James in Feature request: supply secret values programmatically in the new config (cloudflare.config.ts) #15122.) Anything proposed here has to work with the config evaluated once at build time, including under the Vite plugin.cf deploywiped production secrets (cf deploy drops existing Worker secrets cf#70, Implement--polyfill-node/config.polyfill_node#72). Any opt-in to removal has to be explicit, loud, and visible in dry-run.The problems
1. No supported way to supply secret values from the config
bindings.secret()declares a secret but cannot carry a value. The only in-config channel isunsafe:secret_text, which warns on every deploy and tells you to use the out-of-band flows it exists to avoid.cf deployhas--secrets-filebut no--var, andcloudflare.config.tshas nokeep_vars(cloudflare/cf#197, #200). The programmable config is the natural place for this, and the upload API already accepts the result (secret_textbindings with text).This is also the root of cloudflare/cf#31 (first deploy of a Worker with required secrets fails because the secret cannot be set before the Worker exists). If the deploy carries the values, there is no circular dependency.
2. The Vite / Build Output flow has no secure value channel at all
With Vite, the config is evaluated at build and serialized to
dist/.../wrangler.json(and the Build Output). A value supplied in config would be written to disk in plaintext. So "supply values from config" needs a defined way for values to cross the build/deploy boundary without the output carrying them.3. Deploys cannot converge the secret set
Deploys are now 100% additive for secrets. Vars are declarative (the upload carries the total set;
keep_varsis the opt-out), but there is no equivalent for secrets. A tool that wants "the Worker's env is exactly what the config declares" cannot express it. Removing a secret from the declared set means a separatesecret deleteafter the deploy, which is a second deployment and a window where the live env is wrong.The upload API already supports total replacement (omit
keep_bindings), so forwrangler deployandversions uploadthis is a client-side opt-in. The bulk secret commands use a merge PATCH, so convergence there means reading first. Previews are the one place that needs an API change: since #16102 the client inherits prior-deployment secrets explicitly, but Preview base-config env is merged server-side on every deployment, and there is no per-deployment way to exclude it (ignore_base_configon preview creation is too blunt: it also drops observability, logpush, limits, placement, cache, tail consumers).4. Vars and secrets have diverged in the CLI but not in the API or config
The upload API treats both as bindings and
keep_bindingsis per type.cloudflare.config.tsalready putsbindings.text()andbindings.secret()in oneenvmap. The asymmetry lives in the wrangler CLI (--varvs--secrets-file,keep_varsvs nothing) and in which options each binding accepts. If the config is the source of truth, the posture (merge vs replace) and the value options should be the same for both, with sensitivity being the only difference.5. Visibility
There is no names-only view of what a deploy will do to the secret set. Commenters on cloudflare/cf#70 asked for secret names in dry-run and a warning when they differ from the live version. Any removal behaviour needs that to be reviewable before it runs.
A sketch of what could address this in the new declarative config
Posted in #15122 already, repeated here so this thread is self-contained.
Plus a settings-level posture, something like
env: { mode: "merge" | "replace" }, meaning "the configured env is the complete set". That one switch covers #15343 and cloudflare/cf#197 and keeps the decision in the config rather than per invocation. Wrangler could still expose a CLI override for thewrangler.jsonworld.Values cross the build/deploy boundary one of three ways, none of which evaluates the config at deploy:
fromEnv) that the deployer dereferences natively. No user code runs, so the output stays a complete spec.Declarations (names only) always serialize, so types, dev var scoping, and the
secrets.requiredbackstop keep working. Resolved values never sit on the config object, so they structurally cannot reach the serialized output or type-gen.Secrets that must survive deploys regardless of config can live in Workers Builds build secrets and be passed through by the tool, so replace mode needs no carve-out beyond
secrets.required.Phasing, if any of this lands
wrangler deploy/versions upload(the closed [wrangler] add replace mode for --secrets-file #15357 has a working implementation, minus the preview half).value/fromEnv/requiredoptions in@cloudflare/config, and the build-output representation for references and the encrypted payload.env_mode(or equivalent) on the Previews deployment API.Open questions for you
fromEnvreference acceptable inside the Build Output Specification, or should it live adjacent to it?previews_base_config.envinto every deployment? If so, is a per-deployment exclusion feasible?cf?Related
optionaloption tobindings.secret()#15273, [wrangler] Expand dotenv values in secrets files #15955--polyfill-node/config.polyfill_node#72, Added optional shortcuts #96, restartdevwhen session expires #197, modify changelog format #200cc @petebacondarwin @jamesopstad @ericclemmons
tagging for visibility since y'all have been involved with these issues/PRs
All reactions