Skip to content

Support a batched / recursive prefix-delete operation #173

Open

Description

@alukach

Summary

The proxy forwards per-object DELETE /{bucket}/{key} but does not
implement S3's multi-object delete (POST /{bucket}?delete, the DeleteObjects
verb). Requests to it 404 with NoSuchBucket: <account_id> because the proxy
routes by object key and has no bucket-root handler.

This forces clients that need to delete many objects (e.g. an entire prefix) to
issue one DELETE per key. For large stores — a Zarr dataset can have thousands
to millions of chunks — that is thousands of round-trips and a lot of proxy load.

Context: source.coop PR source-cooperative/source.coop#403 added a file-explorer
"delete prefix" button; it currently lists the prefix and deletes each key
individually (concurrency 8) as a workaround. Correct, but slow at scale.

What we'd like

A way to delete many objects in one request. Two shapes, in preference order:

  1. Scoped recursive prefix-delete (preferred for our use case): a single
    request "delete everything under prefix P". The proxy authorizes the prefix
    once against the caller's scope, then lists + deletes server-side.
    • Pros: one authz check; works uniformly across S3/GCS/Azure backends;
      collapses N requests → 1 for the client.
  2. Standard S3 DeleteObjects passthrough: implement the bucket-root
    ?delete endpoint so standard S3 tooling (rclone, boto3, aws-cli bulk delete)
    works against the proxy.
    • Pros: S3-tool compatibility — a reason that stands on its own, independent
      of our delete button.

Known complexity (why this isn't a trivial passthrough)

  • Per-key authorization. The proxy is the per-object authz enforcement
    point. DeleteObjects bundles up to 1000 arbitrary keys in the request
    body (not the URL path). To be safe the proxy must parse the body and
    authorize every key against the caller's scope, returning per-key errors —
    otherwise one request could mix keys across products/accounts. This is the main
    cost and likely why no handler exists today. (A scoped prefix-delete avoids
    this: one prefix check.)
  • Backend heterogeneity. Only S3 has a native ~1000-key batch delete. GCS and
    Azure Blob have different/limited batch primitives, so for those backends the
    proxy would fan out to per-object deletes server-side anyway — the batch
    speedup is fully realized only for S3-backed connections.
  • Response semantics. DeleteObjects returns 200 with a per-key result body
    (including partial failures) and honors Quiet mode; the proxy must construct
    that correctly.
  • Read-only / unowned connections must continue to be rejected (we don't own
    that data).

Suggested scope

If the goal is just to speed up our own prefix deletes, option (1) is simpler and
safer. Implement option (2) only if S3-tool compatibility is independently
wanted. Either way, per-key/per-prefix authorization is non-negotiable.

Workaround in place

source.coop deletes prefixes per-object client-side today (PR
source-cooperative/source.coop#403, S3UploadService.deletePrefix). No action is
blocked; this issue is about performance at scale.

Activity

  1. added
    enhancement
    on Jun 30, 2026
  2. nlebovits commented on Nov 27, 2026

    @nlebovits

    A reprex for the DeleteObjects part of this issue, plus two findings that #173 does not record.

    Findings

    1. DeleteObjects works when the repository is the bucket and the account is in the endpoint path (https://data.source.coop/{account}, bucket {repo}). It fails only when the account is the bucket. Every other verb that we tried works with the account as the bucket.
    2. The failure returns 404 NoSuchBucket. S3 clients read a 404 on a delete as "the object is already gone". obstore / Rust object_store sends every delete as DeleteObjects, also a delete of one key. So with the account as the bucket, an obstore delete raises FileNotFoundError and the object stays. A client that ignores a not-found error on delete (a common pattern) then reports a successful delete.

    We found this in Portolan (portolan-sdi/portolan-cli#1205). A catalog writer "deleted" a collection that stayed in the bucket. portolan push also leaves backup objects behind that it cannot delete.

    Reprex

    boto3 1.42.84, profile with credential_process = source-coop creds:

    import uuid, boto3, botocore
    
    ACCOUNT, REPO = "<account>", "<repo>"
    sess = boto3.Session(profile_name="source-coop-proxy")
    acct = sess.client("s3", endpoint_url="https://data.source.coop")
    repo = sess.client("s3", endpoint_url=f"https://data.source.coop/{ACCOUNT}")
    p = f"reprex-{uuid.uuid4().hex[:8]}"
    
    
    def run(label, fn):
        try:
            r = fn()
            print(f"{label}: OK", r["ResponseMetadata"]["HTTPStatusCode"])
        except botocore.exceptions.ClientError as e:
            err = e.response["Error"]
            print(f"{label}: {e.response['ResponseMetadata']['HTTPStatusCode']} {err['Code']}: {err['Message']}")
    
    
    for k in ("a", "b", "c"):
        acct.put_object(Bucket=ACCOUNT, Key=f"{REPO}/{p}/{k}.json", Body=b"{}")
    
    run("1 PutObject      Bucket=account", lambda: acct.put_object(Bucket=ACCOUNT, Key=f"{REPO}/{p}/a.json", Body=b"{}"))
    run("2 ListObjectsV2  Bucket=account", lambda: acct.list_objects_v2(Bucket=ACCOUNT, Prefix=f"{REPO}/{p}/"))
    run("3 DeleteObject   Bucket=account", lambda: acct.delete_object(Bucket=ACCOUNT, Key=f"{REPO}/{p}/a.json"))
    run("4 DeleteObjects  Bucket=account", lambda: acct.delete_objects(
        Bucket=ACCOUNT, Delete={"Objects": [{"Key": f"{REPO}/{p}/b.json"}]}))
    run("5 DeleteObjects  Bucket=repo, endpoint=/account", lambda: repo.delete_objects(
        Bucket=REPO, Delete={"Objects": [{"Key": f"{p}/c.json"}]}))
    
    left = [o["Key"] for o in acct.list_objects_v2(Bucket=ACCOUNT, Prefix=f"{REPO}/{p}/").get("Contents", [])]
    print("left:", [k.rsplit("/", 1)[1] for k in left])
    for k in left:
        acct.delete_object(Bucket=ACCOUNT, Key=k)

    Output on 2026-11-27:

    1 PutObject      Bucket=account: OK 200
    2 ListObjectsV2  Bucket=account: OK 200
    3 DeleteObject   Bucket=account: OK 204
    4 DeleteObjects  Bucket=account: 404 NoSuchBucket: bucket not found: <account>
    5 DeleteObjects  Bucket=repo, endpoint=/account: OK 200
    left: ['b.json']
    

    Step 4 is the failure. b.json is still there after a delete that some clients treat as a success.

    Requests

    1. Accept POST /{account}?delete and route each key by its first segment, the same way DeleteObject is routed. Steps 3 and 5 suggest the routing already exists.
    2. Until then, answer POST /{account}?delete with 501 NotImplemented, not 404 NoSuchBucket. A 501 makes the delete fail loudly in obstore, boto3, and rclone. A 404 lets it look like a success.
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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions