Skip to content

S3: DeleteBucket leaves every bucket sub-resource behind, so a recreated bucket inherits the deleted one's configuration #508

Closed

Description

@scttfrdmn

Summary

DeleteBucket removes only the bucket:<name> state entry. Every bucket sub-resource
substrate stores under its own key survives, so creating a bucket, configuring it,
deleting it and creating it again yields a bucket that reports the deleted bucket's
configuration.

Found while implementing #470, which made CreateBucket write bucket_acl:<bucket> —
and therefore made the create authoritative for that one key, since a create that names
no ACL now clears any entry left behind. The other sub-resources have no such clear.

The surviving keys

deleteBucket (emulator/s3_plugin.go) deletes bucket:<name> and nothing else. These
keys are all bucket-scoped and all outlive it:

Key Written by Observable through
bucket_policy:<bucket> PutBucketPolicy GetBucketPolicy
public_access_block:<bucket> PutPublicAccessBlock GetPublicAccessBlock, and enforced on PutObject/PutBucketAcl/PutObjectAcl/PutBucketPolicy
bucket_tagging:<bucket> PutBucketTagging GetBucketTagging
bucket_versioning:<bucket> PutBucketVersioning GetBucketVersioning, and changes the write path
bucket_notification:<bucket> PutBucketNotificationConfiguration GetBucketNotificationConfiguration, and dispatches on write
bucket_lifecycle:<bucket> PutBucketLifecycleConfiguration GetBucketLifecycleConfiguration

(bucket_acl:<bucket> is no longer on this list as of #470.)

Why it matters more than a leak

Three of these change behaviour rather than just a GET response:

  • A recreated bucket inherits the deleted bucket's Block Public Access configuration,
    so a PutObject --acl public-read that should succeed against a fresh bucket is
    refused with 403 AccessDenied. That is substrate refusing what real AWS accepts —
    the defect shape the tracker keeps returning to, here caused by leftover state rather
    than by a missing model.
  • A recreated bucket inherits versioning, so a PutObject writes a versioned object
    and returns an x-amz-version-id the consumer never enabled versioning for.
  • A recreated bucket inherits notification configurations, so a write fires a
    notification to a queue or function the new bucket was never wired to.

The natural shape of a fixture makes this easy to hit: a test that tears down and
recreates a bucket between cases is the common case, not an exotic one.

What real S3 does

A bucket is a namespace, and every sub-resource is scoped to it. A deleted bucket's
configuration does not survive — a recreated bucket of the same name starts with no
policy, no BPA configuration, no tagging, no versioning, no notifications and no
lifecycle rules. Object ACLs and the objects themselves cannot survive either, since
DeleteBucket requires the bucket be empty.

Acceptance criteria

  • DeleteBucket clears every bucket-scoped key listed above.
  • Recreate-after-delete: create → configure (each of the six) → delete → create →
    each GET reports the unconfigured default.
  • The BPA case asserted through behaviour, not just through
    GetPublicAccessBlock: PutObject --acl public-read against the recreated bucket
    succeeds.
  • The versioning case asserted through behaviour: a PutObject against the recreated
    bucket returns no x-amz-version-id.
  • Decide and record whether the deletes are best-effort (_ = p.state.Delete(...),
    matching deleteObject's existing style) or must be propagated — a partial delete
    that leaves one key behind is the bug this issue is about, so silence is a
    questionable default here.
  • emulator/s3_plugin.go's s3CreateBucketACL doc comment updated: it currently
    cites this issue as the reason the other sub-resources still leak.

Activity

  1. added
    type: bug
    area: s3
    on Aug 2, 2026
  2. added this to the v0.89.0 milestone on Aug 3, 2026
  3. scttfrdmn commented on Aug 3, 2026

    @scttfrdmn
    OwnerAuthor

    Milestoned to v0.89.0, deliberately alongside #518 (CloudFormation DeleteStack does not delete the stack's resources) rather than on its own.

    Why they are paired. #518 adds a delete dispatcher that will call DeleteBucket for every AWS::S3::Bucket in a stack. Whatever this issue leaves behind, that sweep inherits — and it inherits it in the shape that hurts most: a consumer's test deletes a stack, redeploys it with the same bucket name, and the "new" bucket silently arrives carrying the deleted stack's versioning, lifecycle, policy, CORS and encryption configuration. That is the same defect class as the rest of the v0.87.x CloudFormation work — a caller's observation is wrong while every call returns success — and it is much easier to hit through a stack lifecycle than through a hand-written DeleteBucket.

    Fixing the sweep first would just make this leak reachable from a new path, so the ordering is: this, then the sweep.

    No change to the issue's own analysis. Filing this comment so the pairing is recorded rather than being a coincidence of milestone.

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

    area: s3type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions