mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 14:10:49 -05:00
fix(s3): prevent compliance retention downgrade (#2755)
* fix(s3): prevent compliance retention downgrade * fix(s3): allow updates after compliance expiry
This commit is contained in:
1 parent
2bc37365dc
commit
2e5935d764
2 files changed
+115
-3
No files matched your search
@@ -1859,9 +1859,19 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
.orElseThrow(() -> new AwsException("NoSuchKey",
|
||||
"The specified key does not exist.", 404));
|
||||
|
||||
// COMPLIANCE mode: retainUntil cannot be shortened
|
||||
if ("COMPLIANCE".equals(obj.getObjectLockMode())
|
||||
boolean activeComplianceRetention = "COMPLIANCE".equals(obj.getObjectLockMode())
|
||||
&& obj.getRetainUntilDate() != null
|
||||
&& Instant.now().isBefore(obj.getRetainUntilDate());
|
||||
|
||||
// Active COMPLIANCE mode cannot be changed or removed, even when the
|
||||
// retention date is unchanged or extended.
|
||||
if (activeComplianceRetention && !"COMPLIANCE".equals(mode)) {
|
||||
throw new AwsException("AccessDenied",
|
||||
"COMPLIANCE retention mode cannot be changed", 403);
|
||||
}
|
||||
|
||||
// Active COMPLIANCE mode: retainUntil cannot be shortened.
|
||||
if (activeComplianceRetention
|
||||
&& retainUntil != null
|
||||
&& retainUntil.isBefore(obj.getRetainUntilDate())) {
|
||||
throw new AwsException("AccessDenied",
|
||||
|
||||
+103
-1
@@ -143,7 +143,7 @@ class S3ObjectLockIntegrationTest {
|
||||
String body = """
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Retention xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||
<Mode>GOVERNANCE</Mode>
|
||||
<Mode>COMPLIANCE</Mode>
|
||||
<RetainUntilDate>2030-01-01T00:00:00Z</RetainUntilDate>
|
||||
</Retention>
|
||||
""";
|
||||
@@ -199,6 +199,108 @@ class S3ObjectLockIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Order(14)
|
||||
void putGovernanceObjectForRetentionUpgrade() {
|
||||
given()
|
||||
.header("x-amz-object-lock-mode", "GOVERNANCE")
|
||||
.header("x-amz-object-lock-retain-until-date", "2030-01-01T00:00:00Z")
|
||||
.body("governance object")
|
||||
.when()
|
||||
.put("/" + LOCK_BUCKET + "/governance-object.txt")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(15)
|
||||
void governanceRetentionCanBeUpgradedToCompliance() {
|
||||
String body = """
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Retention xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||
<Mode>COMPLIANCE</Mode>
|
||||
<RetainUntilDate>2030-01-01T00:00:00Z</RetainUntilDate>
|
||||
</Retention>
|
||||
""";
|
||||
given()
|
||||
.body(body)
|
||||
.when()
|
||||
.put("/" + LOCK_BUCKET + "/governance-object.txt?retention")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/" + LOCK_BUCKET + "/governance-object.txt?retention")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<Mode>COMPLIANCE</Mode>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(16)
|
||||
void complianceRetentionCannotBeDowngradedToGovernance() {
|
||||
String body = """
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Retention xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||
<Mode>GOVERNANCE</Mode>
|
||||
<RetainUntilDate>2030-01-01T00:00:00Z</RetainUntilDate>
|
||||
</Retention>
|
||||
""";
|
||||
given()
|
||||
.body(body)
|
||||
.when()
|
||||
.put("/" + LOCK_BUCKET + "/" + RETENTION_KEY + "?retention")
|
||||
.then()
|
||||
.statusCode(403)
|
||||
.body(containsString("AccessDenied"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/" + LOCK_BUCKET + "/" + RETENTION_KEY + "?retention")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<Mode>COMPLIANCE</Mode>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(17)
|
||||
void putObjectWithExpiredComplianceRetention() {
|
||||
given()
|
||||
.header("x-amz-object-lock-mode", "COMPLIANCE")
|
||||
.header("x-amz-object-lock-retain-until-date", "2020-01-01T00:00:00Z")
|
||||
.body("expired compliance object")
|
||||
.when()
|
||||
.put("/" + LOCK_BUCKET + "/expired-compliance-object.txt")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(18)
|
||||
void expiredComplianceRetentionCanChangeMode() {
|
||||
String body = """
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Retention xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||
<Mode>GOVERNANCE</Mode>
|
||||
<RetainUntilDate>2030-01-01T00:00:00Z</RetainUntilDate>
|
||||
</Retention>
|
||||
""";
|
||||
given()
|
||||
.body(body)
|
||||
.when()
|
||||
.put("/" + LOCK_BUCKET + "/expired-compliance-object.txt?retention")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/" + LOCK_BUCKET + "/expired-compliance-object.txt?retention")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<Mode>GOVERNANCE</Mode>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(19)
|
||||
void nonExistentBucketReturnsNoSuchBucket() {
|
||||
given()
|
||||
.when()
|
||||
|
||||
Reference in new issue
Block a user