Skip to content

fix(storage): address the bucket on path-style S3 endpoints - #14628

Merged
ChiragAgg5k merged 9 commits into
mainfrom
fix/s3-path-style
Oct 18, 2026
Merged

ChiragAgg5k merged 9 commits into
mainfrom
fix/s3-path-style

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

Problem

With _APP_STORAGE_S3_ENDPOINT set, 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.

Request Before After
GetObject / PutObject /{bucket}/{root}/{key} unchanged
ListObjectsV2 GET /?list-type=2&prefix={bucket}/{root}/… → bucket list, empty listing GET /{bucket}?list-type=2&prefix={root}/…
ListMultipartUploads GET /?uploads → empty GET /{bucket}?uploads&prefix={root}/…
DeleteObjects (deletePath) lists nothing → no-op POST /{bucket}?delete

Design

The S3 device owns addressing. New constructor argument, mirroring the AWS SDK's force-path-style:

new S3($root, $key, $secret, $endpoint, $region, bucket: 'appwrite', pathStyle: null);

Inference when pathStyle is null:

Endpoint / bucket Addressing
no bucket virtual-hosted
host is a dotted domain equal to the bucket (files.example.com) virtual-hosted
host starts with {bucket}. (files.s3.us-east-1.amazonaws.com) virtual-hosted
last endpoint path segment is the bucket (http://minio:9000/files) virtual-hosted
anything else (http://minio:9000) path-style → bucket requests go to /{bucket}

getDevice() passes only bucket: (first segment of _APP_STORAGE_S3_BUCKET) and pathStyle: from the new _APP_STORAGE_S3_PATH_STYLE:

_APP_STORAGE_S3_PATH_STYLE pathStyle
enabled true
disabled false
empty (default) null (infer)

The root stays {bucket}/{root}, so persisted paths (file path, 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: deleting images no longer removes images-archive/… (already the case on AWS).
  • DeleteObjects keys are XML-escaped.
  • Objects the service keeps in a Quiet-mode DeleteObjects now raise RemoteException instead of reporting success.
  • x-amz-copy-source is /{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

  • A custom domain / CNAME endpoint that points at the bucket but whose host is not named after it is now inferred path-style. Set _APP_STORAGE_S3_PATH_STYLE=disabled.
  • Passing the bucket also turns on server-side CopyObject for custom endpoints (deployment duplicate copies). Objects over 5 GB use UploadPartCopy, which only happens if _APP_COMPUTE_SIZE_LIMIT is raised past 5 GB.

Tests

RED = run against main source with the new tests.

Test Covers On main
E2E testPathStyleListsTheBucket ListObjectsV2 on path-style RED: listFiles() → []
E2E testPathStyleListsUploads ListMultipartUploads on path-style RED: 0 uploads, expected 1
E2E testDeletePathStaysInsideItsRoot (virtual, path-style) deletePath(''), .. refusal RED (path-style): file survives deletePath(''); .. reaches the service
E2E testDeletePathKeepsSiblingsSharingItsName (virtual, path-style) directory semantics RED: images-archive/f.txt deleted
E2E testPathStyleCopyRunsServerSide copy source on path-style RED: NoSuchKey (source /{b}/{b}/…)
E2E testVirtualHostedLegacyRootCopiesTheRealKey copy source on virtual-hosted green (guard)
E2E testLegacyBucketInRootObjectsResolveUnderPathStyle existing {bucket}/{root} objects RED: listFiles() → []
unit testVirtualHostedSubclassesKeepTheirRequestUris ×6 built-in provider subclasses keep their request URIs green (guard)
unit testAddressingFollowsTheEndpoint inference table + explicit pathStyle RED: / instead of /{bucket}
unit testAddressingRefusesWhatItCannotAddress slash in bucket, path-style without bucket RED
unit testDeletePathReportsObjectsTheServiceKept Quiet-mode errors RED: returned true
tests/unit/Deployment/StorageTest (testPathStyleDeviceKnowsItsBucket, testPathStyleSettingReachesTheDevice, testBucketHoldingSlashesKeepsItsRoot) getDevice() wiring RED

Package 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

  • The e2e "S3 Storage" lane now gets path-style through getDevice() (endpoint http://minio:9000, bucket appwrite → /appwrite), but none of its tests assert a bucket-level operation.
  • Overlaps fix: delete a project's storage objects on S3 #14626 in S3.php (same prefix() / $pathStyle names); whichever lands second rebases.

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.
@luxor-code-review

luxor-code-review Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


The change introduces a new _APP_STORAGE_S3_PATH_STYLE environment variable that controls how the S3 device builds request URLs, threading it from .env and docker-compose.yml through app/config/variables.php into app/init/resources.php device registration, with the console docs and compose generator updated to match.

Files Change
packages/storage/src/Device/S3.php Refactors bucket/prefix separation, URL addressing (path-style vs virtual-hosted), and delete/list semantics for the S3 device.
app/init/resources.php, app/config/variables.php, .env, docker-compose.yml Registers the new S3 path-style device option and propagates the _APP_STORAGE_S3_PATH_STYLE variable through service containers and variable docs.
apps/console/.../composeData.ts, .../environment-variables/index.markdoc Adds the new variable to the console compose generator and self-hosting configuration docs.
packages/storage/tests/Device/S3Test.php, packages/storage/tests/E2E/S3Test.php, tests/unit/Deployment/StorageTest.php Adds unit and e2e coverage for path-style addressing and updated device behavior, plus deployment storage test adjustments.

Reviewed commit: b7a7748

@appwrite

appwrite Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

New Console

Project ID: new-console

Sites (1)
Site Status Logs Preview QR
 New Console
new-console
Ready Ready View Logs Preview URL QR Code

Tip

JWT tokens let functions act on behalf of users while preserving their permissions

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 18, 2026
@ghost

ghost commented Oct 18, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The incremental normalization preserves the prior slash-collapsing behavior and the new tests cover both addressing modes.

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.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 11
File Change
.env Adds the S3 path-style environment variable.
app/config/variables.php Registers and describes the S3 path-style setting.
app/init/resources.php Passes the bucket and configured addressing mode to custom-endpoint S3 devices.
apps/console/src/content/docs/advanced/self-hosting/configuration/environment-variables/index.markdoc Documents S3 addressing configuration for self-hosted deployments.
apps/console/src/lib/docs/compose-generator/composeData.ts Includes the new setting in generated compose environment lists.
docker-compose.yml Passes the S3 path-style setting through to storage services.
packages/storage/README.md Documents endpoint inference and bucket-level S3 behavior.
packages/storage/src/Device/S3.php Adds bucket-aware addressing, path-style inference, safer prefix handling, and S3 copy/delete behavior.
packages/storage/tests/Device/S3Test.php Covers addressing, bucket operations, partial deletes, and repeated-slash normalization.
packages/storage/tests/E2E/S3Test.php Covers path-style operations and legacy bucket-root paths against an S3-compatible service.
tests/unit/Deployment/StorageTest.php Covers S3 device configuration wiring and bucket path handling.

Reviewed the commits since b7a7748 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@pkg-pr-new

pkg-pr-new Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/appwrite/appwrite/@appwrite.io/console@14628

commit: 100e7ff

@ghost ghost 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.

🔵 Tier A · Looks good to merge. Summary

Comment thread packages/storage/src/Device/S3.php Resolved
@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

19 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (12)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

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.
@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/s3-path-style (after).

Metric Before After Change
🚀 Requests/sec 209.42 213.31 ⚪ +1.9%
⏱️ Latency P50 80.48 ms 80.36 ms ⚪ -0.2%
⏱️ Latency P95 190.43 ms 191.61 ms ⚪ +0.6%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 80.36 191.61 13,623 213.31 +1.18
Account 160.23 303.1 717 11.93 +26.87
TablesDB 76.94 140.83 7,409 119.29 -24.38
Storage 75.55 166.26 3,585 59.32 -4.27
Functions 122.26 232.58 1,912 32.33 +34.01

Top API waits (after)

API request Max wait (ms)
functions.create 564.31
account.name.update 496.26
account.prefs.update 410.24
storage.buckets.create 404.09
functions.variables.create 373.85

@ghost ghost 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.

🟢 Tier S · Looks good to merge. Summary

@ChiragAgg5k
ChiragAgg5k merged commit bdff2b9 into main Oct 18, 2026
76 checks passed
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