Repository navigation
Seal runtime values with a versioned keyring - #428
Merged
Merged
Conversation
tnkuehne
force-pushed
the
feat/runtime-keyring
branch
from
November 26, 2026 16:57
9aa1cc9 to
0764686
Compare
tnkuehne
force-pushed
the
feat/runtime-keyring
branch
from
November 26, 2026 17:09
0d1623e to
f290b90
Compare
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
widefleet-docs | 5dc744f | Nov 27 2026, 08:31 AM |
The runtime encrypted app secret snapshots, app keys, the workload signing ring and managed OAuth values with one raw key, WIDEFLEET_SECRETS_KEY, whose ciphertexts named no key version. The key could not be rotated. The runtime now takes WIDEFLEET_SECRETS_KEYS, a JWK Set in the control plane's keyring format, and seals values as compact JWE with the key version as `kid` and the value's object or purpose as a protected `ctx`. Stored values open under any version; OAuth bearer values open only under the active one. The rekey management endpoint, `POST /runtime/rekey` and `widefleet runtime rekey` seal stored values again under the active version, page by page with conditional writes. Values written before the keyring stay readable until rewritten.
…g alone New values are always sealed under the active version, so one pass without unreadable values or conflicts already leaves every value under it. The earlier secret binding is deleted once by the operator instead of being overwritten with an empty value on every deployment.
tnkuehne
force-pushed
the
feat/runtime-keyring
branch
from
November 26, 2026 20:35
1bb36b2 to
cbb7243
Compare
… rewrite The keyring reads and writes key material with jose's base64url, and the agent draws its key and key ID from getrandom. A rewrite that loses its conditional write counts a conflict instead of reading again; the operator runs the rewrite again.
…nd CLI command Rewriting runtime storage is a rare maintenance task, like re-encrypting the control plane's secrets with tools/secret-encryption.ts. tools/runtime-rekey.ts calls the runtime's private management route page by page: through the RuntimeManagement binding for a Hosted installation, and through the private listener with the control token inside a self-hosted control-plane container. The control-plane route POST /runtime/rekey and widefleet runtime rekey are removed.
The deployer already knows when the runtime with the current keyring is live, so it drives the rewrite instead of an operator script: deploy-hosted after the whole installation is deployed, and the agent after each committed Runtime job, whose message reports the counts. The runtime's status reports its active key version, so deploy-hosted also waits for a keyring change that keeps the release.
… rekey message During a rollout an earlier Worker version can still answer without a key version; the wait now treats it as not yet live instead of failing the deployment. A failed rewrite's message is cut to the job message limit.
The control plane keeps the keyring helpers only it uses, and modules import the shared parser from contracts directly. deploy-hosted reads the runtime's status once and waits until both its release and active key match, retrying a read that an earlier version answers differently. The rewrite lists only the RS256 ring instead of skipping other workload objects. Tests share one keyring fixture per package, one fixture for values from before the keyring, and the real page loop.
tnkuehne
added a commit
that referenced
this pull request
Nov 27, 2026
Stacked on #428. Each runtime keyring version encrypted every kind of value with its own 32 bytes: app secret snapshots, the keys behind `WIDEFLEET_KEYS`, the workload signing ring and the managed OAuth access, refresh and state values. A weakness in how one of them uses the key, for example a nonce reuse, would then reach all of them. ## Changes - **Purpose keys (`secrets.ts`).** Each version derives one AES-256-GCM key per purpose with HKDF-SHA256 (RFC 5869): a fixed 32-byte zero salt and the label `widefleet runtime <purpose> v1`. The purposes are a closed list: `app-secrets`, `app-keys`, `workload-keys`, `oauth-access`, `oauth-refresh` and `oauth-state`. - **Key IDs.** `kid` is `<version>:<purpose>`. Opening accepts only the purpose the caller expects, and never the root key itself. Version IDs cannot contain a colon, so the scheme is unambiguous. - **Callers.** Snapshot preparation and reads, app keys, the workload ring, managed OAuth and the rewrite pass their purpose. The rewrite counts a value as current only under the active version's key for its purpose. - **Docs** are in #431. This PR ships in the same release as #428, so no deployment writes the root-key format of #428 and the rewrite runs once. ## Testing - `pnpm check` - `packages/app-runtime`: `secrets.test.ts` (a value of one purpose does not open for another, also with the purpose renamed in its header; the root key opens nothing), `rekey.test.ts`, `keys.test.ts`, `oauth.test.ts`, `workload-keys.test.ts`, `oauth-metadata-document.test.ts`, `template-oauth.test.ts` - `apps/control-plane`: `app-services-runtime.test.ts` on workerd, `managed-oauth-runtime.test.ts`, `cloudflare/runtime.test.ts -t secrets` <!-- greptile_comment --> <!-- greptile_summary --> <h2><ruby><rp>Confidence Score: 5/5 · The PR appears safe to merge; no blocking issue remains.</rp></ruby><a href="https://app.greptile.com/api/retrigger?id=120995216&sig=fc88eb82f480fd83d61f191706434ff82974403bb58fb65eedcc940c10e842ed"><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%2F429&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 blocking issue remains. <details open><summary><h3>Summary</h3></summary> Derives a separate encryption key for each runtime purpose and includes that purpose in `kid`. - Runtime values use separate encryption keys for each purpose. - The storage rewrite checks each value against its purpose key. </details> <details open><summary><h3>Diagram</h3></summary> ```mermaid %%{init: {'theme': 'neutral'}}%% flowchart LR Root["Runtime key version"] --> HKDF["HKDF-SHA256 with purpose label"] Purpose["Caller supplies purpose"] --> HKDF HKDF --> Key["Purpose-specific AES-GCM key"] Key --> Seal["Encrypt value"] Context["Expected context"] --> Seal Seal --> Value["JWE with version:purpose and context"] Value --> Open["Open with expected purpose and context"] Key --> Open ``` </details> <!-- greptile_confidence_score:5 --> <sub>Reviews (8) · Last reviewed commit: ["Drop an import the removed refresh test ..."](b963da6) · [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
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.
The runtime encrypts what it stores itself (app secret snapshots, the keys behind
WIDEFLEET_KEYS, the workload signing ring) and the managed OAuth values that clients hold. It used one raw key,WIDEFLEET_SECRETS_KEY, in a format that names no key version, so the key could not be rotated: replacing it made every stored value unreadable, including app keys that exist nowhere else.Changes
WIDEFLEET_SECRETS_KEYSis a JWK Set in the control plane's keyring format, active version first. The format helpers move fromsecret-encryption.tsto@platform/contracts/keyring, so both share one parser.dir+A256GCM, with the key version askidand the value's object path or purpose as a protectedctx. Opening requires the context the reader expects, so a value cannot be moved to another object or purpose./.well-known/widefleet/rekeyseals stored values again under the active version, one bounded page per request. It opens every value, also one that already names the active version, and writes only if the object is still the one it read; deleted objects stay deleted and no app key is created. Whatever deploys the runtime drives the pages in one pass once the runtime is live:deploy-hostedat the end of a deployment, after waiting for the runtime to report the keyring's active key version (a keyring change can keep the release), and the agent after each committed Runtime job, whose message reports the counts.deploy-hostedexits nonzero and the job message says so if a value was unreadable or changed during the pass. New values are always sealed under the active version, so a pass without either leaves every value under it. The earlier Ed25519 ring atworkload/signing-keys.jsonis not read and is left as it is.legacy-runtime-ciphertext.tsreads values written before the keyring with the active version's bytes until they are rewritten, including snapshots that still carry a fingerprint, which the rewrite drops. A later PR removes it.deploy-hostedvalidates and deploysWIDEFLEET_SECRETS_KEYS. The agent generates a keyring per organization atorganizations/<id>/app-secrets-keyring.jsoninstead of the earlier hex key.Upgrade
WIDEFLEET_SECRETS_KEYin unpadded base64url, and deploy; the deployment rewrites runtime storage. Deployments keep secrets they do not name, so delete the earlierWIDEFLEET_SECRETS_KEYsecret from the runtime Worker once withwrangler secret delete. Managed OAuth values still in the earlier format when that reader is removed need a new authorization.The next PR in this stack derives one key per purpose from each version. Both ship in one release, so no deployment writes this PR's root-key format.
Testing
pnpm checkpackages/app-runtime:secrets.test.ts(context binding, earlier versions for stored values, active version only for bearer values, values before the keyring),rekey.test.ts(rewrite of every stored kind with unchanged content and app key bytes, unreadable values, concurrent writes, deletions, paging),keys.test.ts(sealed record, same key bytes from a record before the keyring),oauth.test.ts(retired values after rotation; size limits),workload-keys.test.ts,oauth-metadata-document.test.ts,template-oauth.test.tsapps/control-plane:runtime-rekey.test.ts(page loop);cloudflare/runtime.test.tsstatus checks with the key version;app-services-runtime.test.tson workerd, including a stored snapshot from before the keyring rewritten through the management endpoint;managed-oauth-runtime.test.ts;cloudflare/runtime.test.ts -t secrets;cloudflare/deployment.test.ts -t "private secrets"cargo test -p platform-agent --lib runtime::,cargo test -p platform-agent --bin platform-agent rekeydeploy-hostedwas not run against a Hosted installation.