mirror of
https://github.com/floci-io/floci.git
synced 2026-12-03 10:17: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
@@ -0,0 +1,32 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* The canonical user ID is the S3 wire identity of an account: 64 lowercase hex characters,
|
||||
* stable for the same account and distinct per account, whatever the partition or storage mode.
|
||||
*/
|
||||
class AwsCanonicalUserIdTest {
|
||||
|
||||
@Test
|
||||
void isSixtyFourLowercaseHexCharacters() {
|
||||
assertTrue(AwsCanonicalUserId.forAccount("000000000000").matches("[0-9a-f]{64}"));
|
||||
assertTrue(AwsCanonicalUserId.forAccount("123456789012").matches("[0-9a-f]{64}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void isStableForTheSameAccount() {
|
||||
assertEquals(AwsCanonicalUserId.forAccount("000000000000"),
|
||||
AwsCanonicalUserId.forAccount("000000000000"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void differsPerAccount() {
|
||||
assertNotEquals(AwsCanonicalUserId.forAccount("000000000000"),
|
||||
AwsCanonicalUserId.forAccount("000000000001"));
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.iam;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.core.common.AwsCanonicalUserId;
|
||||
import io.github.hectorvent.floci.core.common.AwsServiceNamespaces;
|
||||
import io.github.hectorvent.floci.services.iam.IamPolicyEvaluator.Decision;
|
||||
import io.github.hectorvent.floci.services.iam.IamPolicyEvaluator.ResourceAccountRelationship;
|
||||
@@ -898,8 +899,11 @@ class IamPolicyEvaluatorTest {
|
||||
@Test
|
||||
void aCanonicalUserNamesTheIamIdentitiesOfItsAccount() {
|
||||
// S3 bucket policies can name an account by its canonical user ID (IAM User Guide, "AWS
|
||||
// account principals"); Floci's canonical ID for an account is the account id.
|
||||
String canonical = resourcePolicy("Allow", "\"Principal\":{\"CanonicalUser\":\"123456789012\"}");
|
||||
// account principals"): the 64-hex value S3 reports as owner, which Floci derives from
|
||||
// the account. The account ID itself still matches, for policies written when Floci
|
||||
// reported the account as the canonical ID.
|
||||
String canonical = resourcePolicy("Allow", "\"Principal\":{\"CanonicalUser\":\""
|
||||
+ AwsCanonicalUserId.forAccount("123456789012") + "\"}");
|
||||
assertEquals(ResourcePolicyDecision.ALLOW_ACCOUNT,
|
||||
resourceDecision(canonical, RequestPrincipal.iam("arn:aws:iam::123456789012:user/alice")));
|
||||
assertEquals(ResourcePolicyDecision.ALLOW_ACCOUNT, resourceDecision(canonical, RequestPrincipal.roleSession(
|
||||
@@ -911,6 +915,13 @@ class IamPolicyEvaluatorTest {
|
||||
assertEquals(ResourcePolicyDecision.NEUTRAL, resourceDecision(canonical, RequestPrincipal.anonymous()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anAccountWrittenAsTheCanonicalIdStillMatches() {
|
||||
String legacy = resourcePolicy("Allow", "\"Principal\":{\"CanonicalUser\":\"123456789012\"}");
|
||||
assertEquals(ResourcePolicyDecision.ALLOW_ACCOUNT,
|
||||
resourceDecision(legacy, RequestPrincipal.iam("arn:aws:iam::123456789012:user/alice")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void onlyAGrantNamingTheUserExactlyIsDirect() {
|
||||
// A grant names a user directly by its exact ARN, or by "*" with aws:PrincipalArn pinned to
|
||||
|
||||
+45
@@ -1,5 +1,6 @@
|
||||
package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsCanonicalUserId;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
@@ -114,6 +115,39 @@ class S3AclPublicAccessEvaluatorTest {
|
||||
"http://acs.amazonaws.com/groups/s3/LogDelivery", "WRITE"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
void ownerCanonicalUserGrantIsNotANonOwnerGrant() {
|
||||
String ownerAccount = "000000000000";
|
||||
String canonicalId = AwsCanonicalUserId.forAccount(ownerAccount);
|
||||
|
||||
assertFalse(S3AclPublicAccessEvaluator.aclGrantsNonOwner(acl(
|
||||
canonicalUserGrant(canonicalId, "FULL_CONTROL")), ownerAccount));
|
||||
}
|
||||
|
||||
@Test
|
||||
void ownerAccountGrantStillMatchesForAclsWrittenBeforeCanonicalIds() {
|
||||
String ownerAccount = "000000000000";
|
||||
|
||||
assertFalse(S3AclPublicAccessEvaluator.aclGrantsNonOwner(acl(
|
||||
canonicalUserGrant(ownerAccount, "FULL_CONTROL")), ownerAccount));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anotherCanonicalUserGrantIsANonOwnerGrant() {
|
||||
String ownerAccount = "000000000000";
|
||||
|
||||
assertTrue(S3AclPublicAccessEvaluator.aclGrantsNonOwner(acl(
|
||||
canonicalUserGrant(AwsCanonicalUserId.forAccount("111111111111"), "READ")),
|
||||
ownerAccount));
|
||||
}
|
||||
|
||||
@Test
|
||||
void grantlessAclGrantsNonOwner() {
|
||||
assertTrue(S3AclPublicAccessEvaluator.aclGrantsNonOwner(
|
||||
"<AccessControlPolicy><AccessControlList/></AccessControlPolicy>",
|
||||
"000000000000"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void canonicalUserOnlyAclIsNotPublic() {
|
||||
String acl = """
|
||||
@@ -160,4 +194,15 @@ class S3AclPublicAccessEvaluatorTest {
|
||||
</Grant>
|
||||
""".formatted(groupUri, permission);
|
||||
}
|
||||
|
||||
private static String canonicalUserGrant(String id, String permission) {
|
||||
return """
|
||||
<Grant>
|
||||
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
|
||||
<ID>%s</ID>
|
||||
</Grantee>
|
||||
<Permission>%s</Permission>
|
||||
</Grant>
|
||||
""".formatted(id, permission);
|
||||
}
|
||||
}
|
||||
+13
-2
@@ -1,5 +1,6 @@
|
||||
package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsCanonicalUserId;
|
||||
import io.github.hectorvent.floci.testing.EnforcementFixtures;
|
||||
import io.github.hectorvent.floci.testing.PartitionCleanup;
|
||||
import io.github.hectorvent.floci.testing.S3IamEnforcementProfile;
|
||||
@@ -357,8 +358,10 @@ class S3BucketPolicyEnforcementIntegrationTest {
|
||||
|
||||
@Test
|
||||
void aBucketPolicyNamingAnAccountByItsCanonicalIdGrantsThatAccount() {
|
||||
// A bucket policy can name an account by its S3 canonical user ID (IAM User Guide, "AWS account
|
||||
// principals"), and Floci's canonical ID for an account is its account id.
|
||||
// A bucket policy can name an account by its S3 canonical user ID (IAM User Guide, "AWS
|
||||
// account principals"): the 64-hex value S3 reports as owner, which Floci derives from
|
||||
// the account. The account ID itself still matches, for policies written when Floci
|
||||
// reported the account as the canonical ID.
|
||||
String suffix = UUID.randomUUID().toString().substring(0, 8);
|
||||
String source = "bp-canonical-" + suffix;
|
||||
S3RequestSigner owner = sourceBucketInAccountA(source);
|
||||
@@ -371,6 +374,14 @@ class S3BucketPolicyEnforcementIntegrationTest {
|
||||
|
||||
allowGetObject(owner, source, "{\"CanonicalUser\":\"" + ACCOUNT_B + "\"}");
|
||||
assertReadAndCopy(reader, source, destination, 200);
|
||||
|
||||
allowGetObject(owner, source,
|
||||
"{\"CanonicalUser\":\"" + AwsCanonicalUserId.forAccount(ACCOUNT_B) + "\"}");
|
||||
assertReadAndCopy(reader, source, destination, 200);
|
||||
|
||||
allowGetObject(owner, source,
|
||||
"{\"CanonicalUser\":\"" + AwsCanonicalUserId.forAccount(ACCOUNT_A) + "\"}");
|
||||
assertReadAndCopy(reader, source, destination, 403);
|
||||
}
|
||||
|
||||
/** Creates a bucket in account A holding {@code o.txt}, and returns its owner, an account-A administrator. */
|
||||
|
||||
+5
-4
@@ -1,5 +1,6 @@
|
||||
package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsCanonicalUserId;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RequestContext;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
@@ -351,15 +352,15 @@ class S3GlobalBucketNamespaceTest {
|
||||
|
||||
String defaultAcl = globalNs.getObjectAcl(
|
||||
"shared-metadata-bucket", "object.txt", versionId);
|
||||
assertTrue(defaultAcl.contains(ACCOUNT_A));
|
||||
assertFalse(defaultAcl.contains(ACCOUNT_B));
|
||||
assertTrue(defaultAcl.contains(AwsCanonicalUserId.forAccount(ACCOUNT_A)));
|
||||
assertFalse(defaultAcl.contains(AwsCanonicalUserId.forAccount(ACCOUNT_B)));
|
||||
globalNs.putObjectAcl(
|
||||
"shared-metadata-bucket", "object.txt", versionId,
|
||||
"", "public-read", null, null, null, null, null);
|
||||
String storedAcl = globalNs.getObjectAcl(
|
||||
"shared-metadata-bucket", "object.txt", versionId);
|
||||
assertTrue(storedAcl.contains(ACCOUNT_A));
|
||||
assertFalse(storedAcl.contains(ACCOUNT_B));
|
||||
assertTrue(storedAcl.contains(AwsCanonicalUserId.forAccount(ACCOUNT_A)));
|
||||
assertFalse(storedAcl.contains(AwsCanonicalUserId.forAccount(ACCOUNT_B)));
|
||||
|
||||
globalNs.deleteObjectTagging("shared-metadata-bucket", "object.txt");
|
||||
assertTrue(globalNs.getObjectTagging("shared-metadata-bucket", "object.txt").isEmpty());
|
||||
|
||||
+81
-13
@@ -1,10 +1,12 @@
|
||||
package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsCanonicalUserId;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.matchesPattern;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
@QuarkusTest
|
||||
@@ -14,32 +16,93 @@ class S3OwnerIdentityIntegrationTest {
|
||||
private static final String ACCOUNT_TWO = "000000000012";
|
||||
|
||||
@Test
|
||||
void listBucketsOwnerMatchesTheCallerAccountAndBucketAcl() {
|
||||
void listBucketsOwnerIsTheCallersCanonicalUserId() {
|
||||
String bucket = "owner-identity-list-bucket";
|
||||
createBucket(ACCOUNT_ONE, bucket);
|
||||
String canonicalOne = canonical(ACCOUNT_ONE);
|
||||
|
||||
given().header("Authorization", authorization(ACCOUNT_ONE))
|
||||
.when().get("/")
|
||||
.then().statusCode(200)
|
||||
.body(containsString("<Owner><ID>" + ACCOUNT_ONE + "</ID><DisplayName>floci</DisplayName></Owner>"))
|
||||
.body(containsString("<Owner><ID>" + canonicalOne
|
||||
+ "</ID><DisplayName>floci</DisplayName></Owner>"))
|
||||
.body(matchesPattern(".*<Owner><ID>[0-9a-f]{64}</ID>.*"))
|
||||
.body(containsString("<Name>" + bucket + "</Name>"));
|
||||
|
||||
given().header("Authorization", authorization(ACCOUNT_ONE))
|
||||
.when().get("/" + bucket + "?acl")
|
||||
.then().statusCode(200)
|
||||
.body(containsString("<Owner><ID>" + ACCOUNT_ONE + "</ID><DisplayName>floci</DisplayName></Owner>"));
|
||||
|
||||
given().header("Authorization", authorization(ACCOUNT_TWO))
|
||||
.when().get("/")
|
||||
.then().statusCode(200)
|
||||
.body(containsString("<Owner><ID>" + ACCOUNT_TWO + "</ID><DisplayName>floci</DisplayName></Owner>"))
|
||||
.body(containsString("<Owner><ID>" + canonical(ACCOUNT_TWO)
|
||||
+ "</ID><DisplayName>floci</DisplayName></Owner>"))
|
||||
.body(not(containsString("<Owner><ID>" + canonicalOne + "</ID>")))
|
||||
.body(not(containsString("<Name>" + bucket + "</Name>")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listPartsOwnerAndInitiatorUseTheUploadAccount() {
|
||||
void defaultBucketAclNamesTheOwnerByCanonicalUserId() {
|
||||
String bucket = "owner-identity-bucket-acl";
|
||||
createBucket(ACCOUNT_ONE, bucket);
|
||||
String canonicalOne = canonical(ACCOUNT_ONE);
|
||||
|
||||
given().header("Authorization", authorization(ACCOUNT_ONE))
|
||||
.when().get("/" + bucket + "?acl")
|
||||
.then().statusCode(200)
|
||||
.body(containsString("<Owner><ID>" + canonicalOne
|
||||
+ "</ID><DisplayName>floci</DisplayName></Owner>"))
|
||||
.body(containsString("xsi:type=\"CanonicalUser\"><ID>" + canonicalOne + "</ID>"))
|
||||
.body(not(containsString("<ID>" + ACCOUNT_ONE + "</ID>")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultObjectAclNamesTheOwnerByCanonicalUserId() {
|
||||
String bucket = "owner-identity-object-acl";
|
||||
createBucket(ACCOUNT_ONE, bucket);
|
||||
|
||||
given().header("Authorization", authorization(ACCOUNT_ONE))
|
||||
.when().put("/" + bucket + "/key.txt")
|
||||
.then().statusCode(200);
|
||||
|
||||
String canonicalOne = canonical(ACCOUNT_ONE);
|
||||
given().header("Authorization", authorization(ACCOUNT_ONE))
|
||||
.when().get("/" + bucket + "/key.txt?acl")
|
||||
.then().statusCode(200)
|
||||
.body(containsString("<Owner><ID>" + canonicalOne
|
||||
+ "</ID><DisplayName>floci</DisplayName></Owner>"))
|
||||
.body(containsString("xsi:type=\"CanonicalUser\"><ID>" + canonicalOne + "</ID>"))
|
||||
.body(not(containsString("<ID>" + ACCOUNT_ONE + "</ID>")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void cannedObjectAclKeepsOnlyTheOwnerGrantCanonical() {
|
||||
String bucket = "owner-identity-canned-acl";
|
||||
createBucket(ACCOUNT_TWO, bucket);
|
||||
|
||||
given().header("Authorization", authorization(ACCOUNT_TWO))
|
||||
.body("<OwnershipControls><Rule><ObjectOwnership>ObjectWriter</ObjectOwnership></Rule></OwnershipControls>")
|
||||
.when().put("/" + bucket + "?ownershipControls")
|
||||
.then().statusCode(200);
|
||||
|
||||
given().header("Authorization", authorization(ACCOUNT_TWO))
|
||||
.header("x-amz-acl", "public-read")
|
||||
.when().put("/" + bucket + "/public.txt")
|
||||
.then().statusCode(200);
|
||||
|
||||
String canonicalTwo = canonical(ACCOUNT_TWO);
|
||||
given().header("Authorization", authorization(ACCOUNT_TWO))
|
||||
.when().get("/" + bucket + "/public.txt?acl")
|
||||
.then().statusCode(200)
|
||||
.body(containsString("<Owner><ID>" + canonicalTwo
|
||||
+ "</ID><DisplayName>floci</DisplayName></Owner>"))
|
||||
.body(containsString("xsi:type=\"CanonicalUser\"><ID>" + canonicalTwo + "</ID>"))
|
||||
.body(containsString("<URI>http://acs.amazonaws.com/groups/global/AllUsers</URI>"))
|
||||
.body(not(containsString("<ID>" + ACCOUNT_TWO + "</ID>")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listPartsOwnerAndInitiatorUseTheUploadAccountsCanonicalUserId() {
|
||||
String bucket = "owner-identity-parts-bucket";
|
||||
createBucket(ACCOUNT_TWO, bucket);
|
||||
String canonicalTwo = canonical(ACCOUNT_TWO);
|
||||
|
||||
String uploadId = given().header("Authorization", authorization(ACCOUNT_TWO))
|
||||
.when().post("/" + bucket + "/part.bin?uploads")
|
||||
@@ -49,10 +112,11 @@ class S3OwnerIdentityIntegrationTest {
|
||||
given().header("Authorization", authorization(ACCOUNT_TWO))
|
||||
.when().get("/" + bucket + "/part.bin?uploadId=" + uploadId)
|
||||
.then().statusCode(200)
|
||||
.body(containsString("<Initiator><ID>" + ACCOUNT_TWO
|
||||
.body(containsString("<Initiator><ID>" + canonicalTwo
|
||||
+ "</ID><DisplayName>floci</DisplayName></Initiator>"))
|
||||
.body(containsString("<Owner><ID>" + ACCOUNT_TWO
|
||||
+ "</ID><DisplayName>floci</DisplayName></Owner>"));
|
||||
.body(containsString("<Owner><ID>" + canonicalTwo
|
||||
+ "</ID><DisplayName>floci</DisplayName></Owner>"))
|
||||
.body(not(containsString("<ID>" + ACCOUNT_TWO + "</ID>")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,10 +158,14 @@ class S3OwnerIdentityIntegrationTest {
|
||||
given().header("Authorization", authorization(ACCOUNT_TWO))
|
||||
.when().get("/" + bucket + "/part.bin?uploadId=" + secondUploadId)
|
||||
.then().statusCode(200)
|
||||
.body(containsString("<Owner><ID>" + ACCOUNT_TWO
|
||||
.body(containsString("<Owner><ID>" + canonical(ACCOUNT_TWO)
|
||||
+ "</ID><DisplayName>floci</DisplayName></Owner>"));
|
||||
}
|
||||
|
||||
private static String canonical(String account) {
|
||||
return AwsCanonicalUserId.forAccount(account);
|
||||
}
|
||||
|
||||
private static void createBucket(String account, String bucket) {
|
||||
given().header("Authorization", authorization(account))
|
||||
.when().put("/" + bucket)
|
||||
|
||||
+5
@@ -1,5 +1,6 @@
|
||||
package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsCanonicalUserId;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
@@ -175,6 +176,10 @@ class S3OwnershipControlsIntegrationTest {
|
||||
given().header("x-amz-grant-full-control", "id=\"000000000000\"")
|
||||
.when().post("/" + bucket + "/accepted?uploads")
|
||||
.then().statusCode(200).body(containsString("<UploadId>"));
|
||||
given().header("x-amz-grant-full-control",
|
||||
"id=\"" + AwsCanonicalUserId.forAccount("000000000000") + "\"")
|
||||
.when().post("/" + bucket + "/accepted-canonical?uploads")
|
||||
.then().statusCode(200).body(containsString("<UploadId>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user