feat(proxy): bucket rules for serving storage files on custom domains - #13569
Draft
Meldiron wants to merge 2 commits into
Draft
feat(proxy): bucket rules for serving storage files on custom domains#13569Meldiron wants to merge 2 commits into
Meldiron wants to merge 2 commits into
Conversation
Add POST /v1/proxy/rules/bucket so a custom domain can serve the files of one storage bucket by ID at the root path, e.g. https://files.example.com/{fileId}. - Pre-routing hook rewrites root paths onto the file view route, so permissions, scopes, usage, audits, and caching apply unchanged - Router branch limits bucket domains to the bucket's own file routes - New ruleForHost resource binds the project from the domain when no project id was supplied, so plain <img src> embeds work - DNS target follows API and function rules; bucket deletion cascades rules - Rule model documents the new type and resource type Closes #13261 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds a new proxy rule type,
bucket, so a custom domain can serve the files of one storage bucket. Closes #13261.Once the domain is verified, files are served by ID at the root of the domain:
The request is rewritten onto the existing file view route before routing, so nothing about file delivery is duplicated. Bucket and file permissions, scopes, abuse limits, usage, audits, the SVG hardening, and the cache path all apply unchanged. Only files readable by guests are public. File tokens (
?token=) work on the branded URL for everything else.The domain also binds the project, so a plain
<img src="https://files.example.com/{fileId}">works without the project header. That is the gap an API rule cannot close today.How it works
Proxy/Http/Rules/Bucket/Create.phpmirrors the other rule creators. The rule storestype: bucketand links the bucket throughdeploymentResourceType/deploymentResourceId, the same way redirect rules link their resource. No collection migration is needed and the existing indexes cover cascade deletes and console listing.Http::onRequest()hook ingeneral.phprewrites/{fileId}to/v1/storage/buckets/{bucketId}/files/{fileId}/viewfor hosts with a bucket rule. Utopia matches routes before init hooks run, so the rewrite has to happen there.bucketbranch that only lets the bucket's own/files/routes through (view, download, preview) and answers 404 for anything else, including other API routes on that domain.ruleForHostresource resolves the rule for the request host once per request. Theprojectresource falls back to it when no project id was supplied and the rule is a bucket rule. API rules keep their current behaviour._APP_DOMAIN_TARGET_CNAME, like API and function rules.Rulemodel documents the new type and addsbucketto the resource type enum.Tests
testCreateBucketRuleinProxyBase, run by both the console-client and custom-server suites. Success: rule shape, public file served at root without project header, the bucket's view route on the domain, private file blocked, file token grants access, listing by resource, Appwrite-owned domains verified immediately, delete disconnects the domain, bucket deletion cascades rules. Failure: domain not connected, unknown file, root and nested paths, bucket file list, foreign bucket, other API routes, duplicate domain, missing bucket, invalid domains, empty params, reserved sites domain.Ran locally with
_APP_OPTIONS_ROUTER_PROTECTION=enabledlike CI: Proxy 36/36, Storage 94/94, General 30/30, unit 1179/1179. The two "domain not connected" assertions expect 401 for the same reason the sibling Proxy tests do.Notes for reviewers
_APP_OPTIONS_FORCE_HTTPSredirect. The router-level_APP_OPTIONS_ROUTER_FORCE_HTTPSused for deployments is not applied, since after the rewrite the redirect would carry the rewritten path.domainType: bucket. Please confirm the issuer accepts that value.Cache-Control: private. Sendingpublicfor guest-readable files on bucket domains is a natural follow-up throughcacheControlForStorage._APP_SDK_PREVIEW. Say the word if it should be for this release.Have you read the Contributing Guidelines on issues?
Yes
🤖 Generated with Claude Code