Repository navigation
fix(storage): address the bucket on path-style S3 endpoints - #14628
Conversation
A device pointed at a bare service endpoint (MinIO, Ceph, R2 and the like) carries its bucket in the root, so object requests reach `/{bucket}/...` while listings, upload listings and DeleteObjects go to `/` and are answered as ListBuckets. Listings come back empty and prefix deletes remove nothing.
These tests pin what such a device must do once it knows its bucket: list and delete inside it, list multipart uploads, copy server side from the real key, refuse prefixes that climb out of its root before sending anything, and keep resolving objects written by the bucket-in-root construction. The virtual-hosted adapters and an endpoint whose path already names the bucket must keep their request URIs.
The fixtures that paired `bucket: 'my-bucket'` with a bare `s3.example.com` host now use `my-bucket.s3.example.com`, so they keep describing a bucket-addressed endpoint.
A bare service endpoint such as `http://minio:9000` has no bucket in its host, so the bucket has to travel in the request path. Object requests already got it from the root (`{bucket}/...`), but ListObjectsV2, ListMultipartUploads and DeleteObjects were always sent to `/`, which the service answers as ListBuckets: listings came back empty and `deletePath()` deleted nothing.
The device now knows whether its endpoint is the bucket or the service, following the AWS SDKs' force-path-style option. `pathStyle` can say so explicitly; by default a device with a bucket is path-style unless the host is the bucket name, the host begins with `{bucket}.`, or the endpoint path already names the bucket. That keeps every provider adapter and the bucket-in-path endpoint on their current request URIs.
Device paths stay request paths, so keys written before keep resolving to the same objects. Only bucket requests change: on a path-style device they go to `/{bucket}` with a bucket-relative prefix, and listings return `{bucket}/{key}` so a listed path can be handed back to `read()`, `delete()` or `abort()`. A prefix outside the bucket, or one with a `.` or `..` segment, is refused before any request, so `deletePath('../x')` can never reach a sibling root. The server-side copy source is built from the normalised object key, without repeating the bucket a path-style path already carries. DeleteObjects keys are XML-escaped.
With `_APP_STORAGE_S3_ENDPOINT` set, the device was built with the bucket only inside its root, so it could address objects but not the bucket: file listings were empty, and the prefix deletes behind deleting a storage bucket or a user's avatars left every object behind. Passing the bucket lets the device address bucket requests itself. Roots and the paths stored for files and deployments are unchanged, so existing objects keep resolving to the same keys. Same-device copies, which duplicating a deployment makes, now run server side instead of streaming through the server.
Rector's LocallyCalledStaticMethodToNonStaticRector rule flags a static helper that is only called from instance context.
…settings
`deletePath('images')` lists the bare prefix `root/images`, which also matches `root/images-archive/...`; deleting one storage bucket can therefore empty another whose ID starts the same. The new E2E case runs on both addressing styles and the U1 expectation moves to the directory prefix `root/x/`.
Inference has to read the bucket from the last segment of an endpoint path (`/s3/files/` names `files`) and compare it case-sensitively, because paths are case-sensitive while hosts are not. A DeleteObjects answer in Quiet mode lists only the keys it failed to delete, so `deletePath()` must surface them instead of reporting success.
On the application side, `_APP_STORAGE_S3_PATH_STYLE` has to reach the device for endpoints inference misreads, and a configured bucket holding a key prefix (`bucket/prefix`, or a DSN path with a trailing slash) must keep working with its current root. All of it is checked without a request: the endpoints are unresolvable and only a refusal counts.
The E2E path-style tests now build from S3_PATH_BUCKET; only the ones that read the same object through both endpoints need S3_BUCKET to match, and they skip instead of failing when it does not.
… objects
`deletePath()` listed `{root}/{path}` without a trailing slash, so deleting `images` also deleted `images-archive/...`. Now that path-style devices list their bucket, that reached real data. The prefix now ends in a slash, matching the directory semantics of the local device, and repeated slashes are collapsed the way object requests already collapse them.
DeleteObjects in Quiet mode answers 200 and lists only the objects it kept, so a denied or failed delete was reported as success. Those entries now raise a RemoteException carrying the first error code.
Inference reads the bucket from the last segment of the endpoint path, so `https://storage.example.com/s3/files/` addresses `files` instead of being treated as a bare service, and compares that segment case-sensitively, as the service does. Only host comparisons ignore case. The delete loop computes its bucket URI and key prefix once.
Some installations configure `_APP_STORAGE_S3_BUCKET` (or the storage DSN path) as `bucket/prefix` or with a trailing slash. Passing that whole value as the bucket made the device refuse to start. The bucket is now its first segment, and the root keeps the full configured value so keys are unchanged. Inference cannot tell a custom domain that is not named after the bucket from a bare service endpoint. `_APP_STORAGE_S3_PATH_STYLE` set to `enabled` or `disabled` decides it; left empty, the device infers it as before. The variable is documented with the other storage settings and passed through the compose files like them.
An endpoint such as `https://files.example.com` that is a CNAME for the bucket used to work as virtual-hosted with `_APP_STORAGE_S3_BUCKET` set. Nothing in that host names the bucket, so the device now infers path-style and requests `/{bucket}/...` against a host that already addresses it. Those installations have to set `_APP_STORAGE_S3_PATH_STYLE=disabled`, and the variable reference says so. The generated `.env` template lists the variable alongside the other S3 settings.
|
Review complete. No issues found — approved ✅. The change introduces a new
Reviewed commit: b7a7748 |
New ConsoleProject ID: Tip JWT tokens let functions act on behalf of users while preserving their permissions |
🟢 Tier S · Ready to merge
This change adds inferred or configurable path-style addressing for custom S3 endpoints, wiring the setting through Appwrite configuration and deployment files. It updates bucket-level S3 listing, multipart upload listing, deletion, and copy behavior, documents the configuration, and adds unit and S3-compatible end-to-end coverage. Latest changes: The newest commit replaces regex-based repeated-slash normalization in S3 bucket request prefixes with segment filtering and adds regression cases for virtual-hosted and path-style endpoints.
📂 Walkthrough · 11
Reviewed the commits since |
commit: |
Security rulesNo new WARNING or ERROR findings from security rules. 19 existing findings tracked in
|
The repository avoids preg_* where string functions do the job. Splitting on the slash and dropping empty segments gives the same prefix, trailing slash included, which the new unit test pins for both addressing styles.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|

Problem
With
_APP_STORAGE_S3_ENDPOINTset,getDevice()puts the bucket in the device root ({bucket}/{root}) but never tells the device it is the bucket. Object requests land on/{bucket}/…; bucket-level requests go to/, which an S3 service answers as ListBuckets./{bucket}/{root}/{key}GET /?list-type=2&prefix={bucket}/{root}/…→ bucket list, empty listingGET /{bucket}?list-type=2&prefix={root}/…GET /?uploads→ emptyGET /{bucket}?uploads&prefix={root}/…deletePath)POST /{bucket}?deleteDesign
The S3 device owns addressing. New constructor argument, mirroring the AWS SDK's force-path-style:
Inference when
pathStyleisnull:files.example.com){bucket}.(files.s3.us-east-1.amazonaws.com)http://minio:9000/files)http://minio:9000)/{bucket}getDevice()passes onlybucket:(first segment of_APP_STORAGE_S3_BUCKET) andpathStyle:from the new_APP_STORAGE_S3_PATH_STYLE:_APP_STORAGE_S3_PATH_STYLEpathStyleenabledtruedisabledfalsenull(infer)The root stays
{bucket}/{root}, so persisted paths (filepath, build paths) keep mapping to the same keys. Listings return paths starting with{bucket}/, so they can be passed back to any other method.Also fixed
deletePath()has directory semantics: deletingimagesno longer removesimages-archive/…(already the case on AWS).RemoteExceptioninstead of reporting success.x-amz-copy-sourceis/{bucket}/{key}with the real key; path-style keys already carry the bucket, so they are not prefixed twice../..segments are refused for path-style bucket-level paths, before any request.Upgrade note
_APP_STORAGE_S3_PATH_STYLE=disabled._APP_COMPUTE_SIZE_LIMITis raised past 5 GB.Tests
RED = run against
mainsource with the new tests.maintestPathStyleListsTheBucketlistFiles()→[]testPathStyleListsUploadstestDeletePathStaysInsideItsRoot(virtual, path-style)deletePath(''),..refusaldeletePath('');..reaches the servicetestDeletePathKeepsSiblingsSharingItsName(virtual, path-style)images-archive/f.txtdeletedtestPathStyleCopyRunsServerSideNoSuchKey(source/{b}/{b}/…)testVirtualHostedLegacyRootCopiesTheRealKeytestLegacyBucketInRootObjectsResolveUnderPathStyle{bucket}/{root}objectslistFiles()→[]testVirtualHostedSubclassesKeepTheirRequestUris×6testAddressingFollowsTheEndpointpathStyle/instead of/{bucket}testAddressingRefusesWhatItCannotAddresstestDeletePathReportsObjectsTheServiceKepttruetests/unit/Deployment/StorageTest(testPathStyleDeviceKnowsItsBucket,testPathStyleSettingReachesTheDevice,testBucketHoldingSlashesKeepsItsRoot)getDevice()wiringPackage E2E runs against an S3-compatible server (silo/MinIO). Each new source rule was also mutated out one at a time and its test went red.
Notes
getDevice()(endpointhttp://minio:9000, bucketappwrite→/appwrite), but none of its tests assert a bucket-level operation.S3.php(sameprefix()/$pathStylenames); whichever lands second rebases.