Repository navigation
fix(s3): bound multipart parts, reclaim expired staging, honour bucket antivirus - #14796
Conversation
…t antivirus Multipart parts were written to the device before any size check, so only completion compared the total against the bucket's maximum file size. Each part now checks itself and the running total, and part numbers are limited to the S3 range of 1 to 10000. Expired uploads only had their index entry dropped, leaving staged chunks on the device. Listing and creating uploads now abort the staging of expired uploads unless it already backs a committed object. The gateway does not scan objects, so writes to buckets the REST upload would scan are refused instead of silently skipping the bucket's antivirus setting. Listings keep the oldest file per key instead of failing the whole bucket when two files share a name.
|
Review complete. 🟡 2 medium 💬 Inline comments (2)
🧹 Nitpicks (1) — 🟢 1 low
This PR hardens the S3 storage-proxy gateway: it enforces the 1–10000 part-number range and bucket
Reviewed commit: a315a1b |
🟢 Tier S · Ready to mergeThis PR adds multipart part-number and aggregate-size limits, reclaims expired multipart staging, applies antivirus checks to S3 writes, and deduplicates duplicate object keys in listings. It also expands the S3 E2E coverage for these behaviors and configures test buckets with antivirus disabled by default.
📂 Walkthrough · 4
🔇 Filtered out · 2Findings Hansi considered but did not post.
Reviewed |
There was a problem hiding this comment.
Adds multipart part/size limits, duplicate-key listing tolerance, antivirus gating, and lazy expiry of abandoned multipart uploads in the S3 storage proxy, with e2e coverage.
Key findings
- 🟡
findObjectrejects keys listings now tolerate — Get.php:84 - 🟡 Expiry abort skips multipart/object locks — Base.php:1030
…xpiry Single-object reads now agree with listings instead of failing on names REST allows to repeat. Expiry takes the object lock that completion commits under, re-checks the state there, and matches committed objects by staging path, so neither a racing completion nor a duplicate name can make it drop or keep the wrong staging.
Devices keep the bytes first staged for a part number, so accepting new content would record its size and ETag against the old bytes. Retries with identical content still succeed.
… expired mid-write The ETag is MD5, so it cannot prove a retry matches the staged bytes. A part that finishes after expiry purged its upload now fails instead of resurrecting state for aborted staging.
The findings that requested changes are resolved. See the summary comment for what is still open.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
|
@hansi-codes review |
…xpiry off live parts The antivirus gate refused every write to a scanned local bucket, while the REST upload skips scanning above APP_LIMIT_ANTIVIRUS. The gateway now refuses only writes at or under that limit, checked where the final size is known: a single PUT or copy, and multipart completion. Expiry took only the object lock, so it could abort staging while a part was still being written under the multipart lock. It now holds the multipart lock around the object lock. It also keeps the upload state when the device abort fails, so the next listing retries instead of losing the path; a NotFound abort means nothing was staged and still purges.
|
@hansi-codes review |
fix(s3): bound multipart parts, reclaim expired staging, honour bucket antivirus (cherry picked from commit 00837ff)
What does this PR do?
Hardens the S3-compatible gateway around multipart limits, staging cleanup, duplicate names and the bucket antivirus setting.
Multipart limits
UploadPartnow checks the part number against the S3 range (1 to 10000) and checks the part size and the running total of the upload's other parts against the bucket'smaximumFileSizebefore writing to the device. Before this, onlyCompleteMultipartUploadchecked the total, after every part was already staged. Re-uploading a part number replaces its earlier size instead of adding to it.Expired staging
getMultipartUploads()now aborts the device staging of an expired upload and then purges it. The cached state outlivesMULTIPART_TTLuntil it is purged, so it is read back with a long retention to find the path and the device upload ID. Staging that already backs a committed object is left in place. Abort failures are logged and don't fail the request.CreateMultipartUploadruns the same sweep for its bucket, so expired staging is reclaimed even when nobody lists uploads.Antivirus
_APP_STORAGE_ANTIVIRUS=enabled, bucketantiviruson, and a Local device. Before, the gateway wrote to those buckets without scanning. The condition matches the REST path, so non-Local devices and deployments with antivirus off behave as before. Reads are unchanged. Buckets created through S3 keepantivirus: false, since enabling it would make them unwritable through the gateway.Duplicate names
$sequenceordering. Single-object operations on an ambiguous key still return 400 for that key only.Also replaced an inline
\Utopia\System\Systemwith an import.Test Plan
New E2E tests in
tests/e2e/Services/Storage/S3CustomServerTest.php:testUploadPartLimits(also in thes3group so it runs against MinIO): with a 1 KiB bucket, a 1025-byte part, a second part that pushes the total past the limit, and part numbers 0 and 10001 return 400. Re-uploading part 1 succeeds, and the upload still completes and reads back.testListObjectsWithDuplicateNames: two REST files with the same name plus one other. Both V1 and V2 listings return 200 with each key once.testWriteAntivirusBucket: on an antivirus-enabled bucket, PutObject and CreateMultipartUpload return 400 when antivirus is enabled on a Local device (the antivirus CI lane), and 200 otherwise.setupBucket()now creates buckets withantivirus: false, so the existing S3 tests also run in the antivirus lane.The expired-staging sweep has no E2E test: forcing expiry means waiting 24 hours or rewriting the cache envelope's timestamp in Redis, which ties the test to the cache encoding.
Pint, PHPStan (host,
phpstan.neon) and Rector pass on touched files. E2E is left to the CI lanes; I didn't bring up a local stack.Related PRs and Issues
None.
Related: appwrite-labs/cloud#6628