fix(s3): reject unrestored archived GetObject reads (#8196)

This commit is contained in:
Jimmy Liu Jia authored and GitHub committed 2026-11-13 09:06:05 -04:00
1 parent e41cc9b88d
commit 19a1742761
5 files changed
+201 -13

No files matched your search

+1 -1
View File
@@ -31,7 +31,7 @@
| **Inventory** | PutBucketInventoryConfiguration, GetBucketInventoryConfiguration, ListBucketInventoryConfigurations, DeleteBucketInventoryConfiguration |
| **Replication** | PutBucketReplication, GetBucketReplication, DeleteBucketReplication |
**RestoreObject** tracks temporary restore state for GLACIER and DEEP_ARCHIVE objects per version. HeadObject and GetObject report `x-amz-restore`; ListObjects, ListObjectsV2, and ListObjectVersions report `RestoreStatus` when requested with `x-amz-optional-object-attributes: RestoreStatus`. New restores return 202, while extending a completed restore returns 200. Restores complete immediately by default; `FLOCI_SERVICES_S3_RESTORE_COMPLETION_DELAY_SECONDS` sets a delay for polling workflows. The temporary copy expires at the next UTC midnight after its requested days elapse from completion. Floci still allows GetObject on archived objects before restoration and after the temporary copy expires.
**RestoreObject** tracks temporary restore state for GLACIER and DEEP_ARCHIVE objects per version. HeadObject reports `x-amz-restore`, and GetObject reports it after restoration completes; ListObjects, ListObjectsV2, and ListObjectVersions report `RestoreStatus` when requested with `x-amz-optional-object-attributes: RestoreStatus`. New restores return 202, while extending a completed restore returns 200. Restores complete immediately by default; `FLOCI_SERVICES_S3_RESTORE_COMPLETION_DELAY_SECONDS` sets a delay for polling workflows. The temporary copy expires at the next UTC midnight after its requested days elapse from completion. GetObject returns `InvalidObjectState` (HTTP 403) before restoration, while it is in progress, and after the temporary copy expires.
**Replication** is configuration-only: the replication configuration is stored on the bucket and round-trips through `GetBucketReplication`, but no objects are actually replicated.
@@ -1128,6 +1128,7 @@ public class S3Controller {
S3Object obj = read.object();
boolean bodyHandedOff = false;
try {
s3Service.requireArchivedObjectReadable(obj);
if (hasPreconditions(ifMatch, ifNoneMatch, ifModifiedSince, ifUnmodifiedSince)) {
// Evaluate preconditions against the same snapshot that is served: a separate
// metadata fetch could approve one version (e.g. If-Match for a CAS read) while a
@@ -1338,6 +1339,12 @@ public class S3Controller {
}
private Response websiteObjectResponse(S3Service.ObjectRead read, ResponseHeaderOverrides overrides) {
try {
s3Service.requireArchivedObjectReadable(read.object());
} catch (AwsException e) {
closeQuietly(read);
throw e;
}
return fullObjectResponse(read, overrides, false);
}
@@ -3762,9 +3769,16 @@ public class S3Controller {
// The routing layer strips a trailing slash from the object key, so the "directory" intent
// has to be recovered from the raw request path before handing off to the service.
String rawPath = currentVertxRequest.getCurrent().request().path();
return renderWebsiteResolution(bucket,
s3Service.resolveWebsiteRequest(bucket, key, rawPath.endsWith("/"), authorization),
rawPath, includeBody);
try {
return renderWebsiteResolution(bucket,
s3Service.resolveWebsiteRequest(bucket, key, rawPath.endsWith("/"), authorization),
rawPath, includeBody);
} catch (AwsException e) {
if (!"InvalidObjectState".equals(e.getErrorCode())) {
throw e;
}
return serveWebsiteErrorResponse(bucket, authorization, e);
}
}
private Response serveWebsiteErrorResponse(String bucket,
@@ -3887,11 +3901,11 @@ public class S3Controller {
// S3 InvalidArgument responses carry ArgumentName and ArgumentValue so the SDK can
// surface which input was rejected, and EntityTooSmall and EntityTooLarge the proposed and
// allowed sizes. Multipart size errors also identify the rejected part, MethodNotAllowed
// the method and the kind of resource that refused it, and NoSuchKey and NoSuchVersion
// the key and version that are missing.
// the method and the kind of resource that refused it, NoSuchKey and NoSuchVersion
// the key and version that are missing, and InvalidObjectState the storage class.
// They travel through AwsException.extendedData.
if (e.getExtendedData() != null) {
for (String field : List.of("Key", "VersionId", "Method", "ResourceType", "ProposedSize",
for (String field : List.of("StorageClass", "Key", "VersionId", "Method", "ResourceType", "ProposedSize",
"MinSizeAllowed", "MaxSizeAllowed", "PartNumber", "ETag")) {
Object value = e.getExtendedData().get(field);
if (value != null) {
@@ -4113,7 +4113,9 @@ public class S3Service implements Resettable, ResourceProvider {
}
try {
authorizeGetObject(bucket, cfg.getErrorDocument(), null, authorization);
return new WebsiteResolution.ErrorDocument(getObject(bucket, cfg.getErrorDocument()), responseStatus);
S3Object object = getObject(bucket, cfg.getErrorDocument());
requireArchivedObjectReadable(object);
return new WebsiteResolution.ErrorDocument(object, responseStatus);
} catch (AwsException e) {
if (!isWebsiteErrorDocumentTrigger(e)) {
throw e;
@@ -4128,7 +4130,8 @@ public class S3Service implements Resettable, ResourceProvider {
* attempting at all.
*/
public static boolean isWebsiteErrorDocumentTrigger(AwsException e) {
return "NoSuchKey".equals(e.getErrorCode()) || "AccessDenied".equals(e.getErrorCode());
return "NoSuchKey".equals(e.getErrorCode()) || "AccessDenied".equals(e.getErrorCode())
|| "InvalidObjectState".equals(e.getErrorCode());
}
public void deleteBucketTagging(String bucketName) {
@@ -6852,6 +6855,17 @@ public class S3Service implements Resettable, ResourceProvider {
return restoreStatus(object, clock.instant());
}
public void requireArchivedObjectReadable(S3Object object) {
if ("GLACIER".equals(object.getStorageClass()) || "DEEP_ARCHIVE".equals(object.getStorageClass())) {
RestoreStatus restore = restoreStatus(object);
if (restore == null || restore.inProgress()) {
throw new AwsException("InvalidObjectState",
"The operation is not valid for the object's storage class", 403,
Map.of("StorageClass", object.getStorageClass()));
}
}
}
private static RestoreStatus restoreStatus(S3Object object, Instant now) {
Instant completedAt = object.getRestoreCompletionAt();
Instant expiresAt = object.getRestoreExpiryAt();
@@ -210,7 +210,12 @@ class S3IntegrationTest {
.statusCode(200)
.body(containsString("CopyObjectResult"));
// Verify the copy
given().when().get("/test-bucket/greeting-copy.txt").then().statusCode(403)
.body("Error.Code", equalTo("InvalidObjectState"));
given().body("<RestoreRequest><Days>1</Days></RestoreRequest>")
.when().post("/test-bucket/greeting-copy.txt?restore").then().statusCode(202);
// Verify the restored copy
given()
.header("x-amz-checksum-mode", "ENABLED")
.when()
@@ -249,7 +254,12 @@ class S3IntegrationTest {
.statusCode(200)
.body(containsString("CopyObjectResult"));
// Verify the copy inherits the source checksum (CRC64NVME)
given().when().get("/test-bucket/greeting-copy-no-override.txt").then().statusCode(403)
.body("Error.Code", equalTo("InvalidObjectState"));
given().body("<RestoreRequest><Days>1</Days></RestoreRequest>")
.when().post("/test-bucket/greeting-copy-no-override.txt?restore").then().statusCode(202);
// Verify the restored copy inherits the source checksum (CRC64NVME)
given()
.header("x-amz-checksum-mode", "ENABLED")
.when()
@@ -5,6 +5,7 @@ import io.floci.aws.testing.MutableClock;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
import io.restassured.RestAssured;
import jakarta.inject.Inject;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -30,6 +31,8 @@ import static org.junit.jupiter.api.Assertions.assertNull;
@TestProfile(S3RestoreStateIntegrationTest.DelayedRestoreProfile.class)
class S3RestoreStateIntegrationTest {
private static final String RESTORE_REQUEST = "<RestoreRequest><Days>1</Days></RestoreRequest>";
private static final String ARCHIVED_OBJECT_ERROR_MESSAGE =
"The operation is not valid for the object's storage class";
private static final String COMPLETED_RESTORE_HEADER =
"ongoing-request=\"false\", expiry-date=\"Sat, 03 Jan 2026 00:00:00 GMT\"";
@@ -61,17 +64,29 @@ class S3RestoreStateIntegrationTest {
given().when().head(olderPath).then().statusCode(200).header("x-amz-restore", nullValue());
given().when().head(currentPath).then().statusCode(200).header("x-amz-restore", nullValue());
given().when().get(olderPath).then().statusCode(403)
.body("Error.Code", equalTo("InvalidObjectState"))
.body("Error.Message", equalTo(ARCHIVED_OBJECT_ERROR_MESSAGE))
.body("Error.StorageClass", equalTo("GLACIER"));
given().when().get(currentPath).then().statusCode(403)
.body("Error.Code", equalTo("InvalidObjectState"));
given().when().get(fixture.path()).then().statusCode(403)
.body("Error.Code", equalTo("InvalidObjectState"));
given().body(RESTORE_REQUEST).when().post(olderPath + "&restore").then().statusCode(202);
given().when().head(olderPath).then().statusCode(200)
.header("x-amz-restore", equalTo("ongoing-request=\"true\""));
given().when().get(olderPath).then().statusCode(200)
.header("x-amz-restore", equalTo("ongoing-request=\"true\""));
given().when().get(olderPath).then().statusCode(403)
.body("Error.Code", equalTo("InvalidObjectState"));
given().when().head(currentPath).then().statusCode(200).header("x-amz-restore", nullValue());
given().body(RESTORE_REQUEST).when().post(currentPath + "&restore").then().statusCode(202);
given().when().head(currentPath).then().statusCode(200)
.header("x-amz-restore", equalTo("ongoing-request=\"true\""));
given().header("Range", "bytes=0-1").when().get(currentPath).then().statusCode(403)
.body("Error.Code", equalTo("InvalidObjectState"));
given().when().get(currentPath + "&partNumber=1").then().statusCode(403)
.body("Error.Code", equalTo("InvalidObjectState"));
given().header("x-amz-optional-object-attributes", "RestoreStatus")
.queryParam("list-type", "2").when().get(fixture.bucketPath()).then().statusCode(200)
.body(containsString("<IsRestoreInProgress>true</IsRestoreInProgress>"));
@@ -92,12 +107,145 @@ class S3RestoreStateIntegrationTest {
given().when().get(olderPath).then().statusCode(200)
.header("x-amz-restore", equalTo(COMPLETED_RESTORE_HEADER))
.body(equalTo("older"));
given().header("Range", "bytes=0-1").when().get(currentPath).then().statusCode(206)
.body(equalTo("cu"));
given().header("x-amz-optional-object-attributes", "RestoreStatus")
.queryParam("list-type", "2").when().get(fixture.bucketPath()).then().statusCode(200)
.body(containsString("<IsRestoreInProgress>false</IsRestoreInProgress>"))
.body(containsString("<RestoreExpiryDate>2026-01-03T00:00:00Z</RestoreExpiryDate>"));
given().body(RESTORE_REQUEST).when().post(olderPath + "&restore").then().statusCode(200);
given().body(RESTORE_REQUEST).when().post(currentPath + "&restore").then().statusCode(200);
clock.advance(Duration.ofDays(2));
given().when().head(olderPath).then().statusCode(200).header("x-amz-restore", nullValue());
given().when().get(olderPath).then().statusCode(403)
.body("Error.Code", equalTo("InvalidObjectState"));
given().when().get(currentPath).then().statusCode(403)
.body("Error.Code", equalTo("InvalidObjectState"));
}
}
@Test
void restoringOneVersionDoesNotUnlockAnother() {
try (Fixture fixture = new Fixture()) {
String olderPath = fixture.path() + "?versionId=" + fixture.olderVersion();
String currentPath = fixture.path() + "?versionId=" + fixture.currentVersion();
given().body(RESTORE_REQUEST).when().post(olderPath + "&restore").then().statusCode(202);
clock.advance(Duration.ofSeconds(61));
given().when().get(olderPath).then().statusCode(200).body(equalTo("older"));
given().when().get(currentPath).then().statusCode(403)
.body("Error.Code", equalTo("InvalidObjectState"));
given().when().get(fixture.path()).then().statusCode(403)
.body("Error.Code", equalTo("InvalidObjectState"));
}
}
@Test
void deepArchiveGetObjectRequiresCompletedRestore() {
try (Fixture fixture = new Fixture()) {
String path = fixture.bucketPath() + "/deep.txt";
String version = given().header("x-amz-storage-class", "DEEP_ARCHIVE").body("deep")
.when().put(path).then().statusCode(200).extract().header("x-amz-version-id");
String versionedPath = path + "?versionId=" + version;
try {
given().when().head(versionedPath).then().statusCode(200);
given().when().get(versionedPath).then().statusCode(403)
.body("Error.Code", equalTo("InvalidObjectState"))
.body("Error.Message", equalTo(ARCHIVED_OBJECT_ERROR_MESSAGE))
.body("Error.StorageClass", equalTo("DEEP_ARCHIVE"));
given().body(RESTORE_REQUEST).when().post(versionedPath + "&restore").then().statusCode(202);
given().when().get(versionedPath).then().statusCode(403)
.body("Error.Code", equalTo("InvalidObjectState"));
clock.advance(Duration.ofSeconds(61));
given().when().get(versionedPath).then().statusCode(200).body(equalTo("deep"));
clock.advance(Duration.ofDays(2));
given().when().get(versionedPath).then().statusCode(403)
.body("Error.Code", equalTo("InvalidObjectState"));
} finally {
given().when().delete(versionedPath).then().statusCode(204);
}
}
}
@Test
void glacierInstantRetrievalDoesNotRequireRestore() {
try (Fixture fixture = new Fixture()) {
String path = fixture.bucketPath() + "/instant.txt";
String version = given().header("x-amz-storage-class", "GLACIER_IR").body("instant")
.when().put(path).then().statusCode(200).extract().header("x-amz-version-id");
try {
given().when().get(path + "?versionId=" + version)
.then().statusCode(200).body(equalTo("instant"));
} finally {
given().when().delete(path + "?versionId=" + version).then().statusCode(204);
}
}
}
@Test
void websiteDoesNotServeArchivedIndexOrErrorDocumentUntilRestored() {
try (Fixture fixture = new Fixture()) {
String indexPath = fixture.bucketPath() + "/index.html";
String errorPath = fixture.bucketPath() + "/error.html";
String websiteHost = fixture.bucket + ".s3-website-us-east-1.localhost:" + RestAssured.port;
String websiteConfiguration = "<WebsiteConfiguration><IndexDocument><Suffix>index.html</Suffix>"
+ "</IndexDocument><ErrorDocument><Key>error.html</Key></ErrorDocument>"
+ "</WebsiteConfiguration>";
given().body(websiteConfiguration).when().put(fixture.bucketPath() + "?website")
.then().statusCode(200);
String indexVersion = null;
String errorVersion = null;
try {
indexVersion = given().header("x-amz-storage-class", "GLACIER").body("archived index")
.when().put(indexPath).then().statusCode(200).extract().header("x-amz-version-id");
errorVersion = given().header("x-amz-storage-class", "DEEP_ARCHIVE").body("archived error")
.when().put(errorPath).then().statusCode(200).extract().header("x-amz-version-id");
given().header("Host", websiteHost).when().get("/missing-page").then().statusCode(404)
.body(not(containsString("archived error")));
given().header("Host", websiteHost).when().head("/").then().statusCode(200);
given().header("Host", websiteHost).when().head("/index.html").then().statusCode(200);
given().header("Host", websiteHost).when().get("/index.html").then().statusCode(403)
.header("Content-Type", containsString("text/html"))
.body(not(containsString("archived index")))
.body(not(containsString("archived error")));
given().header("Host", websiteHost).when().get("/").then().statusCode(not(equalTo(200)))
.body(not(containsString("archived index")));
given().body(RESTORE_REQUEST).when().post(indexPath + "?versionId=" + indexVersion + "&restore")
.then().statusCode(202);
given().body(RESTORE_REQUEST).when().post(errorPath + "?versionId=" + errorVersion + "&restore")
.then().statusCode(202);
given().header("Host", websiteHost).when().get("/").then().statusCode(not(equalTo(200)))
.body(not(containsString("archived index")));
given().header("Host", websiteHost).when().get("/missing-page").then().statusCode(404)
.body(not(containsString("archived error")));
clock.advance(Duration.ofSeconds(61));
given().header("Host", websiteHost).when().get("/").then().statusCode(200)
.body(equalTo("archived index"));
given().header("Host", websiteHost).when().get("/missing-page").then().statusCode(404)
.body(equalTo("archived error"));
clock.advance(Duration.ofDays(2));
given().header("Host", websiteHost).when().get("/").then().statusCode(not(equalTo(200)))
.body(not(containsString("archived index")));
given().header("Host", websiteHost).when().get("/missing-page").then().statusCode(404)
.body(not(containsString("archived error")));
} finally {
if (errorVersion != null) {
given().when().delete(errorPath + "?versionId=" + errorVersion).then().statusCode(204);
}
if (indexVersion != null) {
given().when().delete(indexPath + "?versionId=" + indexVersion).then().statusCode(204);
}
}
}
}
@@ -252,6 +400,8 @@ class S3RestoreStateIntegrationTest {
.then().statusCode(403).body("Error.Code", equalTo("ObjectAlreadyInActiveTierError"));
given().when().head(fixture.bucketPath() + "/ordinary.txt").then().statusCode(200)
.header("x-amz-restore", nullValue());
given().when().get(fixture.bucketPath() + "/ordinary.txt")
.then().statusCode(200).body(equalTo("ordinary"));
given().when().delete(fixture.bucketPath() + "/ordinary.txt?versionId=" + ordinaryVersion)
.then().statusCode(204);
}