Skip to content

Give apps keys they can use but not read - #237

Merged
tnkuehne merged 3 commits into
mainfrom
feat/app-keys
Nov 20, 2026
Merged

tnkuehne merged 3 commits into
mainfrom
feat/app-keys

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

What changes

Every app gets a WIDEFLEET_KEYS binding:

const sealed = await env.WIDEFLEET_KEYS.encrypt("tokens", accessToken);
const plaintext = await env.WIDEFLEET_KEYS.decrypt("tokens", sealed); // Uint8Array
const signature = await env.WIDEFLEET_KEYS.sign("cookies", value);
const valid = await env.WIDEFLEET_KEYS.verify("cookies", value, signature);
  • Keys are addressed by name ([a-z0-9][a-z0-9-]{0,62}) and created on first use.
  • Each key is 32 random bytes, stored only wrapped with AES-KW at app-keys/{appId}/{name}.json in runtime storage. The wrapping key is derived with HKDF from the installation key and the app ID, so a wrapped key copied to another app fails AES-KW's integrity check.
  • AES-GCM and HMAC-SHA256 keys are derived per purpose. Ciphertext and signatures are bound to the app, the key name and optional additional data.
  • Concurrent first uses agree on one key through a conditional write.
  • App code never receives key material. A later change to the installation key only needs the stored keys re-wrapped; encrypted app data stays readable.
  • Removing an app deletes its keys on Cloudflare and on self-hosted runtimes.

Why

Apps such as the connector templates need a stable key to sign cookies and encrypt stored account tokens. Today an administrator generates AUTH_SECRET by hand and the app holds it in code. This binding is the base for removing it.

Tests

  • packages/app-runtime/src/keys.test.ts: round trips, binding to app, name and additional data, copied wrapped keys, racing first use across isolates, another installation key, signatures, invalid names.
  • apps/control-plane/tests/app-services-runtime.test.ts (workerd and celld): an app uses its keys, another app cannot decrypt them, storage holds only wrapped keys.
  • apps/control-plane/tests/cloudflare/deployment.test.ts: app removal deletes stored keys.

Documentation follows in a separate draft PR.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge with no new actionable issues.

Summary

Adds WIDEFLEET_KEYS so apps can encrypt, decrypt, sign, and verify without receiving key material.

  • Every app can encrypt data and sign values without handling key material.
  • App removal deletes the app's stored keys.

tnkuehne accepted the remaining removal race because app IDs are never reused and leftover keys cannot be read by another app. No new actionable issues were found. Tests were inspected, not run.

Diagram

sequenceDiagram
  participant App
  participant Binding as WIDEFLEET_KEYS
  participant Store as Runtime storage
  App->>Binding: Encrypt or sign with a key name
  Binding->>Store: Read wrapped key
  opt Key does not exist
    Binding->>Store: Check app is published
    Binding->>Store: Conditionally store wrapped random key
    Binding->>Store: Read winning wrapped key
  end
  Binding->>Binding: Unwrap and derive purpose keys
  Binding-->>App: Ciphertext or signature
Loading

Reviews (5) · Last reviewed commit: "Bound derived app keys and refuse keys f..." · Reviewed by Greptile

Comment thread packages/app-runtime/src/worker.ts Resolved
Comment thread packages/app-runtime/src/keys.ts Resolved
Comment thread packages/app-runtime/src/keys.ts Resolved
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs 1420cb9 Nov 20 2026, 01:54 PM

Apps get a WIDEFLEET_KEYS binding to encrypt, decrypt, sign and verify with
named keys. Each key is random, stored only wrapped with AES-KW under a key
derived from the installation key and the app ID, and never reaches app code.
Removing an app deletes its keys.
@tnkuehne
tnkuehne merged commit e72ac9f into main Nov 20, 2026
17 checks passed
@tnkuehne
tnkuehne deleted the feat/app-keys branch November 20, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant