Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
dd6ad4d
feat(dr): production-side exporter, StorageRunner import, dr-restore …
cursoragent Jul 23, 2026
00c05ab
feat(dr): control-plane Access-gated UI, sealing, drill, graduated pr…
cursoragent Jul 23, 2026
50f736b
docs(dr): solo-operator runbook rewrite, trust registries, real DR id…
cursoragent Jul 23, 2026
664fbc6
test(dr): pin reviewed restore identities in trust registry guardrail
cursoragent Jul 23, 2026
e439087
docs(dr): extend backup-control-plane primitive roots for exporter an…
cursoragent Jul 23, 2026
c5c9c97
feat(dr): pin live manifest verifying key and registry entries
cursoragent Jul 23, 2026
c3e1c31
fix(dr): render absent verification states as muted dashes on dashboard
cursoragent Jul 23, 2026
75bb891
fix(dr): harden restore, sealing, auth, and exporter per independent …
cursoragent Jul 23, 2026
cfd2d16
test(dr): silence expected error logs under repo console-spy harness
cursoragent Jul 23, 2026
972963f
style: format primitives.yaml
cursoragent Jul 23, 2026
87cb09c
fix(dr): match live D1 export polling semantics (fast completion, exp…
cursoragent Jul 23, 2026
26309ab
fix(dr): use crypto.DigestStream (Workers runtime) and surface stream…
cursoragent Jul 23, 2026
1c0d565
Merge main; fix preview.yml formatting from #903
cursoragent Jul 23, 2026
1065d07
fix(dr): verify every sealed blob, strict D1 import completion, align…
cursoragent Jul 23, 2026
5fd03b4
fix(dr): CodeRabbit review — JWKS timeout, dump checksum verify, resu…
cursoragent Jul 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/dr-escrow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: DR secret escrow

on:
workflow_dispatch:

jobs:
seal-escrow:
name: Seal SECRET_STORE_KEY into DR backup bucket
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
with:
persist-credentials: false

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 26
cache: npm

- name: Install dependencies
run: npm ci

- name: Seal and upload escrow blob
env:
ESCROW_SECRET_VALUE: ${{ secrets.SECRET_STORE_KEY }}
ESCROW_PASSPHRASE: ${{ secrets.SECRET_ESCROW_PASSPHRASE }}
ESCROW_LABEL: secret-store-key
DR_BACKUP_ACCOUNT_ID: ${{ secrets.DR_BACKUP_ACCOUNT_ID }}
DR_BACKUP_BUCKET_NAME: ${{ secrets.DR_BACKUP_BUCKET_NAME }}
DR_BACKUP_ACCESS_KEY_ID: ${{ secrets.DR_BACKUP_ACCESS_KEY_ID }}
DR_BACKUP_SECRET_ACCESS_KEY:
${{ secrets.DR_BACKUP_SECRET_ACCESS_KEY }}
run: node tools/disaster-recovery/seal-escrow.ts
6 changes: 3 additions & 3 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ jobs:
if: >-
github.event_name == 'pull_request' &&
steps.deploy_preview.outputs.url != ''
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
PREVIEW_URL: ${{ steps.deploy_preview.outputs.url }}
PREVIEW_VERSION_URL:
Expand Down Expand Up @@ -538,7 +538,7 @@ jobs:

- name: 🗑️ Delete GitHub preview deployments
if: always()
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
EVENT_NAME: ${{ github.event_name }}
PR_NUMBER: ${{ github.event.pull_request.number || '' }}
Expand Down Expand Up @@ -615,7 +615,7 @@ jobs:

- name: 🏷️ Delete GitHub preview environment
if: always()
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
EVENT_NAME: ${{ github.event_name }}
PR_NUMBER: ${{ github.event.pull_request.number || '' }}
Expand Down
7 changes: 5 additions & 2 deletions docs/contributing/architecture/primitives.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,13 @@ primitives:
group: storage
name: Production backup control plane
summary:
Dedicated scheduled D1 export, immutable R2 retention, isolated restore
drills, and cross-store recovery readiness contracts.
Dedicated scheduled D1 export, production-side multi-store exporter,
immutable R2 retention, Access-gated operator UI, isolated restore drills,
and cross-store recovery contracts.
code:
- packages/backup-control-plane/
- packages/worker/src/dr/
- packages/shared/src/backup-
- tools/ci/backup-
- tools/disaster-recovery/
docs:
Expand Down
1,523 changes: 328 additions & 1,195 deletions docs/contributing/disaster-recovery.md

Large diffs are not rendered by default.

60 changes: 52 additions & 8 deletions docs/contributing/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,58 @@ Optional Worker secrets/vars (see `packages/worker/src/env-schema.ts` and
as `session_repo_namespace` so follow-up lookups resolve the correct namespace
even after env changes.

## Backup manifest signing

The separately deployed backup Worker uses non-secret
`BACKUP_MANIFEST_SIGNING_KEY_ID`, `TRUSTED_RESTORE_BASELINE_ID`, and
`TRUSTED_RESTORE_BASELINE_SHA256` vars. Its
`BACKUP_MANIFEST_SIGNING_PRIVATE_KEY_PKCS8_BASE64` value is a secret containing
only base64-encoded Ed25519 PKCS#8 private-key bytes. Configure it with Wrangler
secret storage, never in a `.env`, checked config, log, or evidence artifact.
## Disaster recovery (production Worker)

Optional production-only vars/secrets for the nightly non-D1 staging exporter
and chunked restore endpoint (`packages/worker/src/dr/`). All are inert until
`DR_EXPORT_ENABLED` is the literal string `"true"` and S3 credentials are set.
See [Disaster recovery](./disaster-recovery.md).

- `DR_EXPORT_ENABLED` — Worker var; enable staging only when `"true"`.
- `DR_BACKUP_ACCOUNT_ID` / `DR_BACKUP_BUCKET_NAME` — DR account id and backup
bucket name (S3 API endpoint host uses the account id).
- `DR_BACKUP_ACCESS_KEY_ID` / `DR_BACKUP_SECRET_ACCESS_KEY` — Worker secrets; R2
S3 credentials that can write `staging/` and `blobs/` in the DR bucket.
- `DR_RESTORE_SECRET` — Worker secret; bearer token for
`POST /__maintenance/dr-restore`. Must match the control-plane secret of the
same name. Fail-closed when unset.

## Backup control plane (DR account Worker)

Deployed separately under `packages/backup-control-plane/` (not app CI). Enable
gates and source identity vars live in that package's `wrangler.jsonc`.

Non-secret vars:

- `ENABLE_PRODUCTION_D1_BACKUPS` / `BACKUP_BENCHMARK_APPROVED` — both must be
exactly `"true"` or schedules stay inert.
- `SOURCE_ACCOUNT_ID` / `SOURCE_DATABASE_ID` / `SOURCE_DATABASE_NAME` plus
`ALLOWED_SOURCE_ACCOUNT_IDS` / `ALLOWED_SOURCE_DATABASE_IDS`.
- `BACKUP_MANIFEST_SIGNING_KEY_ID`,
`BACKUP_MANIFEST_VERIFYING_PUBLIC_KEY_SPKI_BASE64`,
`TRUSTED_RESTORE_BASELINE_ID`, `TRUSTED_RESTORE_BASELINE_SHA256`.
- `BACKUP_MAX_AGE_HOURS` (default 26), `BACKUP_MAX_SOURCE_BYTES` (≤ 4.5e9).
- `ACCESS_TEAM_DOMAIN`, `ACCESS_APP_AUD`, `ACCESS_ALLOWED_EMAIL` — Zero Trust
Access JWT verification (policy pinned to the solo operator email).
- `DRILL_ACCOUNT_ID` — isolated account for UI restore drills (must differ from
source).
- `PRIMARY_WORKER_ORIGIN` — production Worker origin for
`/__maintenance/dr-restore`.

Secrets (Wrangler secret storage only — never `.env`, config, logs, or
evidence):

- `CLOUDFLARE_API_TOKEN` — production-account Account D1 Edit (export +
production import).
- `BACKUP_MANIFEST_SIGNING_PRIVATE_KEY_PKCS8_BASE64` — base64 Ed25519 PKCS#8.
- `DRILL_API_TOKEN` — drill-account D1 Edit for isolated UI drills.
- `RESTORE_CONFIRM_SECRET` — HMAC secret for the 10-minute prepare→execute
production-restore token.
- `DR_RESTORE_SECRET` — bearer shared with the production Worker.

GitHub Actions `workflow_dispatch` escrow (`.github/workflows/dr-escrow.yml`)
also needs `SECRET_STORE_KEY`, `SECRET_ESCROW_PASSPHRASE`, and the DR S3
credentials (`DR_BACKUP_*`) as repository secrets.

## Why Zod?

Expand Down
11 changes: 11 additions & 0 deletions docs/contributing/secret-rotation.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ Cookie signing and saved-secret encryption use separate Worker secrets:
Rotating `SECRET_STORE_KEY` requires a re-encryption migration because AES-GCM
has no built-in key versioning.

### Escrow

The live key must remain recoverable outside GitHub Actions and the deployed
Worker. Solo escrow seals the key under an operator passphrase
(`SECRET_ESCROW_PASSPHRASE` in the password manager and as a GitHub secret) via
`.github/workflows/dr-escrow.yml`, which uploads
`escrow/secret-store-key.v1.json` to the DR backup bucket. After any rotation,
re-run that workflow so the sealed blob matches the deployed key, then
smoke-test unsealing offline. See [Disaster recovery](./disaster-recovery.md).

### Procedure

1. **Keep the old key available** in a secure migration script so you can
Expand All @@ -38,6 +48,7 @@ has no built-in key versioning.
future `/__maintenance/reencrypt-secrets` endpoint.
3. **Deploy** the new `SECRET_STORE_KEY` only after the re-encryption pass is
complete and verified.
4. **Re-seal escrow** with `dr-escrow.yml` for the new key value.

### Important notes

Expand Down
8 changes: 8 additions & 0 deletions docs/contributing/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,21 @@ guarded by a bearer secret comparison.

- Saved secrets are encrypted at rest with AES-GCM under `SECRET_STORE_KEY` and
scoped by `userId` (`packages/worker/src/mcp/secrets/`).
- `SECRET_STORE_KEY` is escrowed for disaster recovery as a passphrase-sealed
blob in the DR backup bucket (solo operator; see
[Disaster recovery](./disaster-recovery.md) and
[Secret rotation](./secret-rotation.md)). The plaintext key must not appear in
backup SQL, manifests, or repository files.
- Outbound secret use goes through the fetch gateway
(`packages/worker/src/mcp/fetch-gateway.ts`), which is deny-by-default: a
secret placeholder is only substituted for a host the user explicitly approved
in the account UI. Policy writes (allowed hosts/capabilities/packages) are
only reachable through the authenticated account UI.
- User code runs in a Cloudflare Worker Loader isolate without the parent `env`;
capabilities are RPC'd back to handlers that enforce the caller's `userId`.
- The DR control-plane Admin UI is protected by Cloudflare Access plus in-worker
`Cf-Access-Jwt-Assertion` verification; production restore is a graduated
prepare → typed confirmation → Workflow path, never a single click.

## Accepted residual risks and out-of-scope items

Expand Down
70 changes: 45 additions & 25 deletions docs/contributing/setup-manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,22 @@ resources from bindings alone, so the deploy workflow runs

### Disaster-recovery control plane

Production backups use a separate deployment and are not provisioned or deployed
by the application workflow above. The dedicated Worker and Workflow live under
`packages/backup-control-plane/` in an independently administered DR Cloudflare
account. Its `BACKUP_BUCKET` R2 binding is private and uses immutable `daily/`
and `weekly/` prefixes.
Production backups are **not** provisioned or deployed by the application
workflow above. The control-plane Worker/Workflows live under
`packages/backup-control-plane/` in the independently administered DR Cloudflare
account and are deployed via the Cloudflare API / Wrangler authenticated to that
account. Its `BACKUP_BUCKET` R2 binding is private. Immutable prefixes include
`daily/`, `weekly/`, `daily/full/`, and content-addressed `blobs/sha256/`.

The retention administrator uses a separate provisioner token to create the
bucket and apply 35-day daily and 400-day weekly lock/lifecycle rules:
The production Worker also stages non-D1 canonical stores into the same bucket
when `DR_EXPORT_ENABLED=true` (StorageRunner dumps, `EMAIL_BLOBS` /
`COMMUNITY_ASSETS` blobs, published `BUNDLE_ARTIFACTS_KV` source snapshots). The
control plane seals complete days and hosts the Access-protected Admin UI for
drills and graduated production restore. See
[Disaster recovery](./disaster-recovery.md).

Use a separate provisioner token (never a Worker secret) to create the bucket
and apply 35-day daily and 400-day weekly lock/lifecycle rules:

```sh
node tools/ci/backup-resources-cli.ts plan \
Expand All @@ -97,24 +105,23 @@ node tools/ci/backup-resources-cli.ts plan \
```

`apply` is an explicit mutation and must be run only after reviewing the plan.
The runtime receives a source-account token with Cloudflare Account D1 Edit as
the `CLOUDFLARE_API_TOKEN` Worker secret. Cloudflare grants this permission
account-wide and it can mutate D1; the runtime's application UUID/name allowlist
reduces operator mistakes but does not technically scope the token to one
database or make it read-only. Keep this source runtime token separate from the
destination R2 provisioning/lock-administration token and drill restore
credentials. The runtime must not receive either of those credentials or R2
bucket, lock, lifecycle, or public-access administration permissions. Scheduling
remains inert until the blocking-export benchmark is approved and both enable
variables are exactly `true`. See [Disaster recovery](./disaster-recovery.md)
for deployment, readiness, drill, credential, and exclusion details.
The control-plane runtime receives a source-account token with Cloudflare
Account D1 Edit as `CLOUDFLARE_API_TOKEN` (export + production D1 import).
Cloudflare grants this permission account-wide and it can mutate D1; the
runtime's UUID/name allowlist reduces mistakes but does not scope the token.
Keep that token separate from the provisioner token, drill token
(`DRILL_API_TOKEN`), and production→DR S3 credentials on the app Worker.
Scheduling remains inert until the blocking-export benchmark is approved and
both `ENABLE_PRODUCTION_D1_BACKUPS` and `BACKUP_BENCHMARK_APPROVED` are exactly
`"true"`.

The backup deployment also requires reviewed non-secret
`BACKUP_MANIFEST_SIGNING_KEY_ID`, `TRUSTED_RESTORE_BASELINE_ID`, and
`TRUSTED_RESTORE_BASELINE_SHA256` vars. Store the matching base64-encoded
Ed25519 PKCS#8 private key only as the
`BACKUP_MANIFEST_SIGNING_PRIVATE_KEY_PKCS8_BASE64` Worker secret. Never commit
that private key. Restore trusts only the checked-in manifest public-key,
Reviewed non-secret control-plane vars include manifest signing key id /
verifying public key, trusted restore baseline id/digest, Access
(`ACCESS_TEAM_DOMAIN`, `ACCESS_APP_AUD`, `ACCESS_ALLOWED_EMAIL`),
`DRILL_ACCOUNT_ID`, and `PRIMARY_WORKER_ORIGIN`. Worker secrets include
`BACKUP_MANIFEST_SIGNING_PRIVATE_KEY_PKCS8_BASE64`, `DRILL_API_TOKEN`,
`RESTORE_CONFIRM_SECRET`, and `DR_RESTORE_SECRET`. Never commit private keys.
Offline CLI restore still trusts only the checked-in manifest public-key,
production-identity, and restore-baseline registries.

## Optional Cloudflare offerings
Expand Down Expand Up @@ -209,7 +216,10 @@ Configure these GitHub Actions secrets and variables for workflows:
owns the user email sending domain; Email Sending event subscriptions require
both this zone id and the domain)
- `COOKIE_SECRET` (same format as local)
- `SECRET_STORE_KEY` (same format as local; required for deploys)
- `SECRET_STORE_KEY` (same format as local; required for deploys; also sealed
into the DR bucket via `.github/workflows/dr-escrow.yml` using
`SECRET_ESCROW_PASSPHRASE` plus `DR_BACKUP_*` S3 credentials — see
[Disaster recovery](./disaster-recovery.md))
- `APP_BASE_URL` (required GitHub Actions **variable** used by the deployed
Worker as the fallback public app origin when no request URL is available —
workflows, password-reset email sender hostname — and written into the
Expand All @@ -224,6 +234,16 @@ Configure these GitHub Actions secrets and variables for workflows:
- `CAPABILITY_REINDEX_SECRET` (required in production; optional locally and for
previews; authenticates post-deploy maintenance calls such as capability
reindex)
- `DR_BACKUP_ACCOUNT_ID` / `DR_BACKUP_BUCKET_NAME` / `DR_BACKUP_ACCESS_KEY_ID` /
`DR_BACKUP_SECRET_ACCESS_KEY` (production DR staging into the DR bucket; also
used by `.github/workflows/dr-escrow.yml`. Pair with Worker var
`DR_EXPORT_ENABLED=true` only after enablement — see
[Disaster recovery](./disaster-recovery.md))
- `DR_RESTORE_SECRET` (shared bearer for control-plane →
`POST /__maintenance/dr-restore`)
- `SECRET_ESCROW_PASSPHRASE` (operator passphrase for sealing `SECRET_STORE_KEY`
into `escrow/secret-store-key.v1.json`; keep the same value in the personal
password manager)
- `OAUTH_GITHUB_CLIENT_ID` / `OAUTH_GITHUB_CLIENT_SECRET`,
`OAUTH_GOOGLE_CLIENT_ID` / `OAUTH_GOOGLE_CLIENT_SECRET`, `OAUTH_X_CLIENT_ID` /
`OAUTH_X_CLIENT_SECRET` (optional; social login provider app credentials. The
Expand Down
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading