Skip to content

Check in preflight that no R2 bucket has a public URL - #91

Open
nedtwigg wants to merge 2 commits into
mainfrom
preflight-bucket
Open

nedtwigg wants to merge 2 commits into
mainfrom
preflight-bucket

Conversation

@nedtwigg

Copy link
Copy Markdown
Member

docs/specs/access.md requires that every image is served by the Worker after an access check, so the bucket's r2.dev URL and custom domains stay off. Nothing checked that. Now preflight, which already checks the Hyperdrive and the Worker's secrets, reads every bucket_name in ui/wrangler.toml and fails the release if any of those buckets has its r2.dev URL on or a custom domain. A response of an unexpected shape fails too, rather than passing.

The rule moves above the fold in access.md, into Who can do what, since it's enforced now. The rest of Serving images stays under ## Future.

The deploy token has had Workers R2 Storage Read since #88. Tested with a real preflight against the account, using wrangler's login token:

Hyperdrive selfie-auth is uncached, selfie-app has all 7 secrets, and no R2 bucket (selfie-blobs) has a public URL.

The responses it reads are {"enabled": false, …} and {"domains": []}. The first release after merging will be the first run with the deploy token itself.

🤖 Generated with Claude Code

nedtwigg and others added 2 commits November 19, 2026 23:02
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ss.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@selfie-bot selfie-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

OPERATIONS.md step 2 of setting up ("Create the R2 bucket, with its r2.dev access left off") still cites docs/specs/access.md → Serving images. The rule now lives under Who can do what, so that pointer should move there too. It's outside the diff, so there's no inline suggestion for it.

Comment thread ui/scripts/production.mjs

/** Every R2 bucket `wrangler.toml` binds. */
function bucketNames() {
const names = [...readFileSync("wrangler.toml", "utf8").matchAll(/^bucket_name = "([^"]+)"$/gm)].map(([, name]) => name);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is the one place the check can pass without having looked. A second [[r2_buckets]] written as bucket_name="x", indented, or with a trailing comment doesn't match, and its bucket is skipped without an error. The length === 0 guard only catches the case where every bucket is missed. A looser match keeps the check fail-closed for those spellings:

Suggested change
const names = [...readFileSync("wrangler.toml", "utf8").matchAll(/^bucket_name = "([^"]+)"$/gm)].map(([, name]) => name);
const names = [...readFileSync("wrangler.toml", "utf8").matchAll(/^\s*bucket_name\s*=\s*["']([^"']+)["']/gm)].map(([, name]) => name);

This branch has not been deployed

No deployments
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