mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(s3): apply CreateBucketConfiguration tags on bucket creation (#2115)
CreateBucket accepted a <Tags> array in the request body but ignored it.
The body was parsed for LocationConstraint only, so tags supplied at
creation were silently dropped: the request returned 200, and a
following GetBucketTagging or S3 Control ListTagsForResource reported an
empty tag set.
AWS applies these tags. The CreateBucket API reference documents Tags
inside CreateBucketConfiguration as "an array of tags that you can apply
to the bucket that you're creating", gated on the s3:TagResource
permission.
The gap is visible through the AWS Terraform provider, which sends
bucket tags this way rather than via a separate PutBucketTagging call.
Against Floci an aws_s3_bucket with a tags map applies cleanly but lands
with tags = {} in state, so every subsequent plan proposes to add them
again -- a diff that never converges.
Parse the same <Tag> key/value pairs handlePutBucketTagging already
parses, and route them through the existing s3Service.putBucketTagging
once the bucket exists.
Verified end to end: with this change a terraform apply of a tagged
aws_s3_bucket records the tag in state, get-bucket-tagging returns it,
and the next plan reports no changes. The unpatched image, same config
and provider version, still reports tags = {} and a pending change.
This commit is contained in:
1 parent
0929f20e1b
commit
79031a240a
2 files changed
+47
No files matched your search
@@ -331,6 +331,15 @@ public class S3Controller {
|
||||
}
|
||||
String region = locationConstraint != null ? locationConstraint : regionResolver.resolveRegion(httpHeaders);
|
||||
s3Service.createBucket(bucket, region);
|
||||
// CreateBucketConfiguration may carry a <Tags> array; AWS applies those tags to the
|
||||
// new bucket, so a follow-up GetBucketTagging / ListTagsForResource must return them.
|
||||
if (body != null && body.length > 0) {
|
||||
Map<String, String> creationTags = XmlParser.extractPairs(
|
||||
new String(body, StandardCharsets.UTF_8), "Tag", "Key", "Value");
|
||||
if (!creationTags.isEmpty()) {
|
||||
s3Service.putBucketTagging(bucket, creationTags);
|
||||
}
|
||||
}
|
||||
String lockEnabled = httpHeaders.getHeaderString("x-amz-bucket-object-lock-enabled");
|
||||
if ("true".equalsIgnoreCase(lockEnabled)) {
|
||||
s3Service.putBucketVersioning(bucket, "Enabled");
|
||||
|
||||
@@ -361,6 +361,44 @@ class S3IntegrationTest {
|
||||
.body(containsString("NoSuchBucket"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(21)
|
||||
void createBucketAppliesTagsFromCreateBucketConfiguration() {
|
||||
String bucket = "tagged-at-create-bucket";
|
||||
String createBucketConfiguration = """
|
||||
<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||
<Tags>
|
||||
<Tag>
|
||||
<Key>owner</Key>
|
||||
<Value>data-team</Value>
|
||||
</Tag>
|
||||
</Tags>
|
||||
</CreateBucketConfiguration>
|
||||
""";
|
||||
|
||||
given()
|
||||
.contentType("application/xml")
|
||||
.body(createBucketConfiguration)
|
||||
.when()
|
||||
.put("/" + bucket)
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/" + bucket + "?tagging")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("owner"))
|
||||
.body(containsString("data-team"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.delete("/" + bucket)
|
||||
.then()
|
||||
.statusCode(204);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
void headBucketReturnsStoredRegionForLocationConstraintBucket() {
|
||||
|
||||
Reference in new issue
Block a user