Skip to content

ci: deploy through the Cloudflare Deploy Broker instead of the static CLOUDFLARE_API_TOKEN - #111

Merged
sds merged 2 commits into
mainfrom
ci/cloudflare-deploy-broker
Nov 21, 2026
Merged

sds merged 2 commits into
mainfrom
ci/cloudflare-deploy-broker

Conversation

@sds

@sds sds commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Merge after tempoxyz/cloudflare-deploy-policies#293 has merged and its Publish policies run has succeeded. See "Merge after" below.

Draft on purpose. A ready pull request gets a preview: preview.yml on main runs this branch's code with the preview environment's token. main's preview_deploy.yml does not yet replace this branch's new tipbot-preview-name placeholder, so that preview would create a D1 database, Queues and a Slack app and then fail at Run migrations. Mark it ready just before merging. Previews of pull requests opened after it merges work.

Summary

A push to main now deploys the tipbot Worker (https://tip.bot) through the Cloudflare Deploy Broker. No job of production.yml holds a Cloudflare credential any more, so the production environment's CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID become unused. The Worker keeps its name, D1 database, Durable Objects, Queue, AI binding, cron, custom domain and secrets. Previews are unchanged and still use the preview environment's token; see "Previews" below.

Why production.yml has been failing

Every Production run since 2026-11-04 (#95's merge) fails at Run migrations, so nothing after #107 has deployed. tipbot still serves version 54437c81, which run 41477298036 deployed on 2026-11-02 with this workflow (author tom@tempo.xyz, the owner of the API token).

  • The step is wrangler d1 migrations apply tipbot --env production --remote. Wrangler reads the ledger and lists 0026_tempo_workspace_ousd.sql, feat: default to OUSD #95's one UPDATE, as pending. Then D1 refuses to run it: You do not have permission to perform this operation. [code: 7500] (runs 41924847485 and 42512225697).
  • So the token can read the database but not write it. 0026 is the first migration since 0025 on 2026-06-05, and the 11-02 run had none to apply, so this is the first D1 write the token has attempted in five months.
  • Someone replaced CLOUDFLARE_API_TOKEN in both environments on 2026-11-17 22:23 UTC and re-ran 42512225697 a minute later. It failed the same way, so the new token cannot write D1 either. It is probably a user token whose owner's tempo-prd role lacks D1 write, or a token without D1 Edit. I could not check which, because I can't read either.

The broker applies 0026 with its own credential, so this PR also fixes the failure, provided the database accepts the statement.

Before / after

Area Before After
D1 migrations wrangler d1 migrations apply with the static token The broker applies pending migrations from the attested db/migrations before it uploads, and stops before promotion if one fails
Build pnpm build in the deploy job, with the token in the job The trusted cloudflare-deploy-broker-build.yml (gh-actions 1a535d66) runs pnpm build:broker and attests the Worker, its 48 chunks, dist/server/wrangler.json, dist/client and the migrations. No credential
Deploy Vendored wrangler-action, deploy --env production, plus wrangler secret bulk of 15 secrets cloudflare-deploy-broker with deployment ID tipbot, then a check that https://tip.bot/api/health (which queries D1) returns 200
Secrets Re-uploaded from the production environment on every deploy Kept on the Worker. Change them in the broker dashboard (https://cf.tehq.net/, Workers tab)
Slack app ID vars.SLACK_APP_ID in the deploy job A Settings job in the production environment reads it and passes it to the build. It is public: tip.bot serves it in a meta tag
Concurrency None One Production run at a time, never cancelled
Slack app update After deploy Unchanged

Changes needed for the broker build

  • Wrangler 4.91.0 → 4.151.0. The builder rejects Durable Object migrations and needs exports, which Wrangler 4.91 does not understand. 4.151.0 is already in the lockfile through @cloudflare/vitest-plugin, so the lockfile only switches the importer; no new package is added. @cloudflare/vite-plugin 1.37.0 accepts it (^4.91.0).
  • src/worker-configuration.d.ts is regenerated by pnpm gen:types. Wrangler now declares Env and Cloudflare.Env as extensions of a generated __BaseEnv_Env, so src/env.d.ts adds its stronger types to both.
  • The preview Worker name placeholder is tipbot-preview-name instead of __PREVIEW_NAME__, because Wrangler 4.151's wrangler types rejects a Worker name with capitals or underscores. preview_deploy.yml replaces both, so branches from before this PR still preview.
  • scripts/broker-build.ts (pnpm build:broker) runs pnpm build for production, then adjusts the generated dist/server/wrangler.json:
    • It declares the live Durable Object classes as exports, derived from wrangler.jsonc's migrations: TipbotChatStateDO as SQLite (created as ChatStateDO, renamed in tipbot_chat_state_v2) and NonceStorage as legacy-kv. The broker never replays migrations. wrangler.jsonc keeps them for previews and local development.
    • It makes migrations_dir relative to the generated file, adds the ASSETS binding the broker requires (nothing reads it), and deletes the Vite plugin's .assetsignore, which the broker rejects and which lists only files the client build does not write.
  • wrangler.jsonc sets account_id (tempo-prd) in env.production, which the builder requires.
  • db/migrations/0020_telegram_provider.sql is a no-op placeholder. Production run 26782816327 applied an earlier file of that name (327ef06) before 954bf9b reverted it, so the production ledger still records it. Wrangler ignores applied names it has no file for; the broker requires every recorded name to be one of the attested manifest's first ones, and otherwise fails with d1_migration_history_mismatch. On a fresh database (local, tests, previews) the placeholder runs one UPDATE … WHERE 0. It sorts before 0020_tip_ask.sql, after 0019.

Also: pnpm audit

c34b6d2 is separate from the migration. main's Verify job now fails pnpm audit on seven advisories published since #109: hono below 4.13.16 (GHSA-4m76-xfj5-7975, GHSA-h7mg-cq63-vhpq and five others) and @hono/node-server below 2.1.6 (GHSA-qv5m-9pm6-hqp3, GHSA-jpvv-r467-5p4w). This PR fails the same way without a fix, so it pins hono 4.13.19 and overrides @hono/node-server to 2.1.9 (both older than the one-day release-age policy). These are patch releases.

Secrets

The broker keeps the live Worker's secrets. wrangler secret list --name tipbot (names only) shows all 14 that wrangler.jsonc requires (FEE_PAYER_PRIVATE_KEY_MAINNET, FEE_PAYER_PRIVATE_KEY_TESTNET, SECRET_KEY, SLACK_CLIENT_ID, SLACK_CLIENT_SECRET, SLACK_SIGNING_SECRET, TEMPO_API_KEY, and the seven TWITTER_*), plus RPC_CREDENTIALS, which src/lib/tempo.ts reads, and TELEGRAM_BOT_TOKEN and TELEGRAM_WEBHOOK_SECRET_TOKEN, which nothing reads since the Telegram revert.

Important

The production environment's RPC_CREDENTIALS was updated on 2026-11-12, after the last successful deploy (11-02). Every deploy since has failed, so the Worker still has the earlier value, and this workflow no longer uploads secrets. If the new value should be live, set RPC_CREDENTIALS in the broker dashboard. No other production secret changed after 11-02.

Behavior to review

  • Source maps. upload_source_maps stays in wrangler.jsonc, but the broker never uploads source maps, so production stack traces will not be source-mapped.
  • New binding. The first broker deploy adds ASSETS. Assets are still served directly, before the Worker, as now.
  • The first deploy applies 0026 (sets OUSD as the default token for Tempo's own Slack workspace), which has been pending since 11-04.
  • Changing bindings needs a policy change. After the first deploy, the broker's remembered grant authorizes code, vars, assets and new D1 migrations. A new binding, Durable Object class or resource ID needs a policy entry in tempoxyz/cloudflare-deploy-policies first.
  • The Settings job records a deployment to the production environment before the build, because it reads that environment's SLACK_APP_ID.
  • This PR's CI does not run the broker build, which runs only on push to main. I replayed it (see Validation).

Previews

PR code runs while the preview environment's token is in the job. preview.yml loads from main, but preview_deploy.yml's deploy job checks out the pull request's commit and then runs its code in the same job as the token: its setup-pnpm composite action and lockfile, src/lib/*.ts, scripts/slack.ts, its wrangler for queues create, d1 migrations apply and deploy, vite.config.ts during the build, and scripts/preview-seed.ts with CLOUDFLARE_API_TOKEN in its environment. The token can edit every Worker and every D1 database in tempo-prd. preview-seed.ts also reads the production tipbot database. Both environments' tokens were replaced in the same second on 11-17, so they are probably the same token.

The broker's isolated previews cannot do this: each preview creates its own Worker, D1 database and Queues, attaches pr<n>.tip.bot, and binds secrets. Moving previews to STS safely means splitting preview_deploy.yml so the pull request's code only builds, without credentials, and code from main does every privileged step. That is a larger change of the Slack and seeding steps too, and it cannot run before it merges, so this PR leaves previews as they are. It is listed as a decision for the owner.

Validation

  • pnpm audit reports no known vulnerabilities, and pnpm check, pnpm check:types and pnpm test --project unit pass locally. pnpm db:migrate and pnpm db:codegen on a fresh local database apply all 30 migrations and leave db/types.gen.ts and db/schemas.gen.ts unchanged.
  • actionlint passes. zizmor 1.30.1 (offline) reports no findings, as on main.
  • I replayed the pinned builder on this branch: its install, its pnpm build:broker build command and every packaging step, on macOS and in a node:24.22.1 Linux container. Every builder check passes. It attests index.js plus 48 esm modules (6.9 MB), 32 assets (6.3 MB, all with known media types) and 30 migrations.
  • tempoxyz/cloudflare-deploy-policies#293's policy accepts that configuration and module manifest at the publisher's BROKER_REF and at broker main, and rejects drifted ones (preview URLs on, another D1 database, another Worker, an extra route, a KV namespace, NonceStorage as SQLite).

Merge after

  1. tempoxyz/cloudflare-deploy-policies#293 merges and Publish policies succeeds. Before that, the broker refuses the existing Worker name ("an explicit policy is required") and the current version keeps serving.
  2. Before merging, optionally confirm the ledger row: wrangler d1 execute tipbot --remote --env production --command "SELECT name FROM d1_migrations ORDER BY id" should list 0020_telegram_provider.sql. If it does not, delete db/migrations/0020_telegram_provider.sql from this PR.

After merge

  1. Confirm the merge push's Production run succeeds (the bootstrap deploy), the deploy step reports a promoted version, and https://tip.bot/api/health returns 200. The broker dashboard (https://cf.tehq.net/) should show tipbot promoted.
  2. Remove the bootstrap entry policies/tempoxyz/tip.bot.yaml from tempoxyz/cloudflare-deploy-policies. Later deploys use the remembered grant.
  3. Set RPC_CREDENTIALS in the broker dashboard if the 11-12 value should be live (see Secrets).
  4. Delete the production environment's CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID. Nothing reads them after this PR. The environment's Worker secrets (FEE_PAYER_*, RPC_CREDENTIALS, SECRET_KEY, SLACK_CLIENT_*, SLACK_SIGNING_SECRET, TEMPO_API_KEY, TWITTER_*, TELEGRAM_*) are unread too; delete them only if no one needs them as the copy of record. Keep vars.SLACK_APP_ID.
  5. Do not revoke the Cloudflare token yet. The preview environment's CLOUDFLARE_API_TOKEN is probably the same token, and previews still use it.

If the bootstrap deploy fails before promotion, the current version keeps serving. Reverting this PR restores the Wrangler workflow, which still fails at the D1 migration.

@sds
sds marked this pull request as draft November 20, 2026 22:45
@sds
sds deployed to preview November 20, 2026 22:46 — with GitHub Actions Active

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed this PR and didn't find any bugs. It rewrites how production is deployed, which changes who holds credentials, how D1 migrations get applied, and how Durable Object classes are declared, so a human should still look at it before merge.

What was reviewed:

  • production.yml: the job graph (authorize -> settings/check -> build -> deploy -> update_slack_app), the non-cancelling concurrency group, the SLACK_APP_ID regex check before it reaches build-command, and the health-check loop.
  • scripts/broker-build.ts: how DO migrations become exports (the rename keeps the storage type, and unsupported migration fields throw), the relative migrations_dir, the ASSETS binding, and the .assetsignore check.
  • The 0020_telegram_provider.sql placeholder (a no-op WHERE 0 update), the preview sed that handles both the old and new placeholder names, and the matching Env additions in src/env.d.ts.
  • Not checked, because reading the code can't settle them: whether the pinned tempoxyz broker workflow and action behave as described, and whether production's d1_migrations ledger and live secrets match what the PR says.
Extended reasoning...

The PR changes the production deploy workflow, adds a build script that rewrites the generated wrangler.json, bumps wrangler from 4.91.0 to 4.151.0 (which regenerates about 3.7k lines of types), and adds a placeholder D1 migration. It touches security-sensitive surface: Cloudflare credentials leave production CI, deploy authorization moves to an external broker, and Worker secrets are no longer uploaded from GitHub. Whether it works depends on external state this review can't see: the broker policy PR it must merge after, the production migration ledger, and the RPC_CREDENTIALS value the description flags as stale. Those, plus the critical deploy path, are why this is a defer rather than an approve.

@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedhono@​4.13.13 ⏵ 4.13.19100 +1100 +69796100

View full report

@sds
sds marked this pull request as ready for review November 21, 2026 04:47
@sds
sds merged commit 38e18dc into main Nov 21, 2026
8 checks passed
@sds
sds deleted the ci/cloudflare-deploy-broker branch November 21, 2026 04:47
@sds
sds deployed to preview November 21, 2026 04:47 — with GitHub Actions Active

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Comment thread pnpm-workspace.yaml
Comment on lines +70 to +71
'@hono/node-server@<2.1.6': 2.1.9
'hono@<4.13.16': 4.13.19

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 (optional) Future hono upgrades will fail to install or leave dependencies stuck on 4.13.19, so later advisories cannot be cleared by bumping hono. pnpm applies 'hono@<4.13.16': 4.13.19 to every spec that overlaps the range, including peer ranges. The lockfile already rewrites ^4, >=3.9.0 and >=4.10.0 to an exact hono: 4.13.19. Fix: make the override track the direct dependency, e.g. hono: $hono, so dependents and peers follow package.json's hono on the next bump. The same applies to the @ hono/node-server@<2.1.6 entry if it gains dependents.

Why this was flagged

pnpm checks an override selector like hono@<4.13.16 by range intersection, not by the version that would resolve. The lockfile shows the effect: the peer ranges of @ hono/node-server (^4, pnpm-lock.yaml:745), @ hono/standard-validator (>=3.9.0), @ hono/zod-validator (>=4.10.0), hono-openapi (^4.11.2) and mppx (>=4.12.25) all became hono: 4.13.19. Suppose a maintainer, or pnpm deps (taze), bumps package.json's hono to 4.13.20 or 4.14.x for the next advisory. The root spec no longer overlaps <4.13.16, so the root moves but every transitive copy stays on 4.13.19. Peers such as @ hono/zod-validator now require exactly 4.13.19, so with strictPeerDependencies: true (pnpm-workspace.yaml) the install fails on an unmet peer. On the base branch no hono override existed, so hono peers and dependents followed the root version. The older '@ hono/node-server@<2.1.3' override caused no such pin because nothing declares @ hono/node-server as a peer, so it is no safeguard here.

Verification: Trigger: a later hono bump in package.json that leaves the 'hono@<4.13.16': 4.13.19 override in place. The root specifier 4.13.19 (package.json:41) does not overlap <4.13.16, so the override does not touch it. @ hono/zod-validator is a direct root dependency (package.json:34) whose peer now reads exactly 4.13.19. With strictPeerDependencies: true (pnpm-workspace.yaml), that unmet peer fails the install.

Comment on lines +101 to +126
timeout-minutes: 20
environment: production
permissions:
contents: read
id-token: write
steps:
- name: Secure runner
uses: tempoxyz/gh-actions/actions/secure-runner@35019557465e3c38ee3468be171771fd73577584 # 2026-10-20T06-22-38Z-35019557

# The broker applies pending D1 migrations to DB, then uploads and
# promotes the version, and stops before promotion if a migration fails.
# The Worker keeps its secrets; change them in the broker dashboard
# (https://cf.tehq.net/, Workers tab).
- name: Migrate D1 and deploy through the broker
uses: tempoxyz/gh-actions/actions/cloudflare-deploy-broker@1a535d662a51f211d750307541069cb849535414 # 2026-11-19T07-33-38Z-1a535d66
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: deploy --env production
environment: production
secrets: |
FEE_PAYER_PRIVATE_KEY_MAINNET
FEE_PAYER_PRIVATE_KEY_TESTNET
RPC_CREDENTIALS
SECRET_KEY
SLACK_CLIENT_ID
SLACK_CLIENT_SECRET
SLACK_SIGNING_SECRET
TEMPO_API_KEY
TWITTER_ACCESS_TOKEN
TWITTER_ACCESS_TOKEN_SECRET
TWITTER_BEARER_TOKEN
TWITTER_CONSUMER_KEY
TWITTER_CONSUMER_SECRET
TWITTER_OAUTH_CLIENT_ID
TWITTER_OAUTH_CLIENT_SECRET
env:
FEE_PAYER_PRIVATE_KEY_MAINNET: ${{ secrets.FEE_PAYER_PRIVATE_KEY_MAINNET }}
FEE_PAYER_PRIVATE_KEY_TESTNET: ${{ secrets.FEE_PAYER_PRIVATE_KEY_TESTNET }}
RPC_CREDENTIALS: ${{ secrets.RPC_CREDENTIALS }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
SLACK_APP_ID: ${{ vars.SLACK_APP_ID }}
SLACK_CLIENT_ID: ${{ secrets.SLACK_CLIENT_ID }}
SLACK_CLIENT_SECRET: ${{ secrets.SLACK_CLIENT_SECRET }}
SLACK_SIGNING_SECRET: ${{ secrets.SLACK_SIGNING_SECRET }}
TEMPO_API_KEY: ${{ secrets.TEMPO_API_KEY }}
TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }}
TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}
TWITTER_BEARER_TOKEN: ${{ secrets.TWITTER_BEARER_TOKEN }}
TWITTER_CONSUMER_KEY: ${{ secrets.TWITTER_CONSUMER_KEY }}
TWITTER_CONSUMER_SECRET: ${{ secrets.TWITTER_CONSUMER_SECRET }}
TWITTER_OAUTH_CLIENT_ID: ${{ secrets.TWITTER_OAUTH_CLIENT_ID }}
TWITTER_OAUTH_CLIENT_SECRET: ${{ secrets.TWITTER_OAUTH_CLIENT_SECRET }}
deployment-id: tipbot
artifact-id: ${{ needs.build.outputs.artifact-id }}
archive-digest: ${{ needs.build.outputs.archive-digest }}
module-digest: ${{ needs.build.outputs.module-digest }}

# /api/health queries D1.
- name: Check https://tip.bot
run: |
for _ in $(seq 1 10); do
if curl -fsS --max-time 10 https://tip.bot/api/health; then exit 0; fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 nit (optional): Two new time durations have no human-readable comment, which AGENTS.md requires. They are timeout-minutes: 20 at production.yml:101 and curl --max-time 10 at production.yml:126. The neighbouring sleep 6 # 6 seconds follows the rule. Fix: add trailing comments such as # 20 minutes and # 10 seconds.

Why this was flagged

AGENTS.md:52 says every added time duration or amount needs a comment next to it giving the human-readable time. The diff adds timeout-minutes: 20 to the deploy job at .github/workflows/production.yml:101 and curl -fsS --max-time 10 in the health-check loop at line 126, and neither has a comment. The sleep 6 # 6 seconds two lines below shows the convention the author was following. This is a convention slip only and changes no behaviour. Nothing in CI enforces the rule, so nothing catches it.

Verification: Severity: nit. This is a convention slip that breaks nothing at runtime. AGENTS.md:52 says: "whenever you add a time duration/amount, make sure it has comment next to it with the human-readable time". The diff adds timeout-minutes: 20 at .github/workflows/production.yml:101 and curl -fsS --max-time 10 at line 126, and neither has a comment. Behavior is unaffected.

sds added a commit that referenced this pull request Nov 21, 2026
…ad of the static CLOUDFLARE_API_TOKEN (#112)

**Merge after** tempoxyz/cloudflare-sts#197 has merged and STS has
deployed it. Before that, the first preview fails at "Fetch a Cloudflare
token". See "Merge after" below.

Pull request previews stop running the pull request's code next to the
`preview` environment's long-lived `CLOUDFLARE_API_TOKEN`. Production
already deploys through the broker (#111). After this PR, no workflow on
`main` reads the `preview` environment's `CLOUDFLARE_API_TOKEN` or
`CLOUDFLARE_ACCOUNT_ID`.

- **`pull_request.yml` gets a Preview Build job.** It builds the pull
request with `CLOUDFLARE_ENV=preview` and no secrets. It uploads the
Worker, static assets, D1 migrations and both Slack manifests as the
`preview` artifact.
- **`preview.yml` → `preview_deploy.yml` now run only main's code.**
They check out main, check the artifact, configure the Slack app, and
only then fetch a 10-minute Cloudflare STS token (`preview-deploy`).
With it they create the D1 database and queues, apply the pull request's
migration SQL, and deploy the build unbundled with main's
`wrangler.jsonc` and the preview secrets. A fresh D1-only token
(`preview-seed`, 15 minutes) then seeds the database with main's
`scripts/preview-seed.ts`.
- **`preview_destroy.yml` and `preview_sweep.yml`** fetch their own STS
tokens (`preview-destroy`, `preview-sweep`) in place of the secret.

## Before / after

| | Before | After |
| --- | --- | --- |
| Pull request's code | Checked out in `preview_deploy.yml`'s Deploy
job. Its `setup-pnpm` action, lockfile, `src/lib`, `scripts/slack.ts`,
Wrangler, build and `scripts/preview-seed.ts` ran there, with the
Cloudflare token, the fee payer keys, `SECRET_KEY` and the Slack config
token (which can mint a `secrets: write` GitHub token) | Runs only in
Preview Build, under the `pull_request` identity, with no secrets |
| Cloudflare token | Static `CLOUDFLARE_API_TOKEN`: no expiry or IP
binding, and `.github/TODO.md` lists it on all accounts | STS tokens
pinned to main's three workflows in the `preview` environment (deploy 10
min, seed 15 min with D1 only, destroy 10, sweep 15), this runner's IP
only, revoked when the job ends |
| Wrangler, config, seed, reaction emoji | The pull request's | Main's.
Wrangler uploads the artifact as data (`no_bundle`, `upload_source_maps:
false`) |
| D1 migrations, Worker bundle, assets, Slack manifests | The pull
request's | Still the pull request's, as checked data |
| Preview D1 database | ID from the preview comment | Found by name
(`tipbot-pr<n>`) |
| Fork pull requests | Previewed if an organization member started or
re-ran the run | No preview |

## Why STS, not the broker

Each preview creates a Worker, a D1 database and two queues, attaches
`pr<n>.tip.bot`, and uploads per-preview secrets, including its Slack
app's credentials. The broker's policy-free previews bind only static
assets and version metadata, and the broker creates no D1 database or
queue for an unpublished Worker. It also never deletes any of these. The
seed also reads the production database. tempoxyz/cloudflare-sts#197 has
the full reasoning.

## How the trusted job treats the pull request's build

- **It checks out and runs only main.** It installs main's lockfile with
`--ignore-scripts`, as `setup-pnpm` already did. Main's code computes
the reaction emoji and runs the seed.
- **The artifact stays outside the workspace.**
`scripts/preview-artifact.ts check` runs before any token is fetched. It
refuses symbolic links and special files, any top-level entry beyond
`client`, `migrations`, `server` and the two manifests, migration names
other than `NNNN_name.sql`, and a manifest whose app name isn't `Tipbot
PR <n>` or that holds a URL off `https://pr<n>.tip.bot/`.
- **`preview-artifact.ts config` writes the deploy config from main's
`wrangler.jsonc`.** That config sets the Worker name, bindings, D1
database, queues, custom domain and vars. Only `main`/`base_dir`, the
assets directory and `migrations_dir` point at the artifact. It sets
`upload_source_maps: false`, because Wrangler otherwise follows
`sourceMappingURL` comments to any file. The build writes no source
maps, so nothing is lost. The script also asserts the name, D1 binding,
route and `HOST` before writing.
- **Only the workflow's own comments count.** Every read of the preview
comment now requires `github-actions[bot]` as the author. Before, any
comment containing `tipbot-preview` counted, and this repository is
public. Destroy and sweep then took `d1_id` and Slack app IDs from it,
so a crafted comment could point a deletion at another D1 database or
Slack app. D1 databases are now always found by name.

## Behavior to review

- **The STS token is broad.** Cloudflare can't scope D1, Queues or
Workers Scripts write to one resource. For 10 minutes the deploy token
can rewrite every Worker in tempo-prd, `tipbot` included, and read and
write every D1 database, the production `tipbot` database included. STS
reserves `d1_read` for tempoxyz/cloudflare, so the seed reads production
with a D1 Write token of its own (15 minutes, no Workers or Queues).
That's why the job must never run pull request code (comment at the top
of `preview_deploy.yml`).
- **A preview still runs the pull request's code with real secrets and
data, as before.** That means
`FEE_PAYER_PRIVATE_KEY_MAINNET`/`_TESTNET`, `SECRET_KEY`,
`TEMPO_API_KEY`, its Slack app's credentials, and a seeded copy of one
production Slack workspace's linked members (addresses, Slack IDs and
names). The org-membership gate and the new same-repository rule are
what stand in front of that.
- **Some pull request changes reach the preview only after they merge.**
That covers changes to `wrangler.jsonc` (bindings, vars, compatibility
date), the Wrangler version, `scripts/preview-seed.ts`, the reaction
emoji code and `public/tipbot-preview.png`. Code, assets, migrations and
Slack scopes and events still preview. If a pull request changes the
seeded tables' schema, main's seed may fail on its preview until it
merges.
- **The `slack-app-id` meta tag on a pull request's first preview is
empty.** The build now runs before the Slack app exists, so it reads the
ID from the preview comment, and the next push fills it in.
- **Fork pull requests get no preview.** Before, an organization
member's re-run would preview a fork's code with all of the above.
- **This PR shows no preview.** Its own Preview Build runs, but
`preview.yml` runs from main, where the old flow still is. I keep this
PR a draft except while the Claude review starts, so main's old flow
never deploys it with the static token. Mark it ready just before
merging, as with #111.
- **Open branches without this change get no preview until they merge
main.** Their Pull Request run uploads no `preview` artifact, so the
Gate job skips the deploy with a notice. The same happens for a run
whose push was a draft's, or whose artifact (kept 3 days) has expired. A
run for a commit the pull request has already moved past also ends
without deploying, and the newer commit's run deploys.
- **Previews haven't deployed since 2026-11-01.** On 11-08 and 11-14 the
static token got 401 at "Setup preview D1". After it was replaced on
11-17, no ready pull request has run one, and production's runs with the
same token were refused D1 writes (#111). So the first run after merge
is also the first test of the whole path.

## Validation

- `pnpm check` (format, lint, type-aware) and `pnpm check:types` pass.
actionlint 1.7.12 passes. zizmor 1.30.1 (offline) reports no findings,
as on main.
- I built the preview locally as Preview Build does
(`CLOUDFLARE_ENV=preview`, substituted `wrangler.jsonc`) and packaged
the artifact.
- `preview-artifact.ts check` accepts it. It refuses: a symlink to a
file, a symlink to a directory, a FIFO, a `.SQL` migration, an extra
top-level file, a directory named `server/index.js`, a manifest redirect
to another host, `https://pr999.tip.bot.evil.example/`,
`https://tip.bot/...`, and an app named `Tipbot`.
  - `preview-artifact.ts config` refuses a malformed D1 ID.
- With main's Wrangler 4.151.0 in the job's layout (config in its own
directory, artifact elsewhere), `wrangler deploy --config wrangler.json
--env preview --dry-run --secrets-file` accepts the generated config. It
uploads 48 ES modules (6,749 KiB), reads 34 asset files, and binds
`CHAT_STATE`, `AUTH_NONCE`, `PENDING_TIP_QUEUE` →
`tipbot-pending-tip-pr999`, `DB` → `tipbot-pr999`, `AI`,
`CF_VERSION_METADATA`, the vars and the seven secrets. That matches what
the old flow deployed in run 41330856120. `wrangler d1 migrations list
--local` with the generated config reads the artifact's 30 migrations.
- I confirmed in Wrangler 4.151.0's source that `--secrets-file` uploads
`secret_text` bindings, and that a first deploy without them fails
because of `secrets.required`. Source maps load unless
`upload_source_maps === false`. Custom domains go through account-level
`/workers/scripts/<name>/domains/changeset` and
`/workers/domains/records` calls, with no `/zones` lookup.

## Merge after

1. tempoxyz/cloudflare-sts#197 merges and STS deploys it.
2. Mark this PR ready and merge it right away.

## After merge

1. On the next ready pull request from a branch of this repository,
check that Preview Build uploads `preview`, and that **Preview /
Deploy** fetches a token and passes "Deploy preview" and "Seed preview
workspace". Also check that `https://pr<n>.tip.bot` answers and the
comment shows Ready.
2. Close or draft that pull request and check that **Preview Destroy**
fetches a token and deletes the Worker, D1 database and queues. The next
midnight **Preview Sweep** should also fetch one.
3. Then delete the `preview` environment's `CLOUDFLARE_API_TOKEN` and
`CLOUDFLARE_ACCOUNT_ID` in tempoxyz/tip.bot. Nothing on main reads them.
4. Revoke the Cloudflare token behind them. It was set at the same
second as production's (2026-11-17 22:23:40 UTC), and production's copy
is already deleted, so it is probably the same token.

This branch was successfully deployed

1 active deployment
preview — c34b6d28 Deployed Nov 21, 2026 by sds via Destroy #85
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