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:
Aniket Shukla authored and GitHub committed 2026-08-30 14:40:28 -05:00
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",