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

@@ -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();