fix(s3): apply and validate Tags from CreateBucket request body#1103
Merged
Nahuel990 merged 2 commits intoJul 18, 2026
Conversation
CreateBucket accepts a <Tags> container in its request body (API_CreateBucket_RequestBody), but _create_bucket parsed only LocationConstraint and silently dropped any tags. A follow-up GetBucketTagging then returned NoSuchTagSet, and S3 Control ListTagsForResource returned an empty list, instead of the tags supplied at creation time. Parse the <Tag> set at creation time and store it in _bucket_tags so both GetBucketTagging and S3 Control ListTagsForResource return it. Validate the tag set against the S3 constraints, with codes, HTTP statuses and messages verified against real AWS S3: - key length 1-128, value length 0-256 (empty value allowed) -> InvalidTag/400 - reserved "aws:" key prefix -> InvalidTag/400 - more than 50 tags -> BadRequest/400 - duplicate keys -> InternalError/500 (matches real AWS on this path) Invalid tags are rejected before the bucket is created, so no partial state is left behind. Parsing is factored into a shared _iter_tag_pairs; the lenient _parse_tags_xml (last-writer-wins) is unchanged and still used by the Put(Bucket|Object)Tagging handlers.
|
Docker image for this PR has been published: |
nirajsapkota
commented
Jul 17, 2026
| return tags | ||
| yield key_text, val_text or "" | ||
|
|
||
| def _parse_tags_xml(body: bytes) -> dict: |
Contributor
Author
There was a problem hiding this comment.
As mentioned in the PR description, I've left paths outside of _create_bucket unchanged to limit the scope of this pull-request so preserving the last-tag wins parsing in this method.
|
Docker image for this PR has been published: |
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.
Summary
CreateBucketaccepts a<Tags>container in its request body, but_create_bucketparsed onlyLocationConstraintand silently dropped anytags. As a result a follow-up
GetBucketTaggingreturnedNoSuchTagSet, andS3 Control
ListTagsForResourcereturned an empty list, instead of the tagssupplied at creation time.
AWS request body reference:
https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateBucket.html#API_CreateBucket_RequestBody
This fix parses the
<Tag>set at creation time and stores it in_bucket_tags, so bothGetBucketTaggingand S3 ControlListTagsForResourcereturn the tags. Invalid tags are rejected before thebucket is created, so no partial state is left behind.
Validation behavior
Each rule's error code, HTTP status, and message were verified against real
AWS S3 (a live account), and the emulator now matches on every case.
InvalidTag/ 400 / "The TagKey you have provided is invalid"InvalidTag/ 400 / "The TagValue you have provided is invalid"aws:key prefixInvalidTag/ 400 /User-defined tag keys can't start with "aws:". This prefix is reserved for system tags. Remove "aws:" from your tag keys and try again.aws:prefix: https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/custom-tags.html#allocation-tag-restrictionsBadRequest/ 400 / "Bucket tag count cannot be greater than 50"InternalError/ 500 / "We encountered an internal error. Please try again."Out of scope
PutBucketTaggingalso validates duplicate keys on real AWS, but it returnsInvalidTag/ 400 / "Cannot provide multiple Tags with the same key" (adifferent response from the CreateBucket 500). I have left
PutBucketTaggingunchanged in this PR to keep the change focused on the CreateBucket path; its
handler still uses the existing last-writer-wins parse. This can be addressed
in a follow-up.
Implementation notes
Parsing is factored into a shared
_iter_tag_pairshelper. The lenient_parse_tags_xml(last-writer-wins on duplicate keys) is unchanged and stillused by the
PutBucketTaggingandPutObjectTagginghandlers.Tests
Added integration tests covering: tags applied on create, tags plus
LocationConstraint, no tags leaving no tag set, empty tag values, all fourvalidation failures above, the duplicate-key 500, and readability of
create-time tags through S3 Control
ListTagsForResource. Every rejectiontest also asserts the bucket was not created.