From cec442da991c5da56adcb2839fa19013eecabdff Mon Sep 17 00:00:00 2001 From: Nathan Rover Date: Thu, 30 Jul 2026 12:18:18 -0400 Subject: [PATCH 1/2] Deploy the worker from CI alongside the Pages site MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Until now only the Pages site deployed on push to main — the worker was manual-only, so merged worker changes silently never reached production (bit us on PR #46). Worker deploys before Pages so a fresh site never races ahead of the API it calls; the existing D1 migration baseline check still gates both. Co-Authored-By: Claude Fable 5 --- .github/workflows/deploy.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ddda77d..c196993 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -27,9 +27,9 @@ jobs: cache: npm - run: npm ci - run: npm run check - # Keep production Pages deploys on the Node suite. The Workers/D1 pool + # Keep production deploys on the Node suite. The Workers/D1 pool # suite stays in CI via `npm test` so workerd/pool flakes cannot block - # an otherwise unrelated site deploy. + # an otherwise unrelated deploy. - run: npm run test:node - run: npm run build # Migration 0001 is already applied remotely. Keep deployment fail-closed @@ -40,6 +40,15 @@ jobs: test "$(find worker/migrations -maxdepth 1 -type f -name '*.sql' | wc -l)" -eq 1 echo "3f820cb7c1f8e76196e83f8bc8448dd9e72e840884fc39641c84e6b9d60ff27f worker/migrations/0001_pegma_storage.sql" | sha256sum --check --strict + # Worker before Pages: the site is a client of the worker's API, so a + # freshly deployed site must never race ahead of the API it calls. + # Secrets persist across deploys; plain vars come from wrangler.jsonc + # (a dashboard-added var would be replaced here — use secrets). + - name: Deploy Worker + env: + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + run: npx wrangler deploy -c worker/wrangler.jsonc - name: Deploy to Cloudflare Pages env: CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} From 4fba44b44a5fe6dcfd1bfb1e9ea18520be082fb0 Mon Sep 17 00:00:00 2001 From: Nathan Rover Date: Thu, 30 Jul 2026 12:26:52 -0400 Subject: [PATCH 2/2] Address review: separate least-privileged Worker credential, npm script, docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - The Worker step now uses CLOUDFLARE_WORKER_API_TOKEN, a second GitHub credential scoped to Worker script + pegma.dev route authority only — the documented contract keeps the Pages token free of Worker scope, and reusing it would have failed auth on every run while blocking Pages. - Deploy via the existing npm run worker:deploy script (single source of truth with local deploys). - docs/PROJECT_PLAN.md and worker/README.md updated: CI deploys the Worker; operator deploy is the break-glass path; step comment spells out the vars-vs-secrets contract (deploy replaces plain vars). Co-Authored-By: Claude Fable 5 --- .github/workflows/deploy.yml | 12 ++++++++---- docs/PROJECT_PLAN.md | 9 ++++++--- worker/README.md | 12 ++++++------ 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c196993..0aea7d8 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -42,13 +42,17 @@ jobs: sha256sum --check --strict # Worker before Pages: the site is a client of the worker's API, so a # freshly deployed site must never race ahead of the API it calls. - # Secrets persist across deploys; plain vars come from wrangler.jsonc - # (a dashboard-added var would be replaced here — use secrets). + # CLOUDFLARE_WORKER_API_TOKEN is a SEPARATE least-privileged credential + # (Workers Scripts:Edit + pegma.dev zone Workers Routes:Edit) — the + # Pages token deliberately carries no Worker authority, per the + # credential contract in docs/PROJECT_PLAN.md. Non-secret worker config + # lives in wrangler.jsonc `vars` (a deploy replaces plain vars, so + # dashboard-added vars do not survive); operator secrets persist. - name: Deploy Worker env: - CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_WORKER_API_TOKEN }} CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - run: npx wrangler deploy -c worker/wrangler.jsonc + run: npm run worker:deploy - name: Deploy to Cloudflare Pages env: CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} diff --git a/docs/PROJECT_PLAN.md b/docs/PROJECT_PLAN.md index f489997..bd24baa 100644 --- a/docs/PROJECT_PLAN.md +++ b/docs/PROJECT_PLAN.md @@ -178,9 +178,12 @@ least-privileged D1 credential. Pull requests run the build gate but never receive the production token; branch previews remain disabled until a separately scoped preview credential exists. -The Worker is an explicit operator deployment until a second GitHub credential -has least-privileged Worker script plus `pegma.dev` route authority. The broad -local OAuth credential is never copied into GitHub. +The Worker deploys from the same push-to-main workflow, ordered before the +Pages deploy, using `CLOUDFLARE_WORKER_API_TOKEN` — a second, separately +least-privileged GitHub credential with Worker script plus `pegma.dev` route +authority only (the Pages token keeps no Worker authority). The broad local +OAuth credential is never copied into GitHub; `npm run worker:deploy` from an +operator session remains available as a break-glass path. ### Phase 3 — the compiled roadmap ✓ (2026-07-27) diff --git a/worker/README.md b/worker/README.md index 2588693..5042fbc 100644 --- a/worker/README.md +++ b/worker/README.md @@ -34,12 +34,12 @@ npx wrangler secret put DATADOG_SITE -c worker/wrangler.jsonc # value: us5.datadoghq.com (or datadoghq.eu — not a full URL) ``` -The GitHub deployment credential is Pages-only. Deploy this Worker from an -authenticated operator session with `npm run worker:deploy` until a separate, -least-privileged credential has both Worker script and `pegma.dev` route -authority. Do not substitute a broad personal OAuth token into GitHub. The -production Worker was operator-deployed on 2026-07-28 as version -`f627b1ee-7675-47b2-a72b-6b26210f3bb3`. +CI deploys this Worker on push to main (before the Pages deploy) using the +separate least-privileged `CLOUDFLARE_WORKER_API_TOKEN` repository secret +(Worker script + `pegma.dev` route authority only; the Pages credential keeps +no Worker authority). Do not substitute a broad personal OAuth token into +GitHub. `npm run worker:deploy` from an authenticated operator session remains +the break-glass path. ## Identity composition