Skip to content

🐛 Bug Report: Deleting a storage bucket leaves its files on S3-compatible storage #13808

Closed

Description

@jbdujardin

👟 Reproduction steps

  1. Run a self-hosted Appwrite 2.2.0 with S3-compatible storage:

    _APP_STORAGE_DEVICE=s3
    _APP_STORAGE_S3_ENDPOINT=nbg1.your-objectstorage.com
    _APP_STORAGE_S3_REGION=nbg1
    _APP_STORAGE_S3_BUCKET=my-bucket
    _APP_STORAGE_S3_ACCESS_KEY=...
    _APP_STORAGE_S3_SECRET=...
    
  2. Create a storage bucket and upload a file. The object shows up in my-bucket as storage/uploads/app-<projectId>/<bucketId>/<fileId>.<ext>.

  3. Delete the storage bucket, from the Console or with DELETE /v1/storage/buckets/{bucketId} (returns 204).

  4. The deletes worker finishes without any error, but every object under storage/uploads/app-<projectId>/<bucketId>/ is still in my-bucket.

👍 Expected behavior

Deleting a storage bucket should delete its files from the S3 bucket.

👎 Actual Behavior

Nothing is deleted on the S3 side, and nothing is logged.

When _APP_STORAGE_S3_ENDPOINT is set, getDevice() puts the bucket name at the start of the root path and gives the bare endpoint as host (app/init/resources.php#L367-L369):

$bucketRoot = (! empty($bucket) ? "{$bucket}/" : '') . \ltrim($root, '/');
return new S3($bucketRoot, $accessKey, $accessSecret, $endpoint, $region);

Single-object requests work because the key starts with the bucket (/my-bucket/storage/..., path-style). Uploads, chunked uploads, downloads, previews and single file deletions are all fine.

Bucket deletion calls $deviceForFiles->deletePath($bucketId) (Deletes.php#L1770-L1777). In utopia-php/storage, listObjects() always sends GET / with the whole root as prefix (S3.php#L374-L399):

GET https://nbg1.your-objectstorage.com/?list-type=2&prefix=my-bucket/storage/uploads/app-<projectId>/<bucketId>

With no bucket in the path, this is a ListBuckets request. The provider answers with ListAllMyBucketsResult, which has no Contents, so deletePath() leaves its loop and returns true (S3.php#L490-L527). The batch POST /?delete it would send next has the same problem.

I reproduced it on Hetzner Object Storage: the request above returns the bucket list, and the same query sent to /my-bucket with prefix=storage/uploads/... returns the files. It should be the same with any provider used through _APP_STORAGE_S3_ENDPOINT, since GET / on the service endpoint means ListBuckets in the S3 API. The code is unchanged in utopia-php/storage 4.2.0.

Related, from reading the code (not reproduced): project deletion calls delete($device->getRoot(), true) on the files, sites, functions, builds and cache devices (Deletes.php#L995-L1019), but S3::delete() ignores $recursive and sends a single DELETE on the directory key (S3.php#L358-L365). AWS extends S3 without overriding it, so a deleted project's files would stay on any S3 device, AWS included.

A possible fix: give the bucket to the S3 device (the constructor already has a bucket argument) and send listObjects() and the batch delete to /{bucket} with a prefix relative to it. And make delete($path, true) go through deletePath().

🎲 Appwrite version

2.2.0 (self-hosted)

💻 Operating system

Linux

🧱 Your Environment

Appwrite 2.2.0 self-hosted, installed with the official installer (default Docker Compose layout, PostgreSQL). utopia-php/storage 4.1.0 as bundled. Ubuntu 26.04. Storage on Hetzner Object Storage (nbg1), configured as shown in the reproduction steps. Nothing else customized.

Activity

  1. added
    product / databases
    product / functions
    product / messaging
    product / self-hosted
    product / sites
    product / storage
    on Sep 21, 2026
  2. HarshMN2345 commented on Oct 29, 2026

    @HarshMN2345
    Member

    Fixed in #14626: deleting a bucket on S3-compatible storage now removes all of its objects. Thanks for reporting it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    product / databasesproduct / functionsproduct / messagingproduct / self-hostedproduct / sitesproduct / storage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions