mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(s3): enforce auth on bucket-level config writes when enforce-auth is enabled (#3536)
* fix(s3): enforce auth on bucket-level config writes when enforce-auth is enabled With FLOCI_SERVICES_S3_ENFORCE_AUTH=true, unsigned object reads are refused unless a policy or ACL makes them public, and since #2326 unsigned object writes are refused the same way. Bucket management was never covered: CreateBucket, DeleteBucket, and every PUT/DELETE on a bucket subresource (?policy, ?acl, ?cors, ?lifecycle, ?versioning, ?website, ?notification, ?logging, ?encryption, ?publicAccessBlock, ?ownershipControls, ?requestPayment, ?tagging, ?accelerate, ?replication, ?object-lock, ?metrics) behaved identically with the flag on or off. An anonymous caller could PUT ?policy a public-read grant onto any bucket and then read what the previous request had correctly refused. Authorization in S3Controller is opt-in per branch, and only the three newest subresources called authorizeBucketWrite. createBucket and deleteBucket now parse the request's credentials once and check every branch against the bucket's policy with the matching s3:* action before the mutator runs, and s3:DeleteBucket before the bare delete. CreateBucket gets its own authorizeCreateBucket: there is no policy to consult and AWS never accepts it anonymously, so an unsigned request is AccessDenied and a signed one must carry a known key; authorizeBucketWrite would have answered NoSuchBucket, the wrong code and an existence oracle. Nothing changes with the flag off. With it on, anonymous bucket management now fails with 403, as it does on AWS. The enforce-auth tests created their buckets and policies anonymously, which was this bug running green; those 38 setup calls now sign with the class's legacy key, and four new tests pin CreateBucket/DeleteBucket, the policy-rewrite exploit, every subresource, and the policy-granted anonymous case. Closes #2335 * fix(s3): never let a bucket policy grant PutBucketPolicy or DeleteBucketPolicy anonymously AWS lets only an identity in the bucket owner's account manage the bucket policy, so the policy itself can never grant s3:PutBucketPolicy or s3:DeleteBucketPolicy to an anonymous caller. authorizeBucketWrite honoured a Principal "*" grant for those two actions like any other, which would have let an unsigned caller rewrite or delete a policy that named them. Refuse them before consulting the policy, and pin it with a test that installs a self-granting policy and checks anonymous PUT and DELETE ?policy are still AccessDenied and the policy survives. Raised in review on #3536.
This commit is contained in:
1 parent
e9454af855
commit
28105c08ec
4 files changed
+361
-28
No files matched your search
+303
-16
@@ -52,6 +52,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
private static final String BYPASS_BUCKET = "auth-bypass-governance-bucket";
|
||||
private static final String BYPASS_KEY = "bypass-target.txt";
|
||||
private static final String CONDITIONAL_DENY_ACL_BUCKET = "auth-conditional-deny-acl-bucket";
|
||||
private static final String BUCKET_CONFIG_BUCKET = "auth-bucket-config-bucket";
|
||||
private static final String PUBLIC_KEY = "public.txt";
|
||||
private static final String PRIVATE_KEY = "private.txt";
|
||||
private static final String ERROR_KEY = "error.html";
|
||||
@@ -71,8 +72,8 @@ class S3AuthEnforcementIntegrationTest {
|
||||
@Test
|
||||
@Order(1)
|
||||
void createBucketsAndObjects() {
|
||||
given().when().put("/" + PUBLIC_BUCKET).then().statusCode(200);
|
||||
given().when().put("/" + PRIVATE_BUCKET).then().statusCode(200);
|
||||
given().header("Authorization", LOCAL_AUTH_HEADER).when().put("/" + PUBLIC_BUCKET).then().statusCode(200);
|
||||
given().header("Authorization", LOCAL_AUTH_HEADER).when().put("/" + PRIVATE_BUCKET).then().statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
@@ -91,6 +92,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.contentType("application/json")
|
||||
.body(publicReadPolicy(PUBLIC_BUCKET))
|
||||
.when()
|
||||
@@ -245,7 +247,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
@Test
|
||||
@Order(12)
|
||||
void websiteRootAuthorizesIndexObjectReadNotBucketList() {
|
||||
given().when().put("/" + WEBSITE_BUCKET).then().statusCode(200);
|
||||
given().header("Authorization", LOCAL_AUTH_HEADER).when().put("/" + WEBSITE_BUCKET).then().statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
@@ -257,6 +259,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.contentType("application/xml")
|
||||
.body(websiteConfiguration())
|
||||
.when()
|
||||
@@ -265,6 +268,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.contentType("application/json")
|
||||
.body(publicGetObjectPolicy(WEBSITE_BUCKET))
|
||||
.when()
|
||||
@@ -292,7 +296,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
@Test
|
||||
@Order(13)
|
||||
void websiteRootUsesErrorDocumentForDeniedIndexObject() {
|
||||
given().when().put("/" + WEBSITE_ERROR_BUCKET).then().statusCode(200);
|
||||
given().header("Authorization", LOCAL_AUTH_HEADER).when().put("/" + WEBSITE_ERROR_BUCKET).then().statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
@@ -313,6 +317,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.contentType("application/xml")
|
||||
.body(websiteConfiguration(ERROR_KEY))
|
||||
.when()
|
||||
@@ -321,6 +326,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.contentType("application/json")
|
||||
.body(publicGetObjectPolicy(WEBSITE_ERROR_BUCKET, ERROR_KEY))
|
||||
.when()
|
||||
@@ -342,7 +348,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
@Test
|
||||
@Order(14)
|
||||
void bucketAclPublicReadAllowsUnsignedList() {
|
||||
given().when().put("/" + BUCKET_ACL_BUCKET).then().statusCode(200);
|
||||
given().header("Authorization", LOCAL_AUTH_HEADER).when().put("/" + BUCKET_ACL_BUCKET).then().statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
@@ -353,6 +359,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.contentType("application/xml")
|
||||
.body(publicReadAcl())
|
||||
.when()
|
||||
@@ -371,7 +378,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
@Test
|
||||
@Order(15)
|
||||
void explicitBucketPolicyDenyOverridesPublicObjectAcl() {
|
||||
given().when().put("/" + DENY_BUCKET).then().statusCode(200);
|
||||
given().header("Authorization", LOCAL_AUTH_HEADER).when().put("/" + DENY_BUCKET).then().statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
@@ -383,6 +390,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.contentType("application/json")
|
||||
.body(denyGetObjectPolicy(DENY_BUCKET))
|
||||
.when()
|
||||
@@ -484,9 +492,10 @@ class S3AuthEnforcementIntegrationTest {
|
||||
@Test
|
||||
@Order(20)
|
||||
void missingObjectRequiresListBucketToReturnNoSuchKey() {
|
||||
given().when().put("/" + GET_ONLY_BUCKET).then().statusCode(200);
|
||||
given().header("Authorization", LOCAL_AUTH_HEADER).when().put("/" + GET_ONLY_BUCKET).then().statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.contentType("application/json")
|
||||
.body(publicGetObjectPolicy(GET_ONLY_BUCKET))
|
||||
.when()
|
||||
@@ -512,9 +521,10 @@ class S3AuthEnforcementIntegrationTest {
|
||||
@Test
|
||||
@Order(21)
|
||||
void versionedObjectReadRequiresGetObjectVersion() {
|
||||
given().when().put("/" + VERSION_BUCKET).then().statusCode(200);
|
||||
given().header("Authorization", LOCAL_AUTH_HEADER).when().put("/" + VERSION_BUCKET).then().statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.contentType("application/xml")
|
||||
.body("<VersioningConfiguration><Status>Enabled</Status></VersioningConfiguration>")
|
||||
.when()
|
||||
@@ -532,6 +542,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
.extract().header("x-amz-version-id");
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.contentType("application/json")
|
||||
.body(publicObjectActionPolicy(VERSION_BUCKET, "s3:GetObject"))
|
||||
.when()
|
||||
@@ -547,6 +558,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
.body("Error.Code", equalTo("AccessDenied"));
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.contentType("application/json")
|
||||
.body(publicObjectActionPolicy(VERSION_BUCKET, "s3:GetObjectVersion"))
|
||||
.when()
|
||||
@@ -703,7 +715,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
@Test
|
||||
@Order(29)
|
||||
void unsignedRequestCannotPutObject() {
|
||||
given().when().put("/" + WRITE_BUCKET).then().statusCode(200);
|
||||
given().header("Authorization", LOCAL_AUTH_HEADER).when().put("/" + WRITE_BUCKET).then().statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
@@ -779,9 +791,10 @@ class S3AuthEnforcementIntegrationTest {
|
||||
@Test
|
||||
@Order(32)
|
||||
void bucketPolicyCanExplicitlyAllowAnonymousWrite() {
|
||||
given().when().put("/" + PUBLIC_WRITE_BUCKET).then().statusCode(200);
|
||||
given().header("Authorization", LOCAL_AUTH_HEADER).when().put("/" + PUBLIC_WRITE_BUCKET).then().statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.contentType("application/json")
|
||||
.body(publicObjectActionPolicy(PUBLIC_WRITE_BUCKET, "s3:PutObject"))
|
||||
.when()
|
||||
@@ -797,6 +810,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.contentType("application/json")
|
||||
.body(publicObjectActionPolicy(PUBLIC_WRITE_BUCKET, "s3:DeleteObject"))
|
||||
.when()
|
||||
@@ -1064,7 +1078,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
// Per AWS's ACL docs, a bucket-ACL WRITE grant to a non-owner (like AllUsers) "denies
|
||||
// non-owners the ability to overwrite or delete existing objects" -- it only lets them
|
||||
// create new ones.
|
||||
given().when().put("/" + PUBLIC_WRITE_ACL_BUCKET).then().statusCode(200);
|
||||
given().header("Authorization", LOCAL_AUTH_HEADER).when().put("/" + PUBLIC_WRITE_ACL_BUCKET).then().statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
@@ -1108,7 +1122,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
@Test
|
||||
@Order(39)
|
||||
void explicitPolicyDenyOverridesPublicWriteAcl() {
|
||||
given().when().put("/" + DENY_WRITE_ACL_BUCKET).then().statusCode(200);
|
||||
given().header("Authorization", LOCAL_AUTH_HEADER).when().put("/" + DENY_WRITE_ACL_BUCKET).then().statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
@@ -1119,6 +1133,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.contentType("application/json")
|
||||
.body(denyObjectActionPolicy(DENY_WRITE_ACL_BUCKET, "s3:PutObject"))
|
||||
.when()
|
||||
@@ -1182,9 +1197,10 @@ class S3AuthEnforcementIntegrationTest {
|
||||
@Test
|
||||
@Order(41)
|
||||
void deleteObjectPolicyGrantDoesNotAuthorizeVersionedDelete() {
|
||||
given().when().put("/" + DELETE_VERSION_BUCKET).then().statusCode(200);
|
||||
given().header("Authorization", LOCAL_AUTH_HEADER).when().put("/" + DELETE_VERSION_BUCKET).then().statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.contentType("application/xml")
|
||||
.body("<VersioningConfiguration><Status>Enabled</Status></VersioningConfiguration>")
|
||||
.when()
|
||||
@@ -1202,6 +1218,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
.extract().header("x-amz-version-id");
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.contentType("application/json")
|
||||
.body(publicObjectActionPolicy(DELETE_VERSION_BUCKET, "s3:DeleteObject"))
|
||||
.when()
|
||||
@@ -1226,7 +1243,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
@Test
|
||||
@Order(42)
|
||||
void deleteObjectDoesNotBypassGovernanceRetentionWithoutDistinctPermission() {
|
||||
given().when().put("/" + BYPASS_BUCKET).then().statusCode(200);
|
||||
given().header("Authorization", LOCAL_AUTH_HEADER).when().put("/" + BYPASS_BUCKET).then().statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
@@ -1237,6 +1254,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.contentType("application/json")
|
||||
.body(publicObjectActionPolicy(BYPASS_BUCKET, "s3:DeleteObject"))
|
||||
.when()
|
||||
@@ -1253,6 +1271,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
.body("Error.Code", equalTo("AccessDenied"));
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.contentType("application/json")
|
||||
.body(deleteAndBypassGovernancePolicy(BYPASS_BUCKET))
|
||||
.when()
|
||||
@@ -1288,7 +1307,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
// Floci has no request context to evaluate a Condition against, so a conditional Deny
|
||||
// is treated as applying (fail closed) -- consistent with S3PublicAccessEvaluatorTest's
|
||||
// conditionalDenyFailsClosedAndOverridesAllow, this must also override the ACL fallback.
|
||||
given().when().put("/" + CONDITIONAL_DENY_ACL_BUCKET).then().statusCode(200);
|
||||
given().header("Authorization", LOCAL_AUTH_HEADER).when().put("/" + CONDITIONAL_DENY_ACL_BUCKET).then().statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
@@ -1299,6 +1318,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.contentType("application/json")
|
||||
.body(conditionalDenyObjectActionPolicy(CONDITIONAL_DENY_ACL_BUCKET, "s3:PutObject"))
|
||||
.when()
|
||||
@@ -1318,9 +1338,10 @@ class S3AuthEnforcementIntegrationTest {
|
||||
@Test
|
||||
@Order(44)
|
||||
void batchDeleteObjectsPolicyGrantDoesNotAuthorizeVersionedDelete() {
|
||||
given().when().put("/" + BATCH_DELETE_VERSION_BUCKET).then().statusCode(200);
|
||||
given().header("Authorization", LOCAL_AUTH_HEADER).when().put("/" + BATCH_DELETE_VERSION_BUCKET).then().statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.contentType("application/xml")
|
||||
.body("<VersioningConfiguration><Status>Enabled</Status></VersioningConfiguration>")
|
||||
.when()
|
||||
@@ -1338,6 +1359,7 @@ class S3AuthEnforcementIntegrationTest {
|
||||
.extract().header("x-amz-version-id");
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.contentType("application/json")
|
||||
.body(publicObjectActionPolicy(BATCH_DELETE_VERSION_BUCKET, "s3:DeleteObject"))
|
||||
.when()
|
||||
@@ -1458,6 +1480,257 @@ class S3AuthEnforcementIntegrationTest {
|
||||
.when().get(path).then().statusCode(403).body(containsString("InvalidAccessKeyId"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(46)
|
||||
void unsignedRequestCannotCreateOrDeleteBucket() {
|
||||
given()
|
||||
.when()
|
||||
.put("/" + BUCKET_CONFIG_BUCKET)
|
||||
.then()
|
||||
.statusCode(403)
|
||||
.body(containsString("AccessDenied"));
|
||||
|
||||
given()
|
||||
.header("Authorization", BAD_AUTH_HEADER)
|
||||
.when()
|
||||
.put("/" + BUCKET_CONFIG_BUCKET)
|
||||
.then()
|
||||
.statusCode(403)
|
||||
.body(containsString("InvalidAccessKeyId"));
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.when()
|
||||
.head("/" + BUCKET_CONFIG_BUCKET)
|
||||
.then()
|
||||
.statusCode(404);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.when()
|
||||
.put("/" + BUCKET_CONFIG_BUCKET)
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.delete("/" + BUCKET_CONFIG_BUCKET)
|
||||
.then()
|
||||
.statusCode(403)
|
||||
.body(containsString("AccessDenied"));
|
||||
|
||||
given()
|
||||
.header("Authorization", BAD_AUTH_HEADER)
|
||||
.when()
|
||||
.delete("/" + BUCKET_CONFIG_BUCKET)
|
||||
.then()
|
||||
.statusCode(403)
|
||||
.body(containsString("InvalidAccessKeyId"));
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.when()
|
||||
.head("/" + BUCKET_CONFIG_BUCKET)
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(47)
|
||||
void unsignedRequestCannotRewriteBucketPolicyToExposePrivateObject() {
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.body("secret data")
|
||||
.when()
|
||||
.put("/" + BUCKET_CONFIG_BUCKET + "/" + PRIVATE_KEY)
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/" + BUCKET_CONFIG_BUCKET + "/" + PRIVATE_KEY)
|
||||
.then()
|
||||
.statusCode(403)
|
||||
.body(containsString("AccessDenied"));
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body(publicGetObjectPolicy(BUCKET_CONFIG_BUCKET))
|
||||
.when()
|
||||
.put("/" + BUCKET_CONFIG_BUCKET + "?policy")
|
||||
.then()
|
||||
.statusCode(403)
|
||||
.body(containsString("AccessDenied"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/" + BUCKET_CONFIG_BUCKET + "/" + PRIVATE_KEY)
|
||||
.then()
|
||||
.statusCode(403)
|
||||
.body(containsString("AccessDenied"));
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.when()
|
||||
.get("/" + BUCKET_CONFIG_BUCKET + "?policy")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body(containsString("NoSuchBucketPolicy"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.delete("/" + BUCKET_CONFIG_BUCKET + "?policy")
|
||||
.then()
|
||||
.statusCode(403)
|
||||
.body(containsString("AccessDenied"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(48)
|
||||
void unsignedRequestCannotWriteBucketSubresources() {
|
||||
for (String subresource : new String[] {
|
||||
"acl", "cors", "lifecycle", "versioning", "website", "notification", "logging",
|
||||
"encryption", "publicAccessBlock", "ownershipControls", "requestPayment", "tagging",
|
||||
"accelerate", "replication", "object-lock", "metrics&id=anon"}) {
|
||||
given()
|
||||
.when()
|
||||
.put("/" + BUCKET_CONFIG_BUCKET + "?" + subresource)
|
||||
.then()
|
||||
.statusCode(403)
|
||||
.body(containsString("AccessDenied"));
|
||||
}
|
||||
for (String subresource : new String[] {
|
||||
"cors", "lifecycle", "website", "encryption", "publicAccessBlock",
|
||||
"ownershipControls", "tagging", "replication", "metrics&id=anon"}) {
|
||||
given()
|
||||
.when()
|
||||
.delete("/" + BUCKET_CONFIG_BUCKET + "?" + subresource)
|
||||
.then()
|
||||
.statusCode(403)
|
||||
.body(containsString("AccessDenied"));
|
||||
}
|
||||
|
||||
given()
|
||||
.header("Authorization", BAD_AUTH_HEADER)
|
||||
.contentType("application/xml")
|
||||
.body("<Tagging><TagSet><Tag><Key>k</Key><Value>v</Value></Tag></TagSet></Tagging>")
|
||||
.when()
|
||||
.put("/" + BUCKET_CONFIG_BUCKET + "?tagging")
|
||||
.then()
|
||||
.statusCode(403)
|
||||
.body(containsString("InvalidAccessKeyId"));
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.when()
|
||||
.get("/" + BUCKET_CONFIG_BUCKET + "?tagging")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(not(containsString("<Key>k</Key>")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(49)
|
||||
void bucketPolicyCanExplicitlyAllowAnonymousBucketConfigWrite() {
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.contentType("application/json")
|
||||
.body(publicBucketActionPolicy(BUCKET_CONFIG_BUCKET, "s3:PutBucketTagging"))
|
||||
.when()
|
||||
.put("/" + BUCKET_CONFIG_BUCKET + "?policy")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/xml")
|
||||
.body("<Tagging><TagSet><Tag><Key>anon</Key><Value>granted</Value></Tag></TagSet></Tagging>")
|
||||
.when()
|
||||
.put("/" + BUCKET_CONFIG_BUCKET + "?tagging")
|
||||
.then()
|
||||
.statusCode(204);
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.when()
|
||||
.get("/" + BUCKET_CONFIG_BUCKET + "?tagging")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<Key>anon</Key>"));
|
||||
|
||||
given()
|
||||
.contentType("application/xml")
|
||||
.body("<CORSConfiguration><CORSRule><AllowedOrigin>*</AllowedOrigin>"
|
||||
+ "<AllowedMethod>GET</AllowedMethod></CORSRule></CORSConfiguration>")
|
||||
.when()
|
||||
.put("/" + BUCKET_CONFIG_BUCKET + "?cors")
|
||||
.then()
|
||||
.statusCode(403)
|
||||
.body(containsString("AccessDenied"));
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.when()
|
||||
.delete("/" + BUCKET_CONFIG_BUCKET + "?policy")
|
||||
.then()
|
||||
.statusCode(204);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(50)
|
||||
void bucketPolicyCannotGrantAnonymousBucketPolicyWrites() {
|
||||
String selfGrantingPolicy = """
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": {
|
||||
"Effect": "Allow",
|
||||
"Principal": "*",
|
||||
"Action": ["s3:PutBucketPolicy", "s3:DeleteBucketPolicy"],
|
||||
"Resource": "arn:aws:s3:::%s"
|
||||
}
|
||||
}
|
||||
""".formatted(BUCKET_CONFIG_BUCKET);
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.contentType("application/json")
|
||||
.body(selfGrantingPolicy)
|
||||
.when()
|
||||
.put("/" + BUCKET_CONFIG_BUCKET + "?policy")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body(publicGetObjectPolicy(BUCKET_CONFIG_BUCKET))
|
||||
.when()
|
||||
.put("/" + BUCKET_CONFIG_BUCKET + "?policy")
|
||||
.then()
|
||||
.statusCode(403)
|
||||
.body(containsString("AccessDenied"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.delete("/" + BUCKET_CONFIG_BUCKET + "?policy")
|
||||
.then()
|
||||
.statusCode(403)
|
||||
.body(containsString("AccessDenied"));
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.when()
|
||||
.get("/" + BUCKET_CONFIG_BUCKET + "?policy")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("s3:DeleteBucketPolicy"))
|
||||
.body(not(containsString("s3:GetObject")));
|
||||
|
||||
given()
|
||||
.header("Authorization", LOCAL_AUTH_HEADER)
|
||||
.when()
|
||||
.delete("/" + BUCKET_CONFIG_BUCKET + "?policy")
|
||||
.then()
|
||||
.statusCode(204);
|
||||
}
|
||||
|
||||
private static String presignedSignature(String method, String path,
|
||||
String accessKeyId, String secretKey, String expires) {
|
||||
return presignedSignature(method, path, accessKeyId, secretKey, expires, "UNSIGNED-PAYLOAD");
|
||||
@@ -1587,6 +1860,20 @@ class S3AuthEnforcementIntegrationTest {
|
||||
""".formatted(action, bucket, key);
|
||||
}
|
||||
|
||||
private static String publicBucketActionPolicy(String bucket, String action) {
|
||||
return """
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": {
|
||||
"Effect": "Allow",
|
||||
"Principal": "*",
|
||||
"Action": "%s",
|
||||
"Resource": "arn:aws:s3:::%s"
|
||||
}
|
||||
}
|
||||
""".formatted(action, bucket);
|
||||
}
|
||||
|
||||
private static String denyGetObjectPolicy(String bucket) {
|
||||
return """
|
||||
{
|
||||
|
||||
+1
@@ -49,6 +49,7 @@ class S3PresignedPostAuthEnforcementIntegrationTest {
|
||||
@Order(1)
|
||||
void createBucket() {
|
||||
given()
|
||||
.header("Authorization", authorizationHeader(LEGACY_ACCESS_KEY_ID))
|
||||
.when()
|
||||
.put("/" + BUCKET)
|
||||
.then()
|
||||
|
||||
Reference in new issue
Block a user