mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(partition): serve a pseudo signing region as its partition's global region (#5233)
A request whose SigV4 scope named a <partition>-global pseudo-region (aws-cn-global) kept the label as its region, so regional services stored state under it and minted ARNs such as arn:aws-cn:sqs:aws-cn-global:... for a region that does not exist. AWS never signs with a pseudo-region: endpoints.json maps each to a real credential scope region. RegionResolver now serves such a scope as the partition's implicit global region (aws-cn-global becomes cn-northwest-1) wherever it reads the region from a request. With floci.partitions.allow-unknown-regions in a non-commercial deployment, an unknown label was scoped to the deployment's partition but RegionResolver.buildArn minted it as aws. buildArn now uses the same partition as the request. ARNs built directly with Arn.of keep the commercial fallback, which partitions.md now states.
This commit is contained in:
1 parent
c0b2b299b0
commit
e1cd6fe6d4
5 files changed
+99
-11
No files matched your search
@@ -115,7 +115,7 @@ class AccountContextFilterTest {
|
||||
filter.filter(mockContext(
|
||||
"AWS4-HMAC-SHA256 Credential=000000000001/20260617/aws-cn-global/iam/aws4_request, SignedHeaders=host, Signature=abc",
|
||||
null));
|
||||
assertEquals("aws-cn-global", requestContext.getRegion());
|
||||
assertEquals("cn-northwest-1", requestContext.getRegion(), "a pseudo-region is never a request region");
|
||||
assertEquals("aws-cn", requestContext.getPartition());
|
||||
}
|
||||
|
||||
|
||||
+31
@@ -127,6 +127,37 @@ class PartitionArnMintingIntegrationTest {
|
||||
assertEquals("arn:aws-cn:ssm:" + REGION + ":000000000000:parameter" + name, arn);
|
||||
}
|
||||
|
||||
/**
|
||||
* A hand-rolled client that signs with the {@code aws-cn-global} pseudo-region is served in
|
||||
* China's implicit global region: the parameter lands in {@code cn-northwest-1}, is readable
|
||||
* there, and no ARN carries the pseudo-region.
|
||||
*/
|
||||
@Test
|
||||
void aPseudoSigningRegionIsServedAsThePartitionsGlobalRegion() {
|
||||
String name = "/partition-pseudo/" + Long.toString(System.nanoTime(), 36);
|
||||
given()
|
||||
.header("Authorization", PartitionMatrix.sigV4Auth("aws-cn-global", "ssm"))
|
||||
.header("X-Amz-Target", "AmazonSSM.PutParameter")
|
||||
.contentType(JSON_1_1)
|
||||
.body("{\"Name\":\"" + name + "\",\"Type\":\"String\",\"Value\":\"v\"}")
|
||||
.when().post("/").then().statusCode(200);
|
||||
cleanup.register(() -> given()
|
||||
.header("Authorization", PartitionMatrix.sigV4Auth("cn-northwest-1", "ssm"))
|
||||
.header("X-Amz-Target", "AmazonSSM.DeleteParameter")
|
||||
.contentType(JSON_1_1)
|
||||
.body("{\"Name\":\"" + name + "\"}")
|
||||
.when().post("/"));
|
||||
|
||||
String arn = given()
|
||||
.header("Authorization", PartitionMatrix.sigV4Auth("cn-northwest-1", "ssm"))
|
||||
.header("X-Amz-Target", "AmazonSSM.GetParameter")
|
||||
.contentType(JSON_1_1)
|
||||
.body("{\"Name\":\"" + name + "\"}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.extract().jsonPath().getString("Parameter.ARN");
|
||||
assertEquals("arn:aws-cn:ssm:cn-northwest-1:000000000000:parameter" + name, arn);
|
||||
}
|
||||
|
||||
@Test
|
||||
void serviceCatalogPortfolioArnIsMintedInTheRequestPartition() {
|
||||
String token = Long.toString(System.nanoTime(), 36);
|
||||
|
||||
@@ -220,6 +220,37 @@ class RegionResolverTest {
|
||||
assertEquals("aws", resolver.partitionForRegion("aws-global"));
|
||||
}
|
||||
|
||||
/**
|
||||
* AWS never signs with a pseudo-region, so one named in a credential scope is served as its
|
||||
* partition's implicit global region instead of becoming a regional namespace of its own.
|
||||
*/
|
||||
@Test
|
||||
void aPseudoSigningRegionIsServedAsItsPartitionsGlobalRegion() {
|
||||
assertEquals("cn-northwest-1", resolver.resolveRegionFromAuth(
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260617/aws-cn-global/sqs/aws4_request, SignedHeaders=host, Signature=abc"));
|
||||
assertEquals("us-east-1", resolver.resolveRegionFromAuthOrNull(
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260617/aws-global/sqs/aws4_request, SignedHeaders=host, Signature=abc"));
|
||||
assertEquals("us-gov-west-1",
|
||||
resolver.resolveRegionFromPresignedCredential("AKID/20260617/aws-us-gov-global/s3/aws4_request"));
|
||||
assertEquals("cn-north-1", resolver.resolveRegionFromAuth(
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260617/cn-north-1/sqs/aws4_request, SignedHeaders=host, Signature=abc"));
|
||||
assertEquals("xx-nowhere-9", resolver.resolveRegionFromAuth(
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260617/xx-nowhere-9/sqs/aws4_request, SignedHeaders=host, Signature=abc"),
|
||||
"an unknown label stays raw so the unknown-region guard can name it");
|
||||
}
|
||||
|
||||
/**
|
||||
* A region no partition publishes is scoped to the deployment's partition when served
|
||||
* ({@code floci.partitions.allow-unknown-regions}), and its ARNs must agree with that scope.
|
||||
*/
|
||||
@Test
|
||||
void buildArnMintsAnUnknownRegionInTheDeploymentPartition() {
|
||||
RegionResolver china = new RegionResolver("cn-north-1", "000000000000");
|
||||
assertEquals("arn:aws-cn:sqs:xx-nowhere-9:000000000000:q", china.buildArn("sqs", "xx-nowhere-9", "q"));
|
||||
assertEquals("arn:aws:sqs:us-east-1:000000000000:q", china.buildArn("sqs", "us-east-1", "q"));
|
||||
assertEquals("arn:aws:sqs:xx-nowhere-9:000000000000:q", resolver.buildArn("sqs", "xx-nowhere-9", "q"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPartitionOutsideARequestIsTheDeploymentPartition() {
|
||||
assertEquals("aws", resolver.getPartition());
|
||||
|
||||
Reference in new issue
Block a user