Skip to content

Re-embedding every page needs a bearer - #4

Merged
pullely merged 1 commit into
mainfrom
orun/DQ-4-refresh-needs-a-bearer
Oct 28, 2026
Merged

pullely merged 1 commit into
mainfrom
orun/DQ-4-refresh-needs-a-bearer

Conversation

@pullely

@pullely pullely commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

POST /api/embeddings?refresh=1 (upstream's --refresh) re-embeds every page, billed to the owner's Workers AI. In baseline-v1 anyone who found the URL could trigger it. It now needs Authorization: Bearer <REINDEX_TOKEN>.

  • REINDEX_TOKEN is an optional Orun secret per environment (optionalSecretEnv). The build runs without it (env -u), and tooling/wire/worker-secrets.mjs hands it to the Worker as a Worker secret (wrangler secret bulk, value over stdin) on the deploy lane only.
  • With no token stored, refresh=1 answers 403. A missing bearer, a wrong one, or the token without "Bearer" also gets 403. Every refusal happens before the database or the model is reached. The bearer is compared in constant time over SHA-256 digests (lib/reindex.ts).
  • The plain POST, which the deploy's smoke calls, is unchanged and open: unchanged checksums make it skip every page, and the advisory lock keeps concurrent calls to one embedding.
  • tests/web asserts the 403s embed nothing and change no row, that the right bearer re-embeds the whole index, that the plain POST ignores any bearer, the constant-time compare, worker-secrets.mjs, and that the token is never a wrangler var (37 tests to 46).
  • The e2e gives the dev Worker a random token. It asserts three refusals that embed nothing and change no stored page, then one full re-embed with the right bearer. The stand-in's exact count of page embeddings goes from 3 to 4 to cover that one.
  • Placement holds REINDEX_TOKEN as web's optional, per-environment key. It is kept out of the bundle and handed to the product's own Worker, and every other key is still exactly the minted or published set.
  • The product README gains "Re-embedding every page" (store, redeploy, curl, turn off). The deployment record lists the secret. Risk DQ-E becomes "plain POST open by design, refresh gated". Departure 16 and task DQ-4 are recorded.

🤖 Generated with Claude Code

POST /api/embeddings?refresh=1 (upstream's --refresh) re-embeds every page, billed to the owner's Workers AI. In baseline-v1 anyone who found the URL could trigger it. It now needs Authorization: Bearer <REINDEX_TOKEN>.

- REINDEX_TOKEN is an optional Orun secret per environment (optionalSecretEnv). The build runs without it (env -u), and tooling/wire/worker-secrets.mjs hands it to the Worker as a Worker secret (wrangler secret bulk, value over stdin) on the deploy lane only.
- With no token stored, refresh=1 answers 403. A missing bearer, a wrong one, or the token without "Bearer" also gets 403. Every refusal happens before the database or the model is reached. The bearer is compared in constant time over SHA-256 digests (lib/reindex.ts).
- The plain POST, which the deploy's smoke calls, is unchanged and open: unchanged checksums make it skip every page, and the advisory lock keeps concurrent calls to one embedding.
- tests/web asserts the 403s embed nothing and change no row, that the right bearer re-embeds the whole index, that the plain POST ignores any bearer, the constant-time compare, worker-secrets.mjs, and that the token is never a wrangler var (37 tests to 46).
- The e2e gives the dev Worker a random token. It asserts three refusals that embed nothing and change no stored page, then one full re-embed with the right bearer. The stand-in's exact count of page embeddings goes from 3 to 4 to cover that one.
- Placement holds REINDEX_TOKEN as web's optional, per-environment key. It is kept out of the bundle and handed to the product's own Worker, and every other key is still exactly the minted or published set.
- The product README gains "Re-embedding every page" (store, redeploy, curl, turn off). The deployment record lists the secret. Risk DQ-E becomes "plain POST open by design, refresh gated". Departure 16 and task DQ-4 are recorded.

Co-Authored-By: Claude <noreply@anthropic.com>
Orun-Task: DQ-4
@pullely
pullely merged commit d4c513e into main Oct 28, 2026
5 checks passed
@pullely
pullely deleted the orun/DQ-4-refresh-needs-a-bearer branch October 28, 2026 19:19
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.

2 participants