Skip to content

S3: ?publicAccessBlock is unrouted; PUT hits CreateBucket and DELETE deletes the bucket #446

Closed

Description

@scttfrdmn

?publicAccessBlock appears to be unrouted, so requests fall through to the bucket-level handler that shares the method. PUT reaches CreateBucket and DELETE reaches DeleteBucket — the latter destroys the bucket.

Substrate 0.82.0, ghcr.io/scttfrdmn/substrate:0.82.0, boto3/botocore from a normal pip resolution, region us-west-2.

PutPublicAccessBlock → CreateBucket

b = "pab-probe"
s3.create_bucket(Bucket=b, CreateBucketConfiguration={"LocationConstraint": "us-west-2"})
s3.put_public_access_block(
    Bucket=b,
    PublicAccessBlockConfiguration={
        "BlockPublicAcls": True, "IgnorePublicAcls": True,
        "BlockPublicPolicy": True, "RestrictPublicBuckets": True,
    },
)
botocore.errorfactory.BucketAlreadyExists: An error occurred (BucketAlreadyExists) when
calling the PutPublicAccessBlock operation: The requested bucket name is not available.

The wire request is well-formed and carries the subresource:

PUT http://localhost:4566/pab-probe?publicAccessBlock
<PublicAccessBlockConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
  <BlockPublicAcls>true</BlockPublicAcls>...

BucketAlreadyExists for a PUT on a bucket that does exist is CreateBucket's answer, so the query string is being ignored and the request dispatched on PUT /{bucket} alone. Real S3 returns 200 here.

DeletePublicAccessBlock → DeleteBucket (destroys the bucket)

Worse, because the same fall-through on DELETE reaches DeleteBucket. On an empty bucket:

s3.create_bucket(Bucket=b, CreateBucketConfiguration={"LocationConstraint": "us-west-2"})
s3.delete_public_access_block(Bucket=b)          # returns 204
b in [x["Name"] for x in s3.list_buckets()["Buckets"]]   # False -- the bucket is gone

and the tell on a non-empty one:

s3.put_object(Bucket=b, Key="important.txt", Body=b"...")
s3.delete_public_access_block(Bucket=b)
botocore.exceptions.ClientError: An error occurred (BucketNotEmpty) when calling the
DeletePublicAccessBlock operation: The bucket you tried to delete is not empty.

BucketNotEmpty is only reachable from DeleteBucket, and the error message names the operation the caller did not make. Against real S3 DeletePublicAccessBlock is 204 and the bucket is untouched either way. A caller that relaxes a public-access block on an empty bucket loses the bucket, and one that does it on a populated bucket gets an error about an operation it never issued.

GET is routed, so the pair is asymmetric

get_public_access_block returns 200 with an empty PublicAccessBlockConfiguration, which suggests the subresource is recognized on GET and only the PUT/DELETE paths are missing. So the configuration also cannot round-trip: nothing can be written for GET to return.

Operation substrate real S3
GET ?publicAccessBlock 200, empty config 200 config, or NoSuchPublicAccessBlockConfiguration
PUT ?publicAccessBlock 409 BucketAlreadyExists (CreateBucket) 200
DELETE ?publicAccessBlock 204 and the bucket is deleted (DeleteBucket) 204, bucket untouched

Why it matters here

parsl-ephemeral-aws calls put_public_access_block immediately after creating a bucket it owns — it is how the provider keeps a state bucket private, replacing the deprecated ACL="private". The PUT failing makes bucket creation raise, so S3State(create_bucket_if_not_exists=True) cannot be exercised against the emulator at all; the surrounding except turns it into StateError: Failed to create S3 bucket: ... BucketAlreadyExists, which points at the wrong operation and sent me looking for a name collision that wasn't there.

Blocking public access is a standard step after CreateBucket for anything not meant to be world-readable, so I'd expect other clients to hit the PUT. The DELETE is the one worth prioritising: silent bucket deletion is a data-loss shape rather than a fidelity gap, and a test suite that tidies up by relaxing a block would take the bucket with it.

Happy to test a patch.

Activity

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

    @scttfrdmn
    OwnerAuthor

    Reproduced, fixed, and out for review in #459 — thanks for the detail, and particularly
    for the two separate DELETE reproductions. The empty-vs-non-empty split is what made the
    severity obvious.

    Confirmed, and it's worse than a fidelity gap

    All three verbs were unrouted. Because ?publicAccessBlock is addressed as a bare query
    key on the bucket itself, each request fell through to whatever bucket-level operation
    owns that method:

    Request Reached Returned
    DELETE /bucket?publicAccessBlock DeleteBucket 204 — and the bucket was gone
    PUT /bucket?publicAccessBlock CreateBucket 409 BucketAlreadyExists
    GET /bucket?publicAccessBlock ListObjects 200 + a ListBucketResult body

    Your read on the DELETE is right and it's the reason this jumped the queue over the other
    open items: on an empty bucket it returns 204, which is exactly what a successful
    DeletePublicAccessBlock returns. There is no signal at all. The bucket is gone and the
    caller finds out at the next operation, as an unexplained NoSuchBucket somewhere else
    entirely.

    One correction to the report

    You wrote that GET is routed and returns an empty configuration. It isn't routed — it
    fell through to ListObjects. What you observed was your SDK parsing a
    ListBucketResult body into an empty PublicAccessBlockConfiguration, because none of
    the four elements it looks for are present.

    Worth flagging because it changes what the bug was: not "substrate forgot to store your
    settings", but "substrate answered a question you didn't ask and the shapes were close
    enough to parse". That reads as "public access is not blocked" — a confident wrong
    answer rather than a missing one, and the harder kind to notice.

    What #459 does

    PUT    /bucket?publicAccessBlock  → 200, empty body
    GET    /bucket?publicAccessBlock  → 200 + PublicAccessBlockConfiguration, or 404
    DELETE /bucket?publicAccessBlock  → 204
    
    • PUT replaces the configuration wholesale rather than merging. The four settings are
      each Required: No, and every one your body omits is recorded — and reported back — as
      false, matching S3.
    • DELETE is idempotent and touches nothing but the configuration. It is now
      structurally incapable of touching the bucket: the configuration lives under its own
      state key, so the delete is a delete, not a rewrite of the bucket record.

    The one decision worth your attention: GET on an unconfigured bucket is a 404

    GetPublicAccessBlock returns 404 NoSuchPublicAccessBlockConfiguration for a bucket
    that has never been the subject of a PutPublicAccessBlock.

    This took some digging, because it is not answerable from the S3 API reference — the code
    is absent from the S3 2006-03-01 model, and the bucket-level GetPublicAccessBlock page
    has no Errors section at all. Rather than guess, it was corroborated three ways:
    terraform-provider-aws handles this exact code in its bucket-level internal/service/s3
    package (on both Get and Delete — the Delete handling is why idempotence is right), the
    s3control model's shape documentation describes the same condition, and boto3 #3627 has
    the live message string verbatim.

    What this means for your code: a bucket you have just created, before your
    put_public_access_block call, will 404 rather than return four falses. An all-false
    configuration you wrote deliberately is still a 200 with four false elements — the
    two states stay distinguishable, which is the point.

    Related: substrate deliberately does not apply S3's April 2023 default of enabling all
    four settings on newly created buckets. That default is real (and does cover buckets made
    via the API/SDKs/CloudFormation), but it comes from AWS-managed account and organization
    state substrate doesn't model — and seeding every new bucket with a configuration would
    make the NoSuchPublicAccessBlockConfiguration path unreachable through the public API,
    which would leave your error branch untestable. Your put_public_access_block call
    straight after create_bucket gets you a configured bucket, so this shouldn't affect your
    flow.

    One thing that is still missing, on purpose

    The settings are recorded, not enforced. Nothing yet rejects a public ACL on a bucket
    with BlockPublicAcls set, or a public bucket policy under BlockPublicPolicy. If you
    have a test asserting that your hardening actually refuses a public ACL, it will still
    pass for the wrong reason. Filed separately as #458, which also argues why
    RestrictPublicBuckets and IgnorePublicAcls should stay recorded-only until substrate
    models anonymous access evaluation at all.

    Your offer to test a patch

    Taking you up on it. The branch is fix/446-s3-public-access-block (#459), and the two
    things most worth a run against your actual code are the 404-when-unset contract above
    and whether your teardown path relies on DELETE being idempotent — it is, but I'd rather
    you confirm than infer. It'll be in the next release either way.

    Targeted at the v0.85.0 milestone.

  4. added a commit that references this issue on Oct 3, 2026
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: s3priority: hightype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions