Repository navigation
Derive one runtime key per purpose - #429
Merged
Merged
Conversation
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
widefleet-docs | e6eae1d | Nov 27 2026, 08:31 AM |
tnkuehne
force-pushed
the
feat/runtime-purpose-keys
branch
from
November 26, 2026 16:57
3b4c4d1 to
a51abe2
Compare
tnkuehne
force-pushed
the
feat/runtime-purpose-keys
branch
3 times, most recently
from
November 26, 2026 17:15
5ef5be1 to
63dbabe
Compare
This was referenced Nov 26, 2026
tnkuehne
force-pushed
the
feat/runtime-purpose-keys
branch
from
November 26, 2026 20:35
63dbabe to
e99bf55
Compare
tnkuehne
force-pushed
the
feat/runtime-purpose-keys
branch
from
November 26, 2026 20:43
e99bf55 to
e4bc8f7
Compare
tnkuehne
force-pushed
the
feat/runtime-purpose-keys
branch
6 times, most recently
from
November 27, 2026 01:41
b77abfd to
c88d32c
Compare
Every runtime keyring version used its 32 bytes directly for app secret snapshots, app keys, the workload signing ring and managed OAuth values. Each version now derives a key per purpose with HKDF-SHA256, and `kid` names version and purpose as `<version>:<purpose>`, so a weakness in one use does not reach the others.
tnkuehne
force-pushed
the
feat/runtime-purpose-keys
branch
from
November 27, 2026 08:30
c88d32c to
e6eae1d
Compare
tnkuehne
added a commit
that referenced
this pull request
Nov 27, 2026
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 `SecretContext` callers pass was not bound to the ciphertext, so a value copied to another row, app, organization or kind still decrypted. ## Changes - **Keys per kind (`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 label `widefleet control-plane <kind> v1`. - **One sealing format.** The runtime already seals this way with its own root keys and labels (`widefleet runtime <purpose> v1`), so the format moves to `createSealing` in `@platform/contracts/keyring`. Both sides pass their namespace and keep only their earlier-format reader; the runtime's ciphertexts do not change. - **Key IDs.** `kid` is `<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. - **Context binding.** The protected header carries the canonical context as `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 (`oidcConfig` or `samlConfig`), because Better Auth's field transforms receive no provider identity. - **Re-encryption.** A value counts as current only under the active version's key for its kind. `status` reports `earlierFormat`, the values still in the earlier format, and is incomplete while any remain. - **Earlier values.** Ciphertexts whose `kid` names only a version decrypt with the version's bytes and no context check until `reencrypt` moves them. A later PR removes this path and `earlierFormat`. ## Upgrade After deploying, run `node tools/secret-encryption.ts reencrypt` and check that `status` reports `earlierFormat: 0`. ## Testing - `pnpm check` - `packages/app-runtime`: `secrets.test.ts`, `rekey.test.ts`, `keys.test.ts`, `oauth.test.ts`, `workload-keys.test.ts` against the shared format; `app-services-runtime.test.ts` on workerd - `secret-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 format - `secret-reencryption.integration.test.ts`: fixtures in the earlier format are counted, moved and read with their contexts - `installation-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.ts` - `cloudflare/initialization.test.ts`, `cloudflare/deployment.test.ts -t secrets`
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 #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
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 labelwidefleet runtime <purpose> v1. The purposes are a closed list:app-secrets,app-keys,workload-keys,oauth-access,oauth-refreshandoauth-state.kidis<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.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 checkpackages/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.tsapps/control-plane:app-services-runtime.test.tson workerd,managed-oauth-runtime.test.ts,cloudflare/runtime.test.ts -t secrets

Confidence Score: 5/5 
The PR appears safe to merge; no blocking issue remains.Summary
Derives a separate encryption key for each runtime purpose and includes that purpose in
kid.Diagram
%%{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 --> OpenReviews (8) · Last reviewed commit: "Drop an import the removed refresh test ..." · Reviewed by Greptile