Repository navigation
Bind control-plane secrets to a key per kind and their context - #435
Merged
tnkuehne merged 5 commits intoNov 27, 2026
Merged
Conversation
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
widefleet-docs | 06507d5 | Nov 27 2026, 08:31 AM |
tnkuehne
force-pushed
the
feat/control-plane-purpose-keys
branch
4 times, most recently
from
November 26, 2026 21:14
f2e859e to
6dc8045
Compare
tnkuehne
force-pushed
the
feat/control-plane-purpose-keys
branch
from
November 26, 2026 22:05
6dc8045 to
e4ea4ba
Compare
tnkuehne
force-pushed
the
feat/control-plane-purpose-keys
branch
from
November 26, 2026 22:17
e4ea4ba to
54cc127
Compare
tnkuehne
force-pushed
the
feat/control-plane-purpose-keys
branch
2 times, most recently
from
November 27, 2026 01:41
2b693d3 to
f6fb208
Compare
Every control-plane ciphertext used its key version's bytes directly and did not bind the context its callers already passed, so a value could be moved to another row, organization or kind without failing to decrypt. Each key version now derives one key per kind of value with HKDF-SHA256. The JWE names version and kind as `kid` and carries the canonical context as a protected `ctx`, and decryption requires both to match the caller's context. Values in the earlier format stay readable until `reencrypt` moves them; the status reports how many remain.
Both seal with the same JWE format and per-purpose HKDF keys, so the format now lives once in the contracts keyring module; each side keeps only its earlier-format reader. The test wrapper that compared contexts is gone, since ciphertexts bind their context, and so is the test for a key ID that only a corrupted row could hold.
tnkuehne
force-pushed
the
feat/control-plane-purpose-keys
branch
from
November 27, 2026 08:30
f6fb208 to
06507d5
Compare
tnkuehne
added a commit
that referenced
this pull request
Nov 27, 2026
Values stored before the runtime keyring (#428) and before the control plane's keys per kind (#435) stayed readable through temporary readers until they were rewritten. This removes those readers. ## Changes - **Runtime.** `legacy-runtime-ciphertext.ts` goes: values sealed with the raw key and app keys wrapped with AES-KW no longer open. Stored values and app keys accept only the keyring format, so the rewrite no longer special-cases app key records. - **Control plane.** The reader for JWEs whose `kid` names only a key version goes, together with `earlierFormat` in `secret-encryption status`. A value still in that format counts as `failed`. - **Tests.** The fixtures and cases for the earlier formats go. The workerd test of the rewrite route now moves a value from a read-only key version to the active one. Rejection and missing-key cases use values in the current format, so each fails only for the property it tests. ## Upgrade Rewrite both stores on the previous release before upgrading: - A runtime deployment reports `0 rewritten, 0 unreadable, 0 conflicts`. - `node tools/secret-encryption.ts status` reports `earlierFormat: 0` and `failed: 0`. Managed OAuth values that clients still hold from before the runtime keyring are no longer accepted; those connections need a new authorization. ## Testing - `svelte-check` (control plane), `tsc` (app runtime), `oxlint`, `oxfmt` - `packages/app-runtime`: `secrets.test.ts`, `keys.test.ts`, `rekey.test.ts`, `oauth.test.ts`, `workload-keys.test.ts` - `apps/control-plane`: `secret-encryption.test.ts`, `secret-reencryption.integration.test.ts`, `runtime-rekey.test.ts`, `app-services-runtime.test.ts` with `RUN_SERVICE_TESTS=1` (workerd and celld), `cloudflare/deployment.test.ts -t "removes an undeployed app"` with `RUN_CLOUDFLARE_TESTS=1`
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.
Stacked on #429. Every control-plane ciphertext (app secrets, the directory and app sign-in client secrets, SSO provider configurations) used its key version's 32 bytes directly. The
SecretContextcallers pass was not bound to the ciphertext, so a value copied to another row, app, organization or kind still decrypted.Changes
secret-encryption.ts). Each version derives one AES-256-GCM key per kind of value with HKDF-SHA256 (RFC 5869): a fixed 32-byte zero salt and the labelwidefleet control-plane <kind> v1.widefleet runtime <purpose> v1), so the format moves tocreateSealingin@platform/contracts/keyring. Both sides pass their namespace and keep only their earlier-format reader; the runtime's ciphertexts do not change.kidis<version>:<kind>. Decryption accepts only the kind of the caller's context. Version IDs could not contain a colon before, so the scheme is unambiguous.ctx: the kind and its fields in a fixed order, for example["app-secret", organizationId, appId, name]. Decryption requires an exact match. SSO configurations bind only their field (oidcConfigorsamlConfig), because Better Auth's field transforms receive no provider identity.statusreportsearlierFormat, the values still in the earlier format, and is incomplete while any remain.kidnames only a version decrypt with the version's bytes and no context check untilreencryptmoves them. A later PR removes this path andearlierFormat.Upgrade
After deploying, run
node tools/secret-encryption.ts reencryptand check thatstatusreportsearlierFormat: 0.Testing
pnpm checkpackages/app-runtime:secrets.test.ts,rekey.test.ts,keys.test.ts,oauth.test.ts,workload-keys.test.tsagainst the shared format;app-services-runtime.test.tson workerdsecret-encryption.test.ts: header and key per kind, checked with node:crypto alone (HKDF and AES-GCM); a recorded value in the new format; rejection for another app secret name, app, organization or kind; a recorded value in the earlier formatsecret-reencryption.integration.test.ts: fixtures in the earlier format are counted, moved and read with their contextsinstallation-keys.test.ts,secret-contexts.integration.test.ts,jwe-secret-guard.integration.test.ts,organization-settings.integration.test.ts,organization-storage.integration.test.ts,app-services.integration.test.ts,company-sso-plugin.integration.test.ts,required-secrets.integration.test.ts,template-installs.integration.test.ts,settings.integration.test.ts,cloudflare-operations.integration.test.tscloudflare/initialization.test.ts,cloudflare/deployment.test.ts -t secrets