Repository navigation
Save template secrets when publishing instead of carrying them in hosted commands - #426
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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>.jsonand 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.secretsis removed from the hosted deploy command and fromHostedExecution.deploy.registerCloudflareOperationkeeps the first-deployment check and no longer saves secrets or strips them from the history.enqueueDeployment.suppliedSecretsis 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 checktests/cloudflare-operations.integration.test.tssaves a template's secrets when publishing and sends Cloudflare no secret values: hosted publish saves the secrets in the app row and callsdeploywithout them. Fails without the change.accepts a template install only as the app's first deploymentreplaces 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.tstests/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.Summary
Saves template secrets during
uploads.publishand removes them from hosted deployment commands.Intentional choices acknowledged by tnkuehne:
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" .-> HReviews (1) · Last reviewed commit: "Save template secrets when publishing in..." · Reviewed by Greptile