Repository navigation
Add a command that re-encrypts stored secrets - #398
Merged
Merged
Conversation
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
widefleet-docs | 128555c | Nov 25 2026, 03:42 PM |
This was referenced Nov 25, 2026
tnkuehne
force-pushed
the
secrets/reencrypt-command
branch
2 times, most recently
from
November 25, 2026 15:06
d5e81e7 to
6f55a63
Compare
`node tools/secret-encryption.ts status|reencrypt` runs inside the control-plane container or from CI with explicit settings. It reads the configured keyring, PLATFORM_ENCRYPTION_KEYS_FILE or an existing encryption.keys, and never creates keys. It covers app secrets, the directory and app sign-in client secrets, SSO provider configurations and leftover pre-plugin identity documents. Rows are read in bounded pages and replaced with a compare-and-swap, by slot, so concurrent writes win and identical ciphertexts in different slots get their own values. Values that already name the active key version are decrypted to verify them. It prints counts per key version, legacy values and failures, and exits nonzero if a value does not decrypt or if re-encryption leaves values under another key version.
A key version named legacy was counted as a legacy value, so re-encryption under it never reported success, and IDs such as constructor or __proto__ read inherited properties. Legacy values are now detected by format, per-version counts use a Map, and values without a readable kid count only as failed.
tnkuehne
force-pushed
the
secrets/reencrypt-command
branch
from
November 25, 2026 15:41
6f55a63 to
128555c
Compare
tnkuehne
added a commit
that referenced
this pull request
Nov 25, 2026
Removes the temporary legacy reader that #384 isolated, now that stored secrets are re-encrypted with the command from #398. ## Changes - **Legacy module deleted.** `legacy-secret-migration.ts` is gone. Stored secrets are now read only as JWE. - **Legacy key chain removed:** - `PLATFORM_ENCRYPTION_KEY` and `PLATFORM_ENCRYPTION_KEY_FILE` - reading an existing `encryption.key` - the `BETTER_AUTH_SECRET` fallback that `createAuthentication` used for encryption - **Configuration.** The legacy key is removed from the Node configuration, the Worker configuration, `deploy-hosted`, Compose and the example environment. - **Command output.** Legacy counting is removed from the re-encryption command. - **Guard migration `0044_require_jwe_secrets`.** Startup refuses to continue while any covered location still holds a value that is not a JWE compact serialization: - app secrets - the directory and app sign-in client secrets - SSO provider OIDC and SAML configurations - a leftover identity document's client secret Its message asks operators to run `node tools/secret-encryption.ts reencrypt` on the previous release first, then upgrade. ## Upgrade path No release contains #384 and #398 without this PR. An installation with secrets stored by an earlier release has two options: - Re-encrypt on a build of a commit between #398 and this PR: run `node tools/secret-encryption.ts reencrypt` until it exits 0, then upgrade. - Start with a fresh database. ## Testing - `pnpm check` - `tests/jwe-secret-guard.integration.test.ts`: for every checked location, a JWE value passes and a value in the earlier format aborts with the upgrade message. Locations: app secrets, the directory and app sign-in client secrets, a leftover identity document, and the SSO provider OIDC and SAML configurations. - `tests/secret-reencryption.integration.test.ts`, `tests/secret-encryption.test.ts`, `tests/installation-keys.test.ts` and `tests/cloudflare/initialization.test.ts`, without legacy cases. ## Stack 1. #383: context API, no behavior change 2. #384: JWE format, JWK Set keyring, temporary legacy reader 3. #398: re-encryption command 4. This PR: legacy cleanup Operator documentation (draft): #385 <!-- greptile_comment --> <!-- greptile_summary --> <h2><a href="https://app.greptile.com/api/retrigger?id=119521333&sig=2114cc615d730cbb335d4f7c6986c67edf164cfc2829706297076f2c957fb586"><picture><source media="(prefers-color-scheme: dark)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/RetriggerDark.svg?v=2"><source media="(prefers-color-scheme: light)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"><img alt="Retrigger" src="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2" align="right"></picture></a><a href="https://app.greptile.com/-/switch-tenant?tenant=mendra&next=%2Fwidefleet%2Fwidefleet%2Fpull%2F399&utm_source=greptile_review&utm_medium=github&utm_campaign=view_in_greptile"><picture><source media="(prefers-color-scheme: dark)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptileDark.svg?v=2"><source media="(prefers-color-scheme: light)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"><img alt="View in Greptile" src="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2" align="right"></picture></a>Confidence Score: 5/5 <sup><img alt="Tier: plus" title="Review tier: plus" src="https://greptile-static-assets.s3.amazonaws.com/badges/effort-plus.svg?v=3" height="12"></sup></h2> <!-- greptile-impact-verdict --> The PR appears safe to merge after the stated release and re-encryption prerequisites are met. <details open><summary><h3>Summary</h3></summary> Stored secrets now use JWE only. The PR removes the old reader and key settings, then adds `0044_require_jwe_secrets` to stop upgrades while older values remain. - Upgrades stop when covered secrets are not JWE. - The control plane reads saved secrets only with its JWK keyring. - The re-encryption status counts only JWE key versions. </details> <details open><summary><h3>Diagram</h3></summary> ```mermaid %%{init: {'theme': 'neutral'}}%% flowchart TD A["Previous release"] --> B["Run re-encryption until it succeeds"] B --> C["Upgrade"] C --> D["0044 checks stored secrets"] D -->|Older format remains| E["Stop with upgrade instructions"] D -->|All values pass| F["Start with JWE-only reads"] ``` </details> <!-- greptile_confidence_score:5 --> <sub>Reviews (3) · Last reviewed commit: ["Test the JWE guard for every stored secr..."](4389d27) · [Reviewed by Greptile](https://www.greptile.com/?utm_source=greptile_review&utm_medium=github&utm_campaign=review_public&utm_content=widefleet/widefleet)</sub> <!-- /greptile_comment -->
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.
Operators need a way to move every stored secret to the active key version before an earlier key, or the legacy format, can be removed. This adds one Node command for that, following
tools/recover.ts. It replaces the closed #386, without UI, API endpoints, a Rust CLI command, a cursor protocol or pending-deployment counting.Based on #384. Review only the commits after #384.
Usage
The command reads only
DATABASE_URL,PLATFORM_STATE_DIRECTORY, the keyring settings and the legacy key settings.It never generates keys. It requires
PLATFORM_ENCRYPTION_KEYS,PLATFORM_ENCRYPTION_KEYS_FILEor an existingencryption.keys, and fails otherwise.installationKeyskeeps generating the keyring on first start; the command uses a new non-generatingreadInstallationKeyring.Behavior
Locations covered:
apps.secretsorganization_settings.directory_secretandapp_client_secretsso_provider.oidc_configandsaml_configorganization_settings.settings.identityHow it works:
changed.kidare decrypted, not skipped by their header.kidcount only as failed.reencryptalso reportsreencryptedandchanged.reencryptleaves values under another key version or in the legacy format.Testing
pnpm checktests/secret-reencryption.integration.test.ts:kidis counted as failed and left unchangedlegacy,constructoror__proto__are counted under their own ID, not as legacy values or inherited propertiesreencryptexits 0statusexits 1 while a value names an unknownkidStack
GitHub stack: #400. Operator documentation (draft): #385


Confidence Score: 5/5 
The PR appears safe to merge; no blocking issues remain.Summary
Adds an operator command to inspect stored secrets and re-encrypt them with the active key.
Both earlier key-counting findings are fixed: legacy values are identified by format, and per-key counts use a
Map. No new actionable issues were found. Tests were inspected, not run.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A["status or reencrypt"] --> B["Read existing keyring and legacy key"] B --> C{"Keyring found?"} C -->|No| D["Exit without creating keys"] C -->|Yes| E{"reencrypt?"} E -->|Yes| F["Read pages and decrypt each value"] F --> G["Replace old ciphertext only if unchanged"] G --> H["Scan again and count values"] E -->|No| H H --> I["Print JSON and set exit status"]Reviews (6) · Last reviewed commit: "Count key versions without colliding wit..." · Reviewed by Greptile