Repository navigation
Remove the legacy secret format - #399
Merged
Merged
Conversation
tnkuehne
force-pushed
the
secrets/legacy-cleanup
branch
from
November 25, 2026 14:56
395e724 to
c492f42
Compare
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
widefleet-docs | 4389d27 | Nov 25 2026, 04:11 PM |
tnkuehne
force-pushed
the
secrets/legacy-cleanup
branch
2 times, most recently
from
November 25, 2026 15:41
e9be844 to
3cfe0b3
Compare
Stored secrets are now only JWE. This removes the temporary legacy reader: decrypting bare hexadecimal ciphertexts, the legacy key chain (PLATFORM_ENCRYPTION_KEY, its _FILE variant, encryption.key and the BETTER_AUTH_SECRET fallback), and legacy counting in the re-encryption command. Migration 0044 refuses to start while app secrets, organization client secrets, SSO provider configurations or a leftover identity document still hold a value that is not JWE. Its message asks operators to run the re-encryption command on the previous release first, then upgrade.
Each location now passes with a JWE value and stops the upgrade with a value in the earlier format: app secrets, the directory and app sign-in client secrets, a leftover identity document, and the SSO provider OIDC and SAML configurations.
tnkuehne
added a commit
that referenced
this pull request
Nov 25, 2026
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 ```sh # Self-hosted, inside the control-plane container docker compose ... exec control-plane node tools/secret-encryption.ts status docker compose ... exec control-plane node tools/secret-encryption.ts reencrypt # Hosted, from CI with explicit settings DATABASE_URL=... PLATFORM_ENCRYPTION_KEYS=... PLATFORM_ENCRYPTION_KEY=... \ node apps/control-plane/tools/secret-encryption.ts reencrypt ``` 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_FILE` or an existing `encryption.keys`, and fails otherwise. `installationKeys` keeps generating the keyring on first start; the command uses a new non-generating `readInstallationKeyring`. ## Behavior **Locations covered:** - `apps.secrets` - `organization_settings.directory_secret` and `app_client_secret` - `sso_provider.oidc_config` and `saml_config` - the client secret in a leftover pre-plugin `organization_settings.settings.identity` **How it works:** - **Bounded pages.** Rows are read in pages of 100 in key order. The page cursor follows the raw database rows, so rows without a secret never end a scan early. - **Compare-and-swap per row.** A row is replaced only if it still holds what was read, so a concurrent write wins and is counted as `changed`. - **Replacement by slot.** New ciphertexts are keyed by row and field or secret name, not by ciphertext string, so two slots holding the same ciphertext each get their own value. - **Active values are verified.** Values whose header names the active `kid` are decrypted, not skipped by their header. - **Secret revisions unchanged.** The secret revision is left alone, so nothing is redeployed. - **Output.** JSON with counts per key version, the legacy count and the failed count. Legacy values are recognized by their format, never by a key name, and values without a readable `kid` count only as failed. `reencrypt` also reports `reencrypted` and `changed`. - **Exit status.** Nonzero if a value does not decrypt, or if `reencrypt` leaves values under another key version or in the legacy format. ## Testing - `pnpm check` - `tests/secret-reencryption.integration.test.ts`: - every location moves from the legacy format and an earlier key version to the active one - counts before and after, and a second run changes nothing - readers find every value with matching contexts (context checks from #383 active) - two slots holding the same ciphertext get distinct values - an altered value under the active `kid` is counted as failed and left unchanged - a concurrent write between read and replace is kept - paging past 110 rows without a secret - key versions named `legacy`, `constructor` or `__proto__` are counted under their own ID, not as legacy values or inherited properties - the command itself: - fails without a keyring and creates no file - `reencrypt` exits 0 - `status` exits 1 while a value names an unknown `kid` - the state directory stays empty ## Stack 1. #383: context API, no behavior change 2. #384: JWE format, JWK Set keyring, temporary legacy reader 3. This PR: re-encryption command 4. #399: legacy cleanup (draft) GitHub stack: #400. Operator documentation (draft): #385 <!-- greptile_comment --> <!-- greptile_summary --> <h2><a href="https://app.greptile.com/api/retrigger?id=119521021&sig=fd953f268e72c3f3f0356af21af5928972e43ebac759c5e0d10aa0fc250ddc73"><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%2F398&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; no new actionable issues remain. <details open><summary><h3>Summary</h3></summary> Adds an operator command to inspect stored secrets and re-encrypt them under the active key. - Secret status counts stored values by key version and decrypt failures. - Readable stored secrets move to the active key without changing their values. - Operators can check or re-encrypt secrets with an existing keyring. Source and tests were inspected; tests were not run. </details> <details open><summary><h3>Diagram</h3></summary> ```mermaid %%{init: {'theme': 'neutral'}}%% flowchart TD A[Read existing keys] --> B{Keyring found?} B -->|No| C[Exit unsuccessfully] B -->|Yes| D{Requested action} D -->|status| I[Scan and decrypt every secret] D -->|reencrypt| E[Read next page] E --> F[Decrypt each secret] F --> G[Encrypt values not using active key] G --> H[Replace only unchanged rows] H --> I I --> J[Print counts and set exit status] ``` </details> <!-- greptile_confidence_score:5 --> <sub>Reviews (4) · Last reviewed commit: ["Count key versions without colliding wit..."](128555c) · [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 -->
tnkuehne
force-pushed
the
secrets/legacy-cleanup
branch
from
November 25, 2026 16:08
3cfe0b3 to
4389d27
Compare
tnkuehne
marked this pull request as ready for review
November 25, 2026 20:14
tnkuehne
added a commit
that referenced
this pull request
Nov 25, 2026
Removes the startup conversion of the company SSO configuration that releases before 0.4.0 stored in `organization_settings.settings.identity`. ## Changes - **Conversion removed.** `sso-migration.ts` (`migrateSsoSettings`) is deleted, with its calls in Node startup (`runtime-initialization.ts`) and Hosted initialization (`tools/cloudflare-initialization.ts`). - **Identity document support removed:** - the `legacy-sso-client-secret` secret context - the leftover identity document location in secret re-encryption - **Guard migration `0046_require_converted_sso`.** Startup refuses to continue while any `organization_settings` row still has an `identity` key, including `identity: null`. Its message: > Company SSO settings still use the configuration format of earlier releases. Start the previous release once so it converts the earlier SSO configuration, then upgrade. `0044_require_jwe_secrets` still checks the identity document's client secret and is unchanged. ## Upgrade path The conversion first shipped in **0.4.0** (#68). Every release from 0.4.0 up to this change runs it at startup, for Node and Hosted installations. Installations upgrading from a release before 0.4.0 must first start a release with the conversion (0.4.0 or newer, before this change) once, so it converts the earlier SSO configuration. Then they can upgrade to a release with this change. Their stored secrets also fall under the requirement of `0044_require_jwe_secrets` (#399). Installations already on 0.4.0 or newer have no identity document left and pass the guard. ## Testing - `pnpm check` - `tests/sso-conversion-guard.integration.test.ts` (new): a row with an identity document or `identity: null` aborts with the message; the converted settings pass. - `tests/secret-reencryption.integration.test.ts`: without the identity document cases. The paging case is removed: it exercised the only location that skipped rows without a ciphertext. - `tests/jwe-secret-guard.integration.test.ts`, `tests/settings.integration.test.ts`, `tests/runtime-errors.integration.test.ts`, `tests/email-setup.integration.test.ts` - `RUN_CLOUDFLARE_TESTS=1 vitest run tests/cloudflare/initialization.test.ts` - `tests/e2e/setup.spec.ts` (Playwright): the upgrade scenario that modeled an identity document and called the conversion is removed. The rest of the test passes. <!-- greptile_comment --> <!-- greptile_summary --> <h2><ruby><rp>Confidence Score: 5/5 · The PR appears safe to merge with the stated staged upgrade requirement.</rp></ruby><a href="https://app.greptile.com/api/retrigger?id=120014892&sig=61f14a6ad9b328c14a763df6075dfaa346dacde9c723e8f71e10f30c95755275"><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%2F415&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 with the stated staged upgrade requirement. <details open><summary><h3>Summary</h3></summary> Removes startup conversion of pre-0.4.0 company SSO settings. - Upgrades now stop until old company sign-in settings are converted. </details> <details open><summary><h3>Diagram</h3></summary> ```mermaid %%{init: {'theme': 'neutral'}}%% flowchart TD A["Node startup or Hosted setup"] --> B["Run database migrations"] B --> C{"Settings contain identity?"} C -->|Yes| D["Stop: start the previous release once"] C -->|No| E["Initialize installation"] ``` </details> <!-- greptile_confidence_score:5 --> <sub>Reviews (1) · Last reviewed commit: ["Remove the conversion of the pre-0.4.0 S..."](2ea9a0b) · [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.
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.tsis gone. Stored secrets are now read only as JWE.Legacy key chain removed:
PLATFORM_ENCRYPTION_KEYandPLATFORM_ENCRYPTION_KEY_FILEencryption.keyBETTER_AUTH_SECRETfallback thatcreateAuthenticationused for encryptionConfiguration. 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:Its message asks operators to run
node tools/secret-encryption.ts reencrypton 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:
node tools/secret-encryption.ts reencryptuntil it exits 0, then upgrade.Testing
pnpm checktests/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.tsandtests/cloudflare/initialization.test.ts, without legacy cases.Stack
Operator documentation (draft): #385


Confidence Score: 5/5
The PR appears safe to merge with the stated intermediate-build upgrade requirement.Summary
Removes legacy secret reading and key settings. Stored secrets now use JWE only.
No new actionable issues were found. Tests were inspected, not run.
Reviews (4) · Last reviewed commit: "Test the JWE guard for every stored secr..." · Reviewed by Greptile