mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(s3): route the replication subresource instead of falling through (#2519)
PUT /{bucket}?replication fell through to CreateBucket: in the default
region the idempotent-create path answered 200 with a Location header
and stored no replication configuration, and elsewhere it failed with
BucketAlreadyOwnedByYou. GET fell through to ListObjects and returned
a ListBucketResult the SDK silently parsed as an empty replication
configuration. Only DELETE was routed, as a no-op.
Route PUT and GET alongside the existing DELETE case, per the issue's
suggested fix: the configuration is stored verbatim on the bucket and
echoed back — Floci does not model replication behavior, and neither
the SDK nor the Terraform provider needs it to. The PUT body's
ReplicationConfiguration root is validated (MalformedXML otherwise);
GET on a bucket with no stored configuration answers
ReplicationConfigurationNotFoundError (404), which is what the SDK and
aws_s3_bucket_replication_configuration treat as "not configured".
Now that PUT stores a configuration, DeleteBucketReplication clears it
instead of no-opping (still an unconditional 204, matching AWS), and a
DELETE on a missing bucket answers NoSuchBucket instead of the no-op's
204.
IamActionRegistry maps the three verbs to the documented actions:
s3:PutReplicationConfiguration for PUT and DELETE (AWS authorizes
DeleteBucketReplication with the put action) and
s3:GetReplicationConfiguration for GET. The mapping mirrors the
controller's per-method dispatch order: on PUT and GET accelerate is
dispatched ahead of replication, while the DELETE chain routes
replication and never routes accelerate to an operation.
Closes #2296
This commit is contained in:
1 parent
60dd795703
commit
ce4f6d1c48
7 files changed
+507
-14
No files matched your search
@@ -198,6 +198,102 @@ class IamActionRegistryTest {
|
||||
registry.resolve("s3", mockCtx("PUT", "/bucket", withUploads, null, "")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void s3ReplicationResolvesToItsOwnActions() {
|
||||
// Without the override, PUT ?replication resolves to s3:CreateBucket — a
|
||||
// principal allowed only to create buckets could rewrite the replication
|
||||
// configuration.
|
||||
MultivaluedMap<String, String> replication = new MultivaluedHashMap<>();
|
||||
replication.add("replication", "");
|
||||
assertEquals("s3:PutReplicationConfiguration",
|
||||
registry.resolve("s3", mockCtx("PUT", "/bucket", replication, null, "")));
|
||||
assertEquals("s3:GetReplicationConfiguration",
|
||||
registry.resolve("s3", mockCtx("GET", "/bucket", replication, null, "")));
|
||||
// AWS authorizes DeleteBucketReplication with the put action.
|
||||
assertEquals("s3:PutReplicationConfiguration",
|
||||
registry.resolve("s3", mockCtx("DELETE", "/bucket", replication, null, "")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void s3ReplicationOnAnObjectPathKeepsTheObjectActions() {
|
||||
// The object routes ignore ?replication, so mapping it there would let a
|
||||
// principal with only replication permissions read or write arbitrary objects.
|
||||
MultivaluedMap<String, String> replication = new MultivaluedHashMap<>();
|
||||
replication.add("replication", "");
|
||||
assertEquals("s3:GetObject",
|
||||
registry.resolve("s3", mockCtx("GET", "/bucket/secret.txt", replication, null, "")));
|
||||
assertEquals("s3:PutObject",
|
||||
registry.resolve("s3", mockCtx("PUT", "/bucket/key.txt", replication, null, "")));
|
||||
assertEquals("s3:DeleteObject",
|
||||
registry.resolve("s3", mockCtx("DELETE", "/bucket/key.txt", replication, null, "")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void s3ReplicationYieldsToSubresourcesDispatchedFirst() {
|
||||
// The controller executes the requestPayment operation for this request, so the
|
||||
// replication mapping must not claim it; resolution falls back to the rule table.
|
||||
MultivaluedMap<String, String> withRequestPayment = new MultivaluedHashMap<>();
|
||||
withRequestPayment.add("requestPayment", "");
|
||||
withRequestPayment.add("replication", "");
|
||||
assertEquals("s3:CreateBucket",
|
||||
registry.resolve("s3", mockCtx("PUT", "/bucket", withRequestPayment, null, "")));
|
||||
MultivaluedMap<String, String> withLocation = new MultivaluedHashMap<>();
|
||||
withLocation.add("location", "");
|
||||
withLocation.add("replication", "");
|
||||
assertEquals("s3:ListBucket",
|
||||
registry.resolve("s3", mockCtx("GET", "/bucket", withLocation, null, "")));
|
||||
// The DELETE chain dispatches website ahead of replication.
|
||||
MultivaluedMap<String, String> withWebsite = new MultivaluedHashMap<>();
|
||||
withWebsite.add("website", "");
|
||||
withWebsite.add("replication", "");
|
||||
assertEquals("s3:DeleteBucket",
|
||||
registry.resolve("s3", mockCtx("DELETE", "/bucket", withWebsite, null, "")));
|
||||
// requestPayment has no DELETE dispatch branch; it is inert there and
|
||||
// replication executes, so the mapping must still claim the request.
|
||||
MultivaluedMap<String, String> deleteWithRequestPayment = new MultivaluedHashMap<>();
|
||||
deleteWithRequestPayment.add("requestPayment", "");
|
||||
deleteWithRequestPayment.add("replication", "");
|
||||
assertEquals("s3:PutReplicationConfiguration",
|
||||
registry.resolve("s3", mockCtx("DELETE", "/bucket", deleteWithRequestPayment, null, "")));
|
||||
// uploads is a GET-only dispatch branch; on PUT it is inert and replication
|
||||
// executes, so the mapping must still claim the request there.
|
||||
MultivaluedMap<String, String> putWithUploads = new MultivaluedHashMap<>();
|
||||
putWithUploads.add("uploads", "");
|
||||
putWithUploads.add("replication", "");
|
||||
assertEquals("s3:PutReplicationConfiguration",
|
||||
registry.resolve("s3", mockCtx("PUT", "/bucket", putWithUploads, null, "")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void s3ReplicationAndAcceleratePrecedenceFollowsEachMethodsDispatchOrder() {
|
||||
// PUT and GET dispatch accelerate ahead of replication; DELETE routes
|
||||
// replication and never routes accelerate to an operation.
|
||||
MultivaluedMap<String, String> both = new MultivaluedHashMap<>();
|
||||
both.add("accelerate", "");
|
||||
both.add("replication", "");
|
||||
assertEquals("s3:PutAccelerateConfiguration",
|
||||
registry.resolve("s3", mockCtx("PUT", "/bucket", both, null, "")));
|
||||
assertEquals("s3:GetAccelerateConfiguration",
|
||||
registry.resolve("s3", mockCtx("GET", "/bucket", both, null, "")));
|
||||
assertEquals("s3:PutReplicationConfiguration",
|
||||
registry.resolve("s3", mockCtx("DELETE", "/bucket", both, null, "")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void s3ReplicationDoesNotPreemptAclOrTagging() {
|
||||
// Appending an inert ?replication must not downgrade a stricter resolution.
|
||||
MultivaluedMap<String, String> withAcl = new MultivaluedHashMap<>();
|
||||
withAcl.add("replication", "");
|
||||
withAcl.add("acl", "");
|
||||
assertEquals("s3:PutBucketAcl",
|
||||
registry.resolve("s3", mockCtx("PUT", "/bucket", withAcl, null, "")));
|
||||
MultivaluedMap<String, String> withTagging = new MultivaluedHashMap<>();
|
||||
withTagging.add("replication", "");
|
||||
withTagging.add("tagging", "");
|
||||
assertEquals("s3:DeleteBucketTagging",
|
||||
registry.resolve("s3", mockCtx("DELETE", "/bucket", withTagging, null, "")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void s3AccelerateDoesNotPreemptAclOrTagging() {
|
||||
// Appending an inert ?accelerate must not downgrade a stricter resolution.
|
||||
|
||||
+318
@@ -0,0 +1,318 @@
|
||||
package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class S3ReplicationConfigurationIntegrationTest {
|
||||
|
||||
private static final String BUCKET = "replication-config-int-test";
|
||||
private static final String REPLICATION_XML = """
|
||||
<ReplicationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||
<Role>arn:aws:iam::000000000000:role/replication-role</Role>
|
||||
<Rule>
|
||||
<ID>rule1</ID>
|
||||
<Status>Enabled</Status>
|
||||
<Destination>
|
||||
<Bucket>arn:aws:s3:::replication-config-int-test-target</Bucket>
|
||||
</Destination>
|
||||
</Rule>
|
||||
</ReplicationConfiguration>
|
||||
""";
|
||||
private static final String REPLACEMENT_XML = """
|
||||
<ReplicationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||
<Role>arn:aws:iam::000000000000:role/replication-role-two</Role>
|
||||
<Rule>
|
||||
<ID>rule2</ID>
|
||||
<Status>Disabled</Status>
|
||||
<Destination>
|
||||
<Bucket>arn:aws:s3:::replication-config-int-test-other</Bucket>
|
||||
</Destination>
|
||||
</Rule>
|
||||
</ReplicationConfiguration>
|
||||
""";
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createBucket() {
|
||||
given()
|
||||
.when()
|
||||
.put("/" + BUCKET)
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* A bucket without a replication configuration answers
|
||||
* {@code ReplicationConfigurationNotFoundError} (404) — what the SDK and the
|
||||
* Terraform provider treat as "not configured". Before the replication
|
||||
* subresource was routed this fell through to ListObjects and returned a
|
||||
* {@code ListBucketResult}, which the SDK parsed as an empty configuration —
|
||||
* a silent wrong answer instead of the 404.
|
||||
*/
|
||||
@Test
|
||||
@Order(2)
|
||||
void getReplicationBeforePutReturnsNotFoundError() {
|
||||
given()
|
||||
.when()
|
||||
.get("/" + BUCKET + "?replication")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body(containsString("ReplicationConfigurationNotFoundError"))
|
||||
.body(not(containsString("ListBucketResult")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Regression test for the fall-through to the bucket-creation handler: outside the
|
||||
* default region it returned {@code BucketAlreadyOwnedByYou}, and inside it the
|
||||
* idempotent-create path answered a silent 200 with a {@code Location} header
|
||||
* without storing a replication configuration — the absent header
|
||||
* distinguishes the routed response.
|
||||
*/
|
||||
@Test
|
||||
@Order(3)
|
||||
void putReplicationOnExistingBucketReturns200() {
|
||||
given()
|
||||
.body(REPLICATION_XML)
|
||||
.when()
|
||||
.put("/" + BUCKET + "?replication")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("Location", nullValue())
|
||||
.body(not(containsString("BucketAlreadyOwnedByYou")));
|
||||
}
|
||||
|
||||
/** The stored configuration is echoed back verbatim. */
|
||||
@Test
|
||||
@Order(4)
|
||||
void getReplicationEchoesTheStoredConfiguration() {
|
||||
given()
|
||||
.when()
|
||||
.get("/" + BUCKET + "?replication")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<ReplicationConfiguration"))
|
||||
.body(containsString("role/replication-role"))
|
||||
.body(containsString("<ID>rule1</ID>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void putReplicationReplacesTheStoredConfiguration() {
|
||||
given()
|
||||
.body(REPLACEMENT_XML)
|
||||
.when()
|
||||
.put("/" + BUCKET + "?replication")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
given()
|
||||
.when()
|
||||
.get("/" + BUCKET + "?replication")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<ID>rule2</ID>"))
|
||||
.body(not(containsString("<ID>rule1</ID>")));
|
||||
}
|
||||
|
||||
/** The ReplicationConfiguration root is Required: Yes, so a body that does not parse to one is malformed. */
|
||||
@Test
|
||||
@Order(6)
|
||||
void putReplicationRejectsAnUnparseableBody() {
|
||||
for (String body : new String[] {
|
||||
"",
|
||||
"garbage {} not xml",
|
||||
"""
|
||||
<ReplicationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||
<Role>arn:aws:iam::000000000000:role/replication-role""" }) {
|
||||
given()
|
||||
.body(body)
|
||||
.when()
|
||||
.put("/" + BUCKET + "?replication")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("MalformedXML"));
|
||||
}
|
||||
given()
|
||||
.when()
|
||||
.get("/" + BUCKET + "?replication")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<ID>rule2</ID>"));
|
||||
}
|
||||
|
||||
/** A configuration inside the wrong root must not store anything. */
|
||||
@Test
|
||||
@Order(7)
|
||||
void putReplicationRejectsAWrongRootElement() {
|
||||
given()
|
||||
.body("""
|
||||
<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||
<Status>Enabled</Status>
|
||||
</VersioningConfiguration>
|
||||
""")
|
||||
.when()
|
||||
.put("/" + BUCKET + "?replication")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("MalformedXML"));
|
||||
given()
|
||||
.when()
|
||||
.get("/" + BUCKET + "?replication")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<ID>rule2</ID>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void putReplicationOnMissingBucketReturns404() {
|
||||
given()
|
||||
.body(REPLICATION_XML)
|
||||
.when()
|
||||
.put("/this-bucket-does-not-exist-repl?replication")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body(containsString("NoSuchBucket"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void getReplicationOnMissingBucketReturns404() {
|
||||
given()
|
||||
.when()
|
||||
.get("/this-bucket-does-not-exist-repl?replication")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body(containsString("NoSuchBucket"));
|
||||
}
|
||||
|
||||
/**
|
||||
* DeleteBucketReplication removes the stored configuration and answers 204;
|
||||
* a later GET is back to the not-configured 404. The bucket itself must
|
||||
* survive — before the subresource was handled a {@code DELETE
|
||||
* /{bucket}?replication} would have fallen through to {@code DeleteBucket}.
|
||||
*/
|
||||
@Test
|
||||
@Order(10)
|
||||
void deleteReplicationClearsTheStoredConfiguration() {
|
||||
given()
|
||||
.when()
|
||||
.delete("/" + BUCKET + "?replication")
|
||||
.then()
|
||||
.statusCode(204);
|
||||
given()
|
||||
.when()
|
||||
.get("/" + BUCKET + "?replication")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body(containsString("ReplicationConfigurationNotFoundError"));
|
||||
given()
|
||||
.when()
|
||||
.get("/" + BUCKET + "?location")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
/** Matching real S3, deleting an already-absent configuration still answers 204. */
|
||||
@Test
|
||||
@Order(11)
|
||||
void deleteReplicationWithoutConfigurationStillReturns204() {
|
||||
given()
|
||||
.when()
|
||||
.delete("/" + BUCKET + "?replication")
|
||||
.then()
|
||||
.statusCode(204);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
void deleteReplicationOnMissingBucketReturns404() {
|
||||
given()
|
||||
.when()
|
||||
.delete("/this-bucket-does-not-exist-repl?replication")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body(containsString("NoSuchBucket"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Pins the per-method precedence at the wire: the PUT and GET chains dispatch
|
||||
* accelerate ahead of replication, while the DELETE chain routes replication —
|
||||
* accelerate's DELETE arm is a 405 and must not preempt it. The IAM mapping
|
||||
* mirrors exactly this order, so a silent controller reorder would desynchronize
|
||||
* the two.
|
||||
*/
|
||||
@Test
|
||||
@Order(13)
|
||||
void accelerateAndReplicationPrecedenceFollowsEachMethodsDispatchOrder() {
|
||||
String bucket = "replication-precedence-test";
|
||||
given()
|
||||
.when()
|
||||
.put("/" + bucket)
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// PUT ?accelerate&replication executes accelerate: the accelerate body is
|
||||
// accepted, and nothing lands in the replication store.
|
||||
given()
|
||||
.body("""
|
||||
<AccelerateConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||
<Status>Enabled</Status>
|
||||
</AccelerateConfiguration>
|
||||
""")
|
||||
.when()
|
||||
.put("/" + bucket + "?accelerate&replication")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
given()
|
||||
.when()
|
||||
.get("/" + bucket + "?accelerate")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<Status>Enabled</Status>"));
|
||||
given()
|
||||
.when()
|
||||
.get("/" + bucket + "?replication")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body(containsString("ReplicationConfigurationNotFoundError"));
|
||||
|
||||
// GET ?accelerate&replication executes accelerate: an AccelerateConfiguration
|
||||
// comes back, not the replication 404.
|
||||
given()
|
||||
.when()
|
||||
.get("/" + bucket + "?accelerate&replication")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<AccelerateConfiguration"));
|
||||
|
||||
// DELETE ?accelerate&replication executes replication: the stored
|
||||
// configuration is cleared at 204 — not accelerate's 405.
|
||||
given()
|
||||
.body(REPLICATION_XML)
|
||||
.when()
|
||||
.put("/" + bucket + "?replication")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
given()
|
||||
.when()
|
||||
.delete("/" + bucket + "?accelerate&replication")
|
||||
.then()
|
||||
.statusCode(204);
|
||||
given()
|
||||
.when()
|
||||
.get("/" + bucket + "?replication")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body(containsString("ReplicationConfigurationNotFoundError"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user