Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(s3): apply and check the Object Lock headers of every object creation (#5828)

Priamo Germosen792260ed49f7
diff --git a/docs/services/s3.md b/docs/services/s3.md
index bb4b82acdb..d86606670c 100644
--- a/docs/services/s3.md
+++ b/docs/services/s3.md
@@ -668,6 +668,8 @@ Floci now persists and returns the following object attribute state on S3 object
after replacing the undersized part.
- multipart checksums follow the AWS checksum type: `COMPOSITE` (`<checksum of the part checksums>-<part count>`) for SHA1, SHA256 and, by default, CRC32 and CRC32C; `FULL_OBJECT` for CRC64NVME or when `x-amz-checksum-type: FULL_OBJECT` was requested on `CreateMultipartUpload`. The `-N` suffix is returned by `CompleteMultipartUpload`, `HeadObject` and `GetObject`, and omitted by `GetObjectAttributes`, which lists part-level checksums only for `COMPOSITE` objects (a `FULL_OBJECT` multipart object reports its `PartsCount` alone, a single-part object has no `ObjectParts`), as on AWS. `UploadPart` echoes the part checksum (`x-amz-checksum-<algorithm>`) when the upload declared an algorithm, and completing a `COMPOSITE` upload requires the checksum of every part in the `CompleteMultipartUpload` body (`InvalidRequest` otherwise), while `FULL_OBJECT` uploads accept a body without them
- canned object ACLs from `x-amz-acl` on `PutObject`, `CopyObject`, and multipart initiation
+- explicit ACL grant headers (`x-amz-grant-read`, `x-amz-grant-write`, `x-amz-grant-full-control`, `x-amz-grant-read-acp`, `x-amz-grant-write-acp`) with `id` and `uri` grantees on `PutObject`, `CopyObject`, and multipart initiation, where they apply when the upload completes
+- Object Lock headers (`x-amz-object-lock-mode`, `x-amz-object-lock-retain-until-date`, `x-amz-object-lock-legal-hold`) on `PutObject`, `CopyObject`, and multipart initiation, where they apply when the upload completes. A mode without a date or a date without a mode, an unknown mode, or a date that is not an ISO 8601 timestamp is refused with `400 InvalidArgument`
- explicit object SSE headers from `x-amz-server-side-encryption` on `PutObject`, `CopyObject`, and multipart initiation, replayed on `GetObject` and `HeadObject`
- SSE-KMS key IDs from `x-amz-server-side-encryption-aws-kms-key-id` on `PutObject` and multipart initiation, and from `CopyObject`/`UploadPartCopy` (inherited from the source object when the request doesn't specify new SSE headers), returned by `PutObject`, `CopyObject`, `UploadPartCopy`, `CompleteMultipartUpload`, `GetObject`, and `HeadObject`. A bucket's default SSE-KMS key is not simulated: `aws:kms` with no explicit key ID omits the header rather than returning a synthesized `aws/s3` key ARN
@@ -675,7 +677,7 @@ Current limitations:
- checksum algorithms: CRC32, CRC32C, CRC64NVME, SHA1 and SHA256 are supported; the other AWS algorithms (SHA512, MD5, XXHASH3, XXHASH64, XXHASH128) are rejected with `InvalidRequest`
- copy-based metadata updates support `x-amz-metadata-directive: REPLACE` for user metadata and content type, but do not yet cover every AWS copy header
-- explicit ACL grant headers such as `x-amz-grant-read` and `x-amz-grant-full-control` are not modeled yet
+- `emailAddress` grantees in the `x-amz-grant-*` headers are refused with `501 NotImplemented`
- cross-account canned ACL variants collapse to the emulator's single synthetic owner where Floci does not model a distinct second principal
- `aws-exec-read` is accepted for compatibility, but Floci does not yet model a distinct EC2 bundle-reader grantee in `GetObjectAcl`
- `log-delivery-write` grants the well-known S3 log-delivery group (`http://acs.amazonaws.com/groups/s3/LogDelivery`) `WRITE` and `READ_ACP`, matching AWS on the bucket path. Floci's shared canned-ACL helper also accepts it on `PutObjectAcl`, where AWS does not: the canned ACL is documented as bucket-only and the SDK's `ObjectCannedACL` enum omits it. That object path is a Floci leniency, not parity. It is the mirror image of `aws-exec-read` above, which botocore's `BucketCannedACL` enum omits, though AWS's canned-ACL reference documents it as valid for both bucket and object; there the narrower party is the SDK model, not AWS
diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java b/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java
index a4a24e049d..38b09d78df 100644
--- a/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java
+++ b/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java
@@ -872,18 +872,17 @@ public class S3Controller {
}
if (copySource != null && !copySource.isEmpty()) {
+ ObjectLockHeaders lock = objectLockHeaders(httpHeaders);
s3Service.authorizeObjectWrite(bucket, key, "s3:PutObject", authorization);
- return handleCopyObject(copySource, bucket, key, contentType, httpHeaders, uriInfo, authorization);
+ return handleCopyObject(copySource, bucket, key, contentType, httpHeaders, uriInfo, authorization,
+ lock);
}
rejectUnimplementedPutConditions(ifMatch, ifNoneMatch);
Map<String, String> inlineTags = parseInlineTaggingHeader(resolveInlineTaggingSource(tagging, uriInfo));
- String lockMode = httpHeaders.getHeaderString("x-amz-object-lock-mode");
- String retainUntilStr = httpHeaders.getHeaderString("x-amz-object-lock-retain-until-date");
- String legalHold = httpHeaders.getHeaderString("x-amz-object-lock-legal-hold");
- Instant retainUntil = retainUntilStr != null ? Instant.parse(retainUntilStr) : null;
+ ObjectLockHeaders lock = objectLockHeaders(httpHeaders);
String checksumAlgorithm = getChecksumAlgorithm(httpHeaders, uriInfo);
String persistedEncoding = toPersistedContentEncoding(contentEncoding);
@@ -903,9 +902,9 @@ public class S3Controller {
new PutObjectOptions()
.withStorageClass(httpHeaders.getHeaderString("x-amz-storage-class"))
.withContentEncoding(persistedEncoding)
- .withObjectLockMode(lockMode)
- .withRetainUntilDate(retainUntil)
- .withLegalHoldStatus(legalHold)
+ .withObjectLockMode(lock.mode())
+ .withRetainUntilDate(lock.retainUntilDate())
+ .withLegalHoldStatus(lock.legalHoldStatus())
.withContentDisposition(contentDisposition)
.withCacheControl(cacheControl)
.withServerSideEncryption(serverSideEncryption)
@@ -1584,21 +1583,35 @@ public class S3Controller {
s3Service.isAuthEnforced(), httpHeaders, uriInfo);
if (hasQueryParam(uriInfo, "uploads")) {
+ ObjectLockHeaders lock = objectLockHeaders(httpHeaders);
s3Service.authorizeObjectWrite(bucket, key, "s3:PutObject", authorization);
MultipartUpload upload = s3Service.initiateMultipartUpload(bucket, key, contentType,
extractUserMetadata(httpHeaders, uriInfo),
- httpHeaders.getHeaderString("x-amz-storage-class"),
- httpHeaders.getHeaderString("Content-Disposition"),
- httpHeaders.getHeaderString("x-amz-server-side-encryption"),
- httpHeaders.getHeaderString("x-amz-acl"),
- httpHeaders.getHeaderString("x-amz-server-side-encryption-aws-kms-key-id"),
- httpHeaders.getHeaderString("x-amz-server-side-encryption-customer-algorithm"),
- httpHeaders.getHeaderString("x-amz-server-side-encryption-customer-key"),
- httpHeaders.getHeaderString("x-amz-server-side-encryption-customer-key-MD5"),
- getChecksumAlgorithm(httpHeaders, uriInfo),
resolveHeaderOrQueryParam(httpHeaders, uriInfo, "x-amz-checksum-type"),
- parseInlineTaggingHeader(
- resolveInlineTaggingSource(httpHeaders.getHeaderString("x-amz-tagging"), uriInfo)));
+ new PutObjectOptions()
+ .withStorageClass(httpHeaders.getHeaderString("x-amz-storage-class"))
+ .withContentDisposition(httpHeaders.getHeaderString("Content-Disposition"))
+ .withServerSideEncryption(httpHeaders.getHeaderString("x-amz-server-side-encryption"))
+ .withSseKmsKeyId(httpHeaders.getHeaderString(
+ "x-amz-server-side-encryption-aws-kms-key-id"))
+ .withSseCustomerAlgorithm(httpHeaders.getHeaderString(
+ "x-amz-server-side-encryption-customer-algorithm"))
+ .withSseCustomerKey(httpHeaders.getHeaderString(
+ "x-amz-server-side-encryption-customer-key"))
+ .withSseCustomerKeyMd5(httpHeaders.getHeaderString(
+ "x-amz-server-side-encryption-customer-key-MD5"))
+ .withChecksumAlgorithm(getChecksumAlgorithm(httpHeaders, uriInfo))
+ .withAcl(httpHeaders.getHeaderString("x-amz-acl"))
+ .withGrantRead(httpHeaders.getHeaderString("x-amz-grant-read"))
+ .withGrantWrite(httpHeaders.getHeaderString("x-amz-grant-write"))
+ .withGrantFullControl(httpHeaders.getHeaderString("x-amz-grant-full-control"))
+ .withGrantReadAcp(httpHeaders.getHeaderString("x-amz-grant-read-acp"))
+ .withGrantWriteAcp(httpHeaders.getHeaderString("x-amz-grant-write-acp"))
+ .withObjectLockMode(lock.mode())
+ .withRetainUntilDate(lock.retainUntilDate())
+ .withLegalHoldStatus(lock.legalHoldStatus())
+ .withTagging(parseInlineTaggingHeader(resolveInlineTaggingSource(
+ httpHeaders.getHeaderString("x-amz-tagging"), uriInfo))));
String xml = new XmlBuilder()
.raw("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
.start("InitiateMultipartUploadResult", AwsNamespaces.S3)
@@ -3047,7 +3060,8 @@ public class S3Controller {
private Response handleCopyObject(String copySource, String destBucket, String destKey,
String contentType, HttpHeaders httpHeaders,
UriInfo uriInfo,
- S3Service.RequestAuthorization authorization) {
+ S3Service.RequestAuthorization authorization,
+ ObjectLockHeaders lock) {
CopySourceRef sourceObject = parseCopySource(copySource);
String sourceBucket = sourceObject.bucket();
authorizeCopySourceRead(httpHeaders, sourceObject, authorization);
@@ -3103,6 +3117,9 @@ public class S3Controller {
.withGrantFullControl(httpHeaders.getHeaderString("x-amz-grant-full-control"))
.withGrantReadAcp(httpHeaders.getHeaderString("x-amz-grant-read-acp"))
.withGrantWriteAcp(httpHeaders.getHeaderString("x-amz-grant-write-acp"))
+ .withObjectLockMode(lock.mode())
+ .withRetainUntilDate(lock.retainUntilDate())
+ .withLegalHoldStatus(lock.legalHoldStatus())
.withIfMatch(httpHeaders.getHeaderString("If-Match"))
.withIfNoneMatch(httpHeaders.getHeaderString("If-None-Match"))
.withCopySourceConditions(copySourceConditions(httpHeaders)));
@@ -4095,6 +4112,44 @@ public class S3Controller {
private static final int MAX_INLINE_TAGS = 10;
private static final int MAX_INLINE_TAGGING_HEADER_BYTES = 8 * 1024;
+ /** The Object Lock settings a PutObject, CopyObject or CreateMultipartUpload asks for in its headers. */
+ private record ObjectLockHeaders(String mode, Instant retainUntilDate, String legalHoldStatus) {
+ }
+
+ /**
+ * Reads the Object Lock headers of a PutObject, CopyObject or CreateMultipartUpload, refusing
+ * them as S3 was recorded refusing them, with InvalidArgument naming the header: a mode and a
+ * retain-until date come together or not at all, checked first, and the mode is GOVERNANCE or
+ * COMPLIANCE. A date that is not an ISO 8601 timestamp is refused the same way; S3 was not
+ * recorded on that one, so its message is floci's.
+ */
+ private static ObjectLockHeaders objectLockHeaders(HttpHeaders httpHeaders) {
+ String mode = httpHeaders.getHeaderString("x-amz-object-lock-mode");
+ String retainUntil = httpHeaders.getHeaderString("x-amz-object-lock-retain-until-date");
+ if ((mode == null) != (retainUntil == null)) {
+ throw new AwsException("InvalidArgument",
+ "x-amz-object-lock-retain-until-date and x-amz-object-lock-mode must both be supplied", 400,
+ Map.of("ArgumentName",
+ mode == null ? "x-amz-object-lock-mode" : "x-amz-object-lock-retain-until-date"));
+ }
+ if (mode != null && !"GOVERNANCE".equals(mode) && !"COMPLIANCE".equals(mode)) {
+ throw new AwsException("InvalidArgument", "Unknown wormMode directive.", 400,
+ Map.of("ArgumentName", "x-amz-object-lock-mode", "ArgumentValue", mode));
+ }
+ Instant retainUntilDate = null;
+ if (retainUntil != null) {
+ try {
+ retainUntilDate = Instant.parse(retainUntil);
+ } catch (DateTimeParseException e) {
+ throw new AwsException("InvalidArgument",
+ "The x-amz-object-lock-retain-until-date header must be an ISO 8601 timestamp.", 400,
+ Map.of("ArgumentName", "x-amz-object-lock-retain-until-date", "ArgumentValue", retainUntil));
+ }
+ }
+ return new ObjectLockHeaders(mode, retainUntilDate,
+ httpHeaders.getHeaderString("x-amz-object-lock-legal-hold"));
+ }
+
/**
* Resolves the inline {@code x-amz-tagging} value for PutObject and CreateMultipartUpload.
* The signed request header wins; otherwise the value comes from the {@code x-amz-tagging}
diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/S3Service.java b/src/main/java/io/github/hectorvent/floci/services/s3/S3Service.java
index 0340e05b26..843af4db42 100644
--- a/src/main/java/io/github/hectorvent/floci/services/s3/S3Service.java
+++ b/src/main/java/io/github/hectorvent/floci/services/s3/S3Service.java
@@ -3995,18 +3995,48 @@ public class S3Service implements Resettable, ResourceProvider {
String sseCustomerAlgorithm, String sseCustomerKey, String sseCustomerKeyMd5,
String checksumAlgorithm, String checksumType,
Map<String, String> tagging) {
+ return initiateMultipartUpload(bucket, key, contentType, metadata, checksumType, new PutObjectOptions()
+ .withStorageClass(storageClass)
+ .withContentDisposition(contentDisposition)
+ .withServerSideEncryption(serverSideEncryption)
+ .withAcl(acl)
+ .withSseKmsKeyId(sseKmsKeyId)
+ .withSseCustomerAlgorithm(sseCustomerAlgorithm)
+ .withSseCustomerKey(sseCustomerKey)
+ .withSseCustomerKeyMd5(sseCustomerKeyMd5)
+ .withChecksumAlgorithm(checksumAlgorithm)
+ .withTagging(tagging));
+ }
+
+ /**
+ * Starts a multipart upload of an object that gets {@code objectOptions} when it completes, as a
+ * PutObject takes them: its storage class, encryption, checksum algorithm, canned ACL or grants,
+ * tags and Object Lock settings. The ACL is checked here, so one S3 refuses fails the upload's
+ * creation rather than its completion.
+ */
+ public MultipartUpload initiateMultipartUpload(String bucket, String key, String contentType,
+ Map<String, String> metadata, String checksumType,
+ PutObjectOptions objectOptions) {
+ String storageClass = objectOptions.getStorageClass();
+ String contentDisposition = objectOptions.getContentDisposition();
+ String serverSideEncryption = objectOptions.getServerSideEncryption();
+ String acl = objectOptions.getAcl();
+ String sseKmsKeyId = objectOptions.getSseKmsKeyId();
+ String sseCustomerAlgorithm = objectOptions.getSseCustomerAlgorithm();
+ String sseCustomerKey = objectOptions.getSseCustomerKey();
+ String sseCustomerKeyMd5 = objectOptions.getSseCustomerKeyMd5();
+ String checksumAlgorithm = objectOptions.getChecksumAlgorithm();
+ Map<String, String> tagging = objectOptions.getTagging();
return withMultipartBucketReadLock(bucket, () -> {
ensureBucketExists(bucket);
Bucket destination = resolveBucket(bucket)
.orElseThrow(() -> new AwsException("NoSuchBucket",
"The specified bucket does not exist.", 404));
- if (ownershipIsEnforced(destination) && !isBlank(acl)
- && !"bucket-owner-full-control".equals(acl)) {
- throw new AwsException("AccessControlListNotSupported", "The bucket does not allow ACLs", 400);
- }
- if (acl != null && !acl.isBlank()) {
- cannedObjectAclXml(acl);
- }
+ String ownerAccount = getBucketOwnerAccountId(bucket);
+ rejectUploadAclWhenOwnershipEnforced(destination, ownerAccount, objectOptions);
+ resolveObjectAclXml(ownerAccount, acl, objectOptions.getGrantRead(), objectOptions.getGrantWrite(),
+ objectOptions.getGrantFullControl(), objectOptions.getGrantReadAcp(),
+ objectOptions.getGrantWriteAcp());
String normalizedServerSideEncryption = normalizeServerSideEncryption(serverSideEncryption);
SseCustomerKey customerKey = validateSseCustomerKey(sseCustomerAlgorithm, sseCustomerKey, sseCustomerKeyMd5);
rejectConflictingServerSideEncryption(normalizedServerSideEncryption, customerKey);
@@ -4025,6 +4055,14 @@ public class S3Service implements Resettable, ResourceProvider {
upload.setSseCustomerKeyMd5(customerKey.keyMd5());
}
upload.setAcl(acl);
+ upload.setGrantRead(objectOptions.getGrantRead());
+ upload.setGrantWrite(objectOptions.getGrantWrite());
+ upload.setGrantFullControl(objectOptions.getGrantFullControl());
+ upload.setGrantReadAcp(objectOptions.getGrantReadAcp());
+ upload.setGrantWriteAcp(objectOptions.getGrantWriteAcp());
+ upload.setObjectLockMode(objectOptions.getObjectLockMode());
+ upload.setRetainUntilDate(objectOptions.getRetainUntilDate());
+ upload.setLegalHoldStatus(objectOptions.getLegalHoldStatus());
ChecksumAlgorithm algorithm = ChecksumAlgorithm.fromWireValue(checksumAlgorithm);
ChecksumType requestedChecksumType = ChecksumType.fromWireValue(checksumType);
if (requestedChecksumType != null && algorithm == null) {
@@ -4476,6 +4514,14 @@ public class S3Service implements Resettable, ResourceProvider {
.withServerSideEncryption(upload.getServerSideEncryption())
.withSseKmsKeyId(upload.getSseKmsKeyId())
.withAcl(upload.getAcl())
+ .withGrantRead(upload.getGrantRead())
+ .withGrantWrite(upload.getGrantWrite())
+ .withGrantFullControl(upload.getGrantFullControl())
+ .withGrantReadAcp(upload.getGrantReadAcp())
+ .withGrantWriteAcp(upload.getGrantWriteAcp())
+ .withObjectLockMode(upload.getObjectLockMode())
+ .withRetainUntilDate(upload.getRetainUntilDate())
+ .withLegalHoldStatus(upload.getLegalHoldStatus())
.withTagging(upload.getTagging()),
compositeETag);
} finally {
@@ -7248,6 +7294,9 @@ public class S3Service implements Resettable, ResourceProvider {
.withGrantFullControl(effectiveOptions.getGrantFullControl())
.withGrantReadAcp(effectiveOptions.getGrantReadAcp())
.withGrantWriteAcp(effectiveOptions.getGrantWriteAcp())
+ .withObjectLockMode(effectiveOptions.getObjectLockMode())
+ .withRetainUntilDate(effectiveOptions.getRetainUntilDate())
+ .withLegalHoldStatus(effectiveOptions.getLegalHoldStatus())
.withChecksumAlgorithm(copyChecksumAlgorithm != null ? copyChecksumAlgorithm.name() : null)
.withTagging(effectiveTags)
.withIfMatch(effectiveOptions.getIfMatch())
diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/model/CopyObjectOptions.java b/src/main/java/io/github/hectorvent/floci/services/s3/model/CopyObjectOptions.java
index d8b4af53ad..d47a7d8255 100644
--- a/src/main/java/io/github/hectorvent/floci/services/s3/model/CopyObjectOptions.java
+++ b/src/main/java/io/github/hectorvent/floci/services/s3/model/CopyObjectOptions.java
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.s3.model;
+import java.time.Instant;
import java.util.Map;
public class CopyObjectOptions {
@@ -26,6 +27,10 @@ public class CopyObjectOptions {
private String grantFullControl;
private String grantReadAcp;
private String grantWriteAcp;
+ // The Object Lock settings the new object gets; the source's are not copied.
+ private String objectLockMode;
+ private Instant retainUntilDate;
+ private String legalHoldStatus;
private String checksumAlgorithm;
// Whether annotations travel with the copy: COPY (the default) or EXCLUDE.
private String annotationDirective;
@@ -103,6 +108,15 @@ public class CopyObjectOptions {
public String getGrantWriteAcp() { return grantWriteAcp; }
public CopyObjectOptions withGrantWriteAcp(String grantWriteAcp) { this.grantWriteAcp = grantWriteAcp; return this; }
+ public String getObjectLockMode() { return objectLockMode; }
+ public CopyObjectOptions withObjectLockMode(String objectLockMode) { this.objectLockMode = objectLockMode; return this; }
+
+ public Instant getRetainUntilDate() { return retainUntilDate; }
+ public CopyObjectOptions withRetainUntilDate(Instant retainUntilDate) { this.retainUntilDate = retainUntilDate; return this; }
+
+ public String getLegalHoldStatus() { return legalHoldStatus; }
+ public CopyObjectOptions withLegalHoldStatus(String legalHoldStatus) { this.legalHoldStatus = legalHoldStatus; return this; }
+
public String getChecksumAlgorithm() { return checksumAlgorithm; }
public CopyObjectOptions withChecksumAlgorithm(String checksumAlgorithm) { this.checksumAlgorithm = checksumAlgorithm; return this; }
diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/model/MultipartUpload.java b/src/main/java/io/github/hectorvent/floci/services/s3/model/MultipartUpload.java
index dc9570a919..ccaa6f7284 100644
--- a/src/main/java/io/github/hectorvent/floci/services/s3/model/MultipartUpload.java
+++ b/src/main/java/io/github/hectorvent/floci/services/s3/model/MultipartUpload.java
@@ -22,6 +22,15 @@ public class MultipartUpload {
private String sseCustomerAlgorithm;
private String sseCustomerKeyMd5;
private String acl;
+ // The grants and Object Lock settings CreateMultipartUpload asks for, applied on completion.
+ private String grantRead;
+ private String grantWrite;
+ private String grantFullControl;
+ private String grantReadAcp;
+ private String grantWriteAcp;
+ private String objectLockMode;
+ private Instant retainUntilDate;
+ private String legalHoldStatus;
private String ownerAccountId;
private String initiatorAccountId;
private ChecksumAlgorithm checksumAlgorithm;
@@ -79,6 +88,30 @@ public class MultipartUpload {
public String getAcl() { return acl; }
public void setAcl(String acl) { this.acl = acl; }
+ public String getGrantRead() { return grantRead; }
+ public void setGrantRead(String grantRead) { this.grantRead = grantRead; }
+
+ public String getGrantWrite() { return grantWrite; }
+ public void setGrantWrite(String grantWrite) { this.grantWrite = grantWrite; }
+
+ public String getGrantFullControl() { return grantFullControl; }
+ public void setGrantFullControl(String grantFullControl) { this.grantFullControl = grantFullControl; }
+
+ public String getGrantReadAcp() { return grantReadAcp; }
+ public void setGrantReadAcp(String grantReadAcp) { this.grantReadAcp = grantReadAcp; }
+
+ public String getGrantWriteAcp() { return grantWriteAcp; }
+ public void setGrantWriteAcp(String grantWriteAcp) { this.grantWriteAcp = grantWriteAcp; }
+
+ public String getObjectLockMode() { return objectLockMode; }
+ public void setObjectLockMode(String objectLockMode) { this.objectLockMode = objectLockMode; }
+
+ public Instant getRetainUntilDate() { return retainUntilDate; }
+ public void setRetainUntilDate(Instant retainUntilDate) { this.retainUntilDate = retainUntilDate; }
+
+ public String getLegalHoldStatus() { return legalHoldStatus; }
+ public void setLegalHoldStatus(String legalHoldStatus) { this.legalHoldStatus = legalHoldStatus; }
+
public String getOwnerAccountId() { return ownerAccountId; }
public void setOwnerAccountId(String ownerAccountId) { this.ownerAccountId = ownerAccountId; }
diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3AclIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3AclIntegrationTest.java
index 7314a5be89..2fdd77c985 100644
--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3AclIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3AclIntegrationTest.java
@@ -402,4 +402,53 @@ class S3AclIntegrationTest {
.body(containsString("<Permission>FULL_CONTROL</Permission>"))
.body(not(containsString(ALL_USERS_GROUP_URI)));
}
+
+ @Test
+ @Order(18)
+ void initiateMultipartUploadAppliesExplicitGrantReadHeaderOnComplete() {
+ String uploadId = given()
+ .header("x-amz-grant-read", "uri=\"" + ALL_USERS_GROUP_URI + "\"")
+ .when()
+ .post("/" + BUCKET + "/multipart-grant.txt?uploads")
+ .then()
+ .statusCode(200)
+ .extract().xmlPath().getString("InitiateMultipartUploadResult.UploadId");
+ String partETag = given()
+ .body("part-one")
+ .when()
+ .put("/" + BUCKET + "/multipart-grant.txt?uploadId=" + uploadId + "&partNumber=1")
+ .then()
+ .statusCode(200)
+ .extract().header("ETag");
+
+ given()
+ .contentType("application/xml")
+ .body("<CompleteMultipartUpload><Part><PartNumber>1</PartNumber><ETag>" + partETag
+ + "</ETag></Part></CompleteMultipartUpload>")
+ .when()
+ .post("/" + BUCKET + "/multipart-grant.txt?uploadId=" + uploadId)
+ .then()
+ .statusCode(200);
+
+ given()
+ .when()
+ .get("/" + BUCKET + "/multipart-grant.txt?acl")
+ .then()
+ .statusCode(200)
+ .body(containsString(ALL_USERS_GROUP_URI))
+ .body(containsString("<Permission>READ</Permission>"));
+ }
+
+ @Test
+ @Order(19)
+ void initiateMultipartUploadRejectsExplicitGrantByEmailAddress() {
+ // Refused when the upload is created, as PutObject refuses it, not when it completes.
+ given()
+ .header("x-amz-grant-read", "emailAddress=\"[email protected]\"")
+ .when()
+ .post("/" + BUCKET + "/multipart-grant-email.txt?uploads")
+ .then()
+ .statusCode(501)
+ .body(containsString("NotImplemented"));
+ }
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3ObjectLockIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3ObjectLockIntegrationTest.java
index 84693c2da0..2a0f833338 100644
--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3ObjectLockIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3ObjectLockIntegrationTest.java
@@ -1,6 +1,9 @@
package io.github.hectorvent.floci.services.s3;
import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.response.Response;
+import io.restassured.response.ValidatableResponse;
+import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
@@ -390,4 +393,118 @@ class S3ObjectLockIntegrationTest {
.statusCode(403)
.body(containsString("AccessDenied"));
}
+
+ // --- Object Lock headers on CopyObject and CreateMultipartUpload ---
+
+ @Test
+ @Order(22)
+ void copyObjectAppliesItsObjectLockHeaders() {
+ given().body("source").when().put("/" + LOCK_BUCKET + "/copy-lock-source.txt").then().statusCode(200);
+
+ given()
+ .header("x-amz-copy-source", "/" + LOCK_BUCKET + "/copy-lock-source.txt")
+ .header("x-amz-object-lock-mode", "GOVERNANCE")
+ .header("x-amz-object-lock-retain-until-date", "2099-01-01T00:00:00Z")
+ .header("x-amz-object-lock-legal-hold", "ON")
+ .when()
+ .put("/" + LOCK_BUCKET + "/copy-lock-target.txt")
+ .then()
+ .statusCode(200);
+
+ assertLockedUntil2099("/" + LOCK_BUCKET + "/copy-lock-target.txt");
+ }
+
+ @Test
+ @Order(23)
+ void multipartUploadAppliesItsObjectLockHeadersOnCompletion() {
+ String path = "/" + LOCK_BUCKET + "/multipart-lock.txt";
+ String uploadId = given()
+ .header("x-amz-object-lock-mode", "GOVERNANCE")
+ .header("x-amz-object-lock-retain-until-date", "2099-01-01T00:00:00Z")
+ .header("x-amz-object-lock-legal-hold", "ON")
+ .when()
+ .post(path + "?uploads")
+ .then()
+ .statusCode(200)
+ .extract().xmlPath().getString("InitiateMultipartUploadResult.UploadId");
+ String partETag = given()
+ .body("part-one")
+ .when()
+ .put(path + "?uploadId=" + uploadId + "&partNumber=1")
+ .then()
+ .statusCode(200)
+ .extract().header("ETag");
+
+ given()
+ .contentType("application/xml")
+ .body("<CompleteMultipartUpload><Part><PartNumber>1</PartNumber><ETag>" + partETag
+ + "</ETag></Part></CompleteMultipartUpload>")
+ .when()
+ .post(path + "?uploadId=" + uploadId)
+ .then()
+ .statusCode(200);
+
+ assertLockedUntil2099(path);
+ }
+
+ @Test
+ @Order(24)
+ void objectLockHeadersAreCheckedOnEveryObjectCreation() {
+ // The errors S3 was recorded answering: a mode and a date come together, and the mode is one
+ // S3 knows. The unparseable date was not recorded, and is refused the same way.
+ String copySource = "/" + LOCK_BUCKET + "/copy-lock-source.txt";
+ for (String[] request : new String[][] {{"put", null}, {"copy", copySource}, {"upload", null}}) {
+ assertInvalidLockHeaders(request[0], request[1], "GOVERNANCE", null,
+ "x-amz-object-lock-retain-until-date", null, "must both be supplied");
+ assertInvalidLockHeaders(request[0], request[1], null, "2099-01-01T00:00:00Z",
+ "x-amz-object-lock-mode", null, "must both be supplied");
+ assertInvalidLockHeaders(request[0], request[1], "BAD-VALUE", "2099-01-01T00:00:00Z",
+ "x-amz-object-lock-mode", "BAD-VALUE", "Unknown wormMode directive.");
+ assertInvalidLockHeaders(request[0], request[1], "GOVERNANCE", "next-week",
+ "x-amz-object-lock-retain-until-date", "next-week", "ISO 8601");
+ }
+ }
+
+ /** A PutObject, a CopyObject of {@code copySource} or a CreateMultipartUpload refused for its lock headers. */
+ private static void assertInvalidLockHeaders(String operation, String copySource, String mode, String until,
+ String argumentName, String argumentValue, String message) {
+ RequestSpecification request = given();
+ if (mode != null) {
+ request = request.header("x-amz-object-lock-mode", mode);
+ }
+ if (until != null) {
+ request = request.header("x-amz-object-lock-retain-until-date", until);
+ }
+ String path = "/" + LOCK_BUCKET + "/invalid-lock-" + operation + ".txt";
+ Response response = switch (operation) {
+ case "put" -> request.body("x").when().put(path);
+ case "copy" -> request.header("x-amz-copy-source", copySource).when().put(path);
+ default -> request.when().post(path + "?uploads");
+ };
+ ValidatableResponse then = response.then()
+ .statusCode(400)
+ .body(containsString("<Code>InvalidArgument</Code>"))
+ .body(containsString(message))
+ .body(containsString("<ArgumentName>" + argumentName + "</ArgumentName>"));
+ if (argumentValue != null) {
+ then.body(containsString("<ArgumentValue>" + argumentValue + "</ArgumentValue>"));
+ }
+ }
+
+ /** The object holds the GOVERNANCE retention until 2099 and the legal hold its request set. */
+ private static void assertLockedUntil2099(String path) {
+ given()
+ .when()
+ .get(path + "?retention")
+ .then()
+ .statusCode(200)
+ .body(containsString("<Mode>GOVERNANCE</Mode>"))
+ .body(containsString("<RetainUntilDate>2099-01-01T00:00:00"));
+ given()
+ .when()
+ .get(path + "?legal-hold")
+ .then()
+ .statusCode(200)
+ .body(containsString("<Status>ON</Status>"));
+ }
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3OwnershipControlsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3OwnershipControlsIntegrationTest.java
index de90bbf0aa..839f089009 100644
--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3OwnershipControlsIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3OwnershipControlsIntegrationTest.java
@@ -166,6 +166,14 @@ class S3OwnershipControlsIntegrationTest {
.statusCode(400)
.body(containsString("AccessControlListNotSupported"));
+ given()
+ .header("x-amz-grant-read", "uri=\"http://acs.amazonaws.com/groups/global/AllUsers\"")
+ .when()
+ .post("/" + BUCKET + "/rejected-multipart-grant?uploads")
+ .then()
+ .statusCode(400)
+ .body(containsString("AccessControlListNotSupported"));
+
given()
.body("new object")
.when()