Skip to content

Save template secrets when publishing instead of carrying them in hosted commands - #426

Merged
tnkuehne merged 1 commit into
mainfrom
fix/template-secrets-at-publish
Nov 26, 2026
Merged

tnkuehne merged 1 commit into
mainfrom
fix/template-secrets-at-publish

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

A template install asks for the secrets its code requires and saves them with its first deployment. On Cloudflare, the install put the encrypted values into the deployment command. The command is stored in R2 at apps/<appId>/commands/<id>.json and passed to the deployment Workflow as its parameters. Registration then saved the values to the app and removed them only from the SQL history, so the R2 copy stayed until the app was removed and the Workflow copy until the instance expired. Those copies kept changed or deleted values, and values under encryption keys that were rotated out.

The values travelled with the command so that only the deployment Cloudflare accepted first received them. That order protected nothing: a deployment that wins the race comes from someone who can deploy to the app, and any later deployment of theirs can read the app's secrets.

Changes

  • uploads.publish. Publishing saves the install's secrets under the app lock on both executions, as an agent installation already did. If another deployment prepared at the same time is accepted first, the install is still rejected and the app keeps the saved secrets.
  • Deployment command. secrets is removed from the hosted deploy command and from HostedExecution.deploy. registerCloudflareOperation keeps the first-deployment check and no longer saves secrets or strips them from the history.
  • enqueueDeployment. suppliedSecrets is removed, since the app now holds the values before the required-secret check runs.

Commands stored by earlier template installs keep their encrypted values until the app is removed.

Testing

  • pnpm check
  • tests/cloudflare-operations.integration.test.ts
    • saves a template's secrets when publishing and sends Cloudflare no secret values: hosted publish saves the secrets in the app row and calls deploy without them. Fails without the change.
    • accepts a template install only as the app's first deployment replaces the registration test of secret saving and keeps its first-deployment and retry checks.
  • tests/template-installs.integration.test.ts, tests/required-secrets.integration.test.ts
  • tests/cloudflare/deployment.test.ts (workerd): deploys app services with private secrets and follows their activated versions, through the changed fixture. The test that passed secrets through the command is removed. The first-deployment check is covered by the registration test, and secrets come from the app row as for every other deployment.

Confidence Score: 5/5 · The PR appears safe to merge; no actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5 Tier: apex

The PR appears safe to merge; no actionable issues were found.

Summary

Saves template secrets during uploads.publish and removes them from hosted deployment commands.

  • Template secrets are saved on the app before hosted deployment.

Intentional choices acknowledged by tnkuehne:

  • Secrets remain if another prepared deployment wins the acceptance race, since app deployers can already read them through their code.
  • Older command copies remain until app removal or Workflow expiry.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["Template install"] --> B["Publish under app lock"]
  B --> C["Save encrypted secrets on app"]
  C --> D["Check required secret names"]
  D --> E["Commit"]
  E --> F["Store hosted command without secret values"]
  F --> G["Register and check first deployment"]
  G --> H["Activate deployment"]
  C -. "Read current app secrets" .-> H
Loading

Reviews (1) · Last reviewed commit: "Save template secrets when publishing in..." · Reviewed by Greptile

…ted commands

A template install on Cloudflare put its encrypted secrets into the deployment
command, which is stored in R2 and passed as Workflow parameters. Registration
saved them to the app and removed them only from the SQL copy, so both copies
stayed until the app was removed or the Workflow instance expired.

Publishing now saves the secrets under the app lock on both executions, and the
command carries no secret values.
@tnkuehne
tnkuehne merged commit a3acce1 into main Nov 26, 2026
16 of 18 checks passed
@tnkuehne
tnkuehne deleted the fix/template-secrets-at-publish branch November 26, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant