Repository navigation
fix(s3): DeleteBucket clears the bucket's namespace (#508) - #543
Merged
Merged
Conversation
A bucket-scoped configuration is keyed by bucket name alone, so all six outlived their bucket and were inherited by the next bucket of that name. DeleteBucket now clears them, plus the object-scoped keys that outlive the object they describe, and aborts in-flight multipart uploads. Errors propagate and the bucket: record goes last, so a failed clear leaves the bucket present and retryable. The emptiness check counted only live objects, so a bucket holding only a deleted object's history deleted successfully and stranded every version; it now counts object_version: too. Permanently deleting a version never updated the current-version pointer, which made a versioned bucket impossible to empty and so blocked the widened check outright. The promoted version's body moves with its record.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…#508) Every store or filesystem failure along the clear, and along the current-version promotion, must surface as a 500 with the bucket left in place. That is this PR's central design claim -- a partial clear reported as a 204 is precisely the bug being fixed -- but the error returns implementing it were untested, so a future `_ = state.Delete(...)` would have reintroduced the leak silently. Adds two seams the existing helpers could not provide: - `s3PrefixFaultState` fails one operation for every key under a prefix. `pabFaultState` targets a single exact key and passes `List` straight through, so it cannot reach the prefix scans or the keys whose names are generated at request time (upload IDs, version IDs). - `s3FaultFs` fails one filesystem operation. The object mirror is the other half of the plugin's state; a failure removing an upload's part bodies, or writing a promoted body, leaks exactly what a store failure leaks. One operation at a time, because the promotion does MkdirAll then WriteFile and failing both would only ever exercise the first. `newS3TestServerWithFS` now delegates to `newS3TestServerWithFaultFS` rather than constructing its own filesystem, so there is one setup path. Also pins three non-error outcomes the fault tests sit against, each the boundary that makes the corresponding 500 meaningful: an absent bucket is a 404 and not a 500; an upload record already gone is nothing to abort rather than a wedge; and a surviving version whose record is unreadable leaves no `object:` pointer, rather than one aimed at something a GET cannot read. The explicit `AbortMultipartUpload` gets the same assertion, since it shares `abortUploadState` with `DeleteBucket`. Ten mutants applied against the propagation claim -- each error return swallowed in turn, the bucket lookup's failure reported as `NoSuchBucket`, an unreadable upload record skipped, and both directions of `promoteVersionBody`'s absent-body tolerance -- all ten caught. Every line this PR adds to s3_plugin.go is now covered.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #508.
DeleteBucketremovedbucket:<name>and nothing else. Since a bucket-scopedconfiguration is keyed by the bucket name alone, every one of them outlived its
bucket and was inherited by the next bucket created with that name — reproduced end
to end against a binary built from this branch's parent:
What is cleared
All six:
bucket_acl:,bucket_policy:,bucket_lifecycle:,bucket_versioning:,notification:,bucket_public_access_block:— held in ones3BucketSubresourcePrefixesslice, so adding a bucket-scoped configuration is achange to that slice rather than a seventh open-coded delete. The drift between one
cleared key and five uncleared ones is what this bug was.
Two corrections to the issue's table, both verified in the source rather than
assumed: the notification prefix is
notification:, notbucket_notification:; andbucket tagging never leaked, because
PutBucketTaggingwritesTagsinto thebucket:record rather than under a key of its own.Object-scoped leftovers go too. An object ACL and a version index are stored under
their own keys and outlive the object they describe, so an empty bucket could
still own state a recreated bucket inherited.
On the issue's open question — best-effort vs propagated: propagated. A partial
clear is precisely the bug being fixed, so
_ = state.Delete(...)would hide arecurrence. The
bucket:record is deleted last, so a failed clear leaves thebucket present and retryable rather than half-deleted, and
HeadBucketagrees withthe error instead of contradicting it.
The emptiness check was undercounting (not in the issue)
"All objects (including all object versions and delete markers) in the bucket must
be deleted before the bucket itself can be deleted", but the check listed only
object:<bucket>/. A bucket holding nothing but a deleted object's history deleted"successfully" and stranded every version. It now counts
object_version:as well,which covers noncurrent versions and delete markers alike.
The sharpest case is a versioning-suspended bucket: substrate's
DELETEremovesthe current-version pointer outright there, so the bucket looked empty while the
version it wrote was still present. Real S3 keeps that version too — "when you
suspend versioning, existing objects in your bucket do not change" — so it is not
empty either way.
Multipart: aborted, not refused — correcting my own plan
The plan said an in-flight upload should refuse the delete. The reference says
otherwise, and the reference wins: the refusal is documented for directory
buckets, which substrate does not model. For general purpose buckets the guidance
is only that "while emptying your bucket, we recommend that you also remove all
incomplete multipart uploads". An upload whose destination bucket is gone can never
be completed, so the delete aborts it — part records, upload record, and part bodies
— through the same helper
AbortMultipartUploadnow calls, so the two paths cannotleave different residue. Only uploads whose
Bucketfield names the bucket beingdeleted are touched: an upload is keyed by upload ID alone, so the scan sees every
bucket's.
A pre-existing defect that blocked this one outright
Permanently deleting a version by ID never updated the
object:current-versionpointer. A versioned bucket could therefore never be emptied — the key stayed
listed with a 200
GETafter its last version was gone — so the widened emptinesscheck above could never have been satisfied. Fixing #508 required fixing this.
promoteCurrentVersionpromotes the newest surviving version, since "if you deletethe current object version, … the version that is next in the version stack becomes
the current version", and removes the key entirely when none survives. The promoted
version's body moves with its record: a versioned
PUTwrites the body bothunder
.versions/<key>/<versionID>and at the unversioned path an unversionedGETreads, so promoting the record alone served the deleted version's bytes under the
promoted version's ETag.
Two subtleties, each pinned by a test because each was found by a surviving mutant:
a delete marker has no body to promote (an absent versioned body is not an error),
and the promotion honours #534's
s3ObjectHasBodyguard — afero reads a directoryas an empty body with no error, so an unguarded promote truncates the object at
dirto zero bytes while promoting a version of the markerdir/, and reportssuccess.
Tests
emulator/s3_delete_bucket_state_test.go, all failing before the change:ClearsBucketScopedConfigurationRecreatedBucketDoesNotInheritBPARecreatedBucketDoesNotInheritVersioningx-amz-version-idRefusesNoncurrentVersionsBucketNotEmptyAllVersionsRemovedIsEmptyDeleteBucketimpossible to satisfyAbortsInFlightMultipartUploadsAbortsOnlyThisBucketsUploadsClearsObjectScopedLeftoversVersionDeletePromotesPredecessorVersionDeletePromotesDeleteMarkerPromotingADirectoryMarkerTouchesNoBodyPromotingAMarkerDoesNotClobberItsSiblingdirkeeps its bodyErrorsPropagateHeadBucketstill 200Two test-design notes worth stating, since both were cases of a test passing for the
wrong reason:
bucket_acl:is also cleared byCreateBucket, so a read after the recreatepasses with no fix at all. Every sub-test therefore asserts on the state key
immediately after the delete, which is what attributes the clear to
DeleteBucket.way stores nothing: substrate unmarshals that XML by Go field name, so
<QueueConfiguration><Queue>never matches. There was no leak to observe. Filedas S3: PutBucketNotificationConfiguration parses XML by Go field name, so a real-S3 request body stores nothing and returns 200 #542; the test carries a comment pointing there and uses substrate's shape so
it fails for the right reason today.
Mutation testing
30 mutants across the clear list, the emptiness check, error propagation, delete
ordering, the multipart abort and the promotion. 27 applied and all CAUGHT, zero
survivors; 3 were stale duplicate anchors superseded by working forms in the same
run.
Five survived initially, and each was a genuine test-design gap rather than an
equivalence, so the tests were strengthened rather than the mutants excused:
object:only — no case reached "object:empty,versions remaining" until the suspended-versioning sub-case was added, which the
AWS reference confirmed is a real state rather than a substrate artefact;
path, which
promoteCurrentVersionnow tidies itself, so it needed the plaindelete that genuinely strands an
object_acl:key;upload.Bucket— no test had uploads in two buckets;content;
afero probe first (truncates the sibling at
dirto zero bytes, no error), thenpinned end to end.
Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...→ 0issues,
make test(race),make docs-reference docs-reference-check docs-versions(no diff — no plugin added),npm --prefix docs run build,go vet -C test/e2e ./...,go test -C test/e2e ./.... Plus the end-to-endsequences above against
substrate server: the recreated bucket reports theunconfigured default for versioning and BPA, a bucket holding only a delete marker
is refused and deletes once its versions are gone, an in-flight upload is aborted
rather than refused and is not resumable, and the promoted version serves
olderwhile the key stays listed.
Compatibility
No state-format change, so existing snapshots and recorded event logs replay
identically. Three behaviour changes a consumer may be asserting on:
DeleteBucketon a bucket holding noncurrent versions or delete markers nowreturns 409
BucketNotEmptywhere it returned 204. A test that deleted such abucket successfully was relying on the leak.
that leaned on the inheritance — deliberately or not — will see defaults.
GETandListObjectsV2report for that key, which is what real S3 does.