mirror of
https://github.com/floci-io/floci.git
synced 2026-11-28 16:11:48 -05:00
fix(s3): report the owner and ACL grantees as a canonical user id (#6549)
* fix(s3): report the owner and ACL grantees as a canonical user id S3 reported the 12-digit account id where AWS reports the account's canonical user id: the bucket owner in ListBuckets, the owner and the multipart initiator in ListParts, and every CanonicalUser grantee and Owner the ACL responses name. All of them now answer the canonical id, a 64-character lowercase hex string Floci derives as the SHA-256 of the account id, so the same account answers the same id across calls, restarts and storage modes and two accounts never share one. The account id stays the internal identity; only the emitted value changes, and ACLs persisted by an older Floci keep serving the form they store. Owner evaluations, the public-access checks and bucket-policy CanonicalUser principals accept the canonical id and the account id alike, so stored policies and scripts written against the old form keep working. Closes #6242 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * test(s3): say why the cleanup catches stay silent The two new compatibility cleanup catches swallowed without a word, which the guide allows only for a named, explained tolerance. Both now name the reason: cleanup must not mask the assertion. Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * test(s3): expect the canonical owner in the namespace ACL assertions The cross-account object metadata test still expected the raw account id in the ACLs, which the canonical owner id broke, and its ACCOUNT_B assertFalse checks passed whatever the ACL held. All four assertions now name the accounts the way the ACLs do, through AwsCanonicalUserId. Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> * test(s3): share the compatibility cleanup between the two tests The explained cleanup catches landed on the wrong method, a helper that was already on main, leaving the new canonical owner test with bare catches. One deleteObjectAndBucketQuietly helper now holds the commented catches and serves both tests. Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> --------- Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
1 parent
89be5c1742
commit
56196fec1c
15 files changed
+331
-45
No files matched your search
@@ -5,6 +5,7 @@ import software.amazon.awssdk.core.ResponseBytes;
|
||||
import software.amazon.awssdk.core.ResponseInputStream;
|
||||
import software.amazon.awssdk.core.sync.RequestBody;
|
||||
import software.amazon.awssdk.services.s3.S3Client;
|
||||
import software.amazon.awssdk.services.s3.model.AbortMultipartUploadRequest;
|
||||
import software.amazon.awssdk.services.s3.model.BucketLocationConstraint;
|
||||
import software.amazon.awssdk.services.s3.model.CompleteMultipartUploadRequest;
|
||||
import software.amazon.awssdk.services.s3.model.CompletedMultipartUpload;
|
||||
@@ -21,10 +22,14 @@ import software.amazon.awssdk.services.s3.model.DeleteObjectRequest;
|
||||
import software.amazon.awssdk.services.s3.model.DeleteObjectTaggingRequest;
|
||||
import software.amazon.awssdk.services.s3.model.DeleteObjectsRequest;
|
||||
import software.amazon.awssdk.services.s3.model.DeleteObjectsResponse;
|
||||
import software.amazon.awssdk.services.s3.model.GetBucketAclRequest;
|
||||
import software.amazon.awssdk.services.s3.model.GetBucketAclResponse;
|
||||
import software.amazon.awssdk.services.s3.model.GetBucketLocationRequest;
|
||||
import software.amazon.awssdk.services.s3.model.GetBucketLocationResponse;
|
||||
import software.amazon.awssdk.services.s3.model.GetBucketTaggingRequest;
|
||||
import software.amazon.awssdk.services.s3.model.GetBucketTaggingResponse;
|
||||
import software.amazon.awssdk.services.s3.model.GetObjectAclRequest;
|
||||
import software.amazon.awssdk.services.s3.model.GetObjectAclResponse;
|
||||
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
|
||||
import software.amazon.awssdk.services.s3.model.GetObjectResponse;
|
||||
import software.amazon.awssdk.services.s3.model.GetObjectTaggingRequest;
|
||||
@@ -36,14 +41,18 @@ import software.amazon.awssdk.services.s3.model.HeadObjectResponse;
|
||||
import software.amazon.awssdk.services.s3.model.ListBucketsResponse;
|
||||
import software.amazon.awssdk.services.s3.model.ListObjectsV2Request;
|
||||
import software.amazon.awssdk.services.s3.model.ListObjectsV2Response;
|
||||
import software.amazon.awssdk.services.s3.model.ListPartsRequest;
|
||||
import software.amazon.awssdk.services.s3.model.ListPartsResponse;
|
||||
import software.amazon.awssdk.services.s3.model.NoSuchBucketException;
|
||||
import software.amazon.awssdk.services.s3.model.ObjectIdentifier;
|
||||
import software.amazon.awssdk.services.s3.model.Permission;
|
||||
import software.amazon.awssdk.services.s3.model.PutBucketTaggingRequest;
|
||||
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
|
||||
import software.amazon.awssdk.services.s3.model.PutObjectResponse;
|
||||
import software.amazon.awssdk.services.s3.model.PutObjectTaggingRequest;
|
||||
import software.amazon.awssdk.services.s3.model.S3Exception;
|
||||
import software.amazon.awssdk.services.s3.model.Tagging;
|
||||
import software.amazon.awssdk.services.s3.model.Type;
|
||||
import software.amazon.awssdk.services.s3.model.UploadPartRequest;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -612,6 +621,56 @@ class S3Test {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(35)
|
||||
void ownerAndGranteesAreTheAccountsCanonicalUserId() {
|
||||
// S3 identifies the owner of buckets and objects, and CanonicalUser ACL grantees, by the
|
||||
// account's 64-hex canonical user ID, the same value in ListBuckets, both ACLs and the
|
||||
// multipart listing. The value itself is opaque on AWS, so the SDK test pins the form
|
||||
// and the cross-response identity, not a specific derivation.
|
||||
String bucket = TestFixtures.uniqueName("canonical-owner-bucket");
|
||||
String key = "owned.txt";
|
||||
String multipartKey = "owned.bin";
|
||||
s3.createBucket(CreateBucketRequest.builder().bucket(bucket).build());
|
||||
try {
|
||||
String ownerId = s3.listBuckets().owner().id();
|
||||
assertThat(ownerId).matches("[0-9a-f]{64}");
|
||||
|
||||
GetBucketAclResponse bucketAcl = s3.getBucketAcl(
|
||||
GetBucketAclRequest.builder().bucket(bucket).build());
|
||||
assertThat(bucketAcl.owner().id()).isEqualTo(ownerId);
|
||||
assertThat(bucketAcl.grants()).singleElement().satisfies(grant -> {
|
||||
assertThat(grant.grantee().id()).isEqualTo(ownerId);
|
||||
assertThat(grant.grantee().type()).isEqualTo(Type.CANONICAL_USER);
|
||||
assertThat(grant.permission()).isEqualTo(Permission.FULL_CONTROL);
|
||||
});
|
||||
|
||||
s3.putObject(PutObjectRequest.builder().bucket(bucket).key(key).build(),
|
||||
RequestBody.fromString(CONTENT));
|
||||
GetObjectAclResponse objectAcl = s3.getObjectAcl(
|
||||
GetObjectAclRequest.builder().bucket(bucket).key(key).build());
|
||||
assertThat(objectAcl.owner().id()).isEqualTo(ownerId);
|
||||
assertThat(objectAcl.grants()).singleElement().satisfies(grant -> {
|
||||
assertThat(grant.grantee().id()).isEqualTo(ownerId);
|
||||
assertThat(grant.grantee().type()).isEqualTo(Type.CANONICAL_USER);
|
||||
assertThat(grant.permission()).isEqualTo(Permission.FULL_CONTROL);
|
||||
});
|
||||
|
||||
String uploadId = s3.createMultipartUpload(CreateMultipartUploadRequest.builder()
|
||||
.bucket(bucket).key(multipartKey).build()).uploadId();
|
||||
s3.uploadPart(UploadPartRequest.builder().bucket(bucket).key(multipartKey)
|
||||
.uploadId(uploadId).partNumber(1).build(), RequestBody.fromString("part"));
|
||||
ListPartsResponse parts = s3.listParts(ListPartsRequest.builder()
|
||||
.bucket(bucket).key(multipartKey).uploadId(uploadId).build());
|
||||
assertThat(parts.initiator().id()).isEqualTo(ownerId);
|
||||
assertThat(parts.owner().id()).isEqualTo(ownerId);
|
||||
s3.abortMultipartUpload(AbortMultipartUploadRequest.builder()
|
||||
.bucket(bucket).key(multipartKey).uploadId(uploadId).build());
|
||||
} finally {
|
||||
deleteObjectAndBucketQuietly(bucket, key);
|
||||
}
|
||||
}
|
||||
|
||||
private void assertInlineTaggingHeaderRejected(String rawTaggingHeader, int expectedStatus, String expectedErrorCode) {
|
||||
String bucket = TestFixtures.uniqueName("inline-tag-reject");
|
||||
String key = "rejected.txt";
|
||||
@@ -630,12 +689,20 @@ class S3Test {
|
||||
assertThat(s3e.awsErrorDetails().errorCode()).isEqualTo(expectedErrorCode);
|
||||
});
|
||||
} finally {
|
||||
try {
|
||||
s3.deleteObject(DeleteObjectRequest.builder().bucket(bucket).key(key).build());
|
||||
} catch (Exception ignored) {}
|
||||
try {
|
||||
s3.deleteBucket(DeleteBucketRequest.builder().bucket(bucket).build());
|
||||
} catch (Exception ignored) {}
|
||||
deleteObjectAndBucketQuietly(bucket, key);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteObjectAndBucketQuietly(String bucket, String key) {
|
||||
try {
|
||||
s3.deleteObject(DeleteObjectRequest.builder().bucket(bucket).key(key).build());
|
||||
} catch (Exception ignored) {
|
||||
// cleanup only: an already-deleted object must not mask the assertion
|
||||
}
|
||||
try {
|
||||
s3.deleteBucket(DeleteBucketRequest.builder().bucket(bucket).build());
|
||||
} catch (Exception ignored) {
|
||||
// cleanup only: an already-emptied bucket must not mask the assertion
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user