mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(ec2): Returning origin-facing prefix list for ec2 (#8652)
DescribeManagedPrefixLists and GetManagedPrefixListEntries now include the AWS-managed com.amazonaws.global.cloudfront.origin-facing list (pl-3b927c52) with the 49 CLOUDFRONT_ORIGIN_FACING IPv4 ranges of ip-ranges.json, in commercial-partition regions only; China, GovCloud and the other partitions keep only the S3 and DynamoDB lists, and an accepted unknown region takes the deployment's partition. Like those lists, its MaxEntries is its entry count; the security-group rule quota is tracked in #8790. A prefix-list catalog that already declares the list keeps loading, the built-in list serving it. Closes #8634
This commit is contained in:
1 parent
6ea09ee520
commit
b5f29c8434
6 files changed
+216
-26
No files matched your search
@@ -17,6 +17,7 @@ import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
@@ -252,7 +253,7 @@ class PartitionRegionGatesIntegrationTest {
|
||||
/**
|
||||
* The AWS-managed prefix lists belong to the S3 and DynamoDB gateway endpoints, which keep
|
||||
* {@code com.amazonaws} in every partition; only interface endpoint names take the reversed
|
||||
* suffix China lists.
|
||||
* suffix China lists. The CloudFront origin-facing list is commercial-only.
|
||||
*/
|
||||
@Test
|
||||
void gatewayPrefixListsKeepComAmazonawsWhileChinaInterfaceNamesReverseTheSuffix() {
|
||||
@@ -264,6 +265,7 @@ class PartitionRegionGatesIntegrationTest {
|
||||
.extract().xmlPath().getList("DescribeManagedPrefixListsResponse.prefixListSet.item.prefixListName");
|
||||
assertTrue(names.contains("com.amazonaws.cn-north-1.s3"), names.toString());
|
||||
assertTrue(names.contains("com.amazonaws.cn-north-1.dynamodb"), names.toString());
|
||||
assertFalse(names.contains("com.amazonaws.global.cloudfront.origin-facing"), names.toString());
|
||||
|
||||
XmlPath endpointServices = given()
|
||||
.header("Authorization", PartitionMatrix.sigV4Auth("cn-north-1", "ec2"))
|
||||
|
||||
+18
-1
@@ -16,7 +16,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* A China deployment that allows unknown regions serves a region no partition publishes in its
|
||||
* own partition, so DescribeRegions lists the China regions for it, not the commercial ones.
|
||||
* own partition, so DescribeRegions lists the China regions for it, not the commercial ones, and
|
||||
* the AWS-managed prefix lists are China's.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestProfile(Ec2DescribeRegionsUnknownRegionIntegrationTest.ChinaAllowUnknownRegionsProfile.class)
|
||||
@@ -53,6 +54,22 @@ class Ec2DescribeRegionsUnknownRegionIntegrationTest {
|
||||
assertFalse(names.contains("cn-north-1"), names.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUnknownRegionServesTheDeploymentPartitionsManagedPrefixLists() {
|
||||
Response response = given()
|
||||
.header("Authorization", PartitionMatrix.sigV4Auth(UNKNOWN, "ec2"))
|
||||
.formParam("Action", "DescribeManagedPrefixLists")
|
||||
.formParam("Version", "2016-11-15")
|
||||
.when().post("/").then().statusCode(200).contentType("application/xml")
|
||||
.extract().response();
|
||||
List<String> names = response.xmlPath().getList("DescribeManagedPrefixListsResponse.prefixListSet.item.prefixListName");
|
||||
List<String> arns = response.xmlPath().getList("DescribeManagedPrefixListsResponse.prefixListSet.item.prefixListArn");
|
||||
|
||||
assertTrue(names.contains("com.amazonaws." + UNKNOWN + ".s3"), names.toString());
|
||||
assertFalse(names.contains("com.amazonaws.global.cloudfront.origin-facing"), names.toString());
|
||||
assertTrue(arns.contains("arn:aws-cn:ec2:" + UNKNOWN + ":aws:prefix-list/pl-63a5400a"), arns.toString());
|
||||
}
|
||||
|
||||
public static final class ChinaAllowUnknownRegionsProfile implements QuarkusTestProfile {
|
||||
@Override
|
||||
public Map<String, String> getConfigOverrides() {
|
||||
|
||||
@@ -6,6 +6,8 @@ import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
@@ -73,22 +75,41 @@ class Ec2ManagedPrefixListIntegrationTest {
|
||||
.body("DescribeManagedPrefixListsResponse.prefixListSet.item.prefixListName", equalTo(LIST_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ParameterizedTest
|
||||
@Order(3)
|
||||
void describeIncludesAwsManagedGatewayLists() {
|
||||
@CsvSource({
|
||||
"com.amazonaws.us-east-1.s3, pl-63a5400a",
|
||||
"com.amazonaws.global.cloudfront.origin-facing, pl-3b927c52"
|
||||
})
|
||||
void describeIncludesAwsManagedLists(String prefixListName, String expectedId) {
|
||||
given()
|
||||
.formParam("Action", "DescribeManagedPrefixLists")
|
||||
.formParam("Filter.1.Name", "prefix-list-name")
|
||||
.formParam("Filter.1.Value.1", "com.amazonaws.us-east-1.s3")
|
||||
.formParam("Filter.1.Value.1", prefixListName)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeManagedPrefixListsResponse.prefixListSet.item.prefixListId", equalTo("pl-63a5400a"))
|
||||
.body("DescribeManagedPrefixListsResponse.prefixListSet.item.prefixListId", equalTo(expectedId))
|
||||
.body("DescribeManagedPrefixListsResponse.prefixListSet.item.ownerId", equalTo("AWS"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void getEntriesReturnsTheCloudFrontOriginFacingRanges() {
|
||||
given()
|
||||
.formParam("Action", "GetManagedPrefixListEntries")
|
||||
.formParam("PrefixListId", "pl-3b927c52")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("GetManagedPrefixListEntriesResponse.entrySet.item.cidr",
|
||||
hasItems("130.176.0.0/18", "15.158.0.0/16"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void getEntriesReturnsTheInitialEntry() {
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.github.dockerjava.api.DockerClient;
|
||||
import com.github.dockerjava.api.command.ListNetworksCmd;
|
||||
import io.floci.aws.config.EmulatorConfig;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.AwsPartitions;
|
||||
import io.floci.aws.core.common.PaginatedResult;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.common.RequestContext;
|
||||
@@ -7717,7 +7718,7 @@ class Ec2ServiceTest {
|
||||
assertEquals(List.of("192.0.2.0/24"), service.describePrefixLists("eu-west-1", List.of(id), Map.of())
|
||||
.getFirst().getCidrs());
|
||||
assertEquals("192.0.2.0/24", service.getManagedPrefixListEntries("eu-west-1", id, null).getFirst().getCidr());
|
||||
assertEquals(3, service.describeManagedPrefixLists("eu-west-1", List.of(), Map.of()).size());
|
||||
assertEquals(4, service.describeManagedPrefixLists("eu-west-1", List.of(), Map.of()).size());
|
||||
assertEquals("InvalidPrefixListID.NotFound", assertThrows(AwsException.class,
|
||||
() -> service.describeManagedPrefixLists("us-east-1", List.of(id), Map.of())).getErrorCode());
|
||||
assertEquals("UnsupportedOperation", assertThrows(AwsException.class,
|
||||
@@ -7745,6 +7746,11 @@ class Ec2ServiceTest {
|
||||
"{\"eu-west-1\": [{\"prefixListId\":\"pl-12345678\",\"prefixListName\":\"example\",\"cidrs\":[\"invalid\"]}]}",
|
||||
"{\"eu-west-1\": [{\"prefixListId\":\"pl-63a5400a\",\"prefixListName\":\"example\",\"cidrs\":[\"192.0.2.0/24\"]}]}",
|
||||
"{\"eu-west-1\": [{\"prefixListId\":\"pl-12345678\",\"prefixListName\":\"com.amazonaws.eu-west-1.s3\","
|
||||
+ "\"cidrs\":[\"192.0.2.0/24\"]}]}",
|
||||
"{\"eu-west-1\": [{\"prefixListId\":\"pl-3b927c52\",\"prefixListName\":\"example\","
|
||||
+ "\"cidrs\":[\"192.0.2.0/24\"]}]}",
|
||||
"{\"eu-west-1\": [{\"prefixListId\":\"pl-12345678\","
|
||||
+ "\"prefixListName\":\"com.amazonaws.global.cloudfront.origin-facing\","
|
||||
+ "\"cidrs\":[\"192.0.2.0/24\"]}]}"
|
||||
})
|
||||
void invalidManagedPrefixListCatalogFailsStartup(String json, @TempDir Path temp) throws IOException {
|
||||
@@ -7758,6 +7764,36 @@ class Ec2ServiceTest {
|
||||
assertTrue(error.getMessage().contains(catalog.toString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void legacyCloudFrontCatalogEntryGivesWayToTheBuiltIn(@TempDir Path temp) throws IOException {
|
||||
Path catalog = temp.resolve("prefix-lists.json");
|
||||
Files.writeString(catalog, """
|
||||
{"eu-west-1": [
|
||||
{"prefixListId": "pl-3b927c52", "prefixListName": "com.amazonaws.global.cloudfront.origin-facing",
|
||||
"cidrs": ["192.0.2.0/24"]},
|
||||
{"prefixListId": "pl-0123456789abcdef0", "prefixListName": "example-managed-service",
|
||||
"cidrs": ["198.51.100.0/24"]}]}
|
||||
""");
|
||||
EmulatorConfig config = mockConfig(true);
|
||||
when(config.services().ec2().enabled()).thenReturn(true);
|
||||
when(config.services().ec2().managedPrefixListCatalogPath()).thenReturn(Optional.of(catalog.toString()));
|
||||
|
||||
Ec2Service service = assertDoesNotThrow(() -> prefixListService(config));
|
||||
|
||||
List<ManagedPrefixList> cloudFront = service.describeManagedPrefixLists("eu-west-1",
|
||||
List.of("pl-3b927c52"), Map.of());
|
||||
assertEquals(1, cloudFront.size());
|
||||
assertEquals(49, cloudFront.getFirst().getMaxEntries());
|
||||
List<String> cidrs = service.getManagedPrefixListEntries("eu-west-1", "pl-3b927c52", null).stream()
|
||||
.map(PrefixListEntry::getCidr)
|
||||
.toList();
|
||||
assertFalse(cidrs.contains("192.0.2.0/24"), cidrs.toString());
|
||||
assertTrue(cidrs.contains("130.176.0.0/18"), cidrs.toString());
|
||||
assertEquals(List.of("198.51.100.0/24"), service.describePrefixLists("eu-west-1",
|
||||
List.of("pl-0123456789abcdef0"), Map.of()).getFirst().getCidrs());
|
||||
assertEquals(4, service.describeManagedPrefixLists("eu-west-1", List.of(), Map.of()).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void missingManagedPrefixListCatalogFailsStartup(@TempDir Path temp) {
|
||||
EmulatorConfig config = mockConfig(true);
|
||||
@@ -7951,13 +7987,13 @@ class Ec2ServiceTest {
|
||||
service.createManagedPrefixList("us-east-1", "corp", "IPv4", 5, List.of(), List.of());
|
||||
|
||||
List<ManagedPrefixList> east = service.describeManagedPrefixLists("us-east-1", List.of(), Map.of());
|
||||
assertEquals(3, east.size());
|
||||
assertEquals(4, east.size());
|
||||
assertTrue(east.stream().anyMatch(l -> "com.amazonaws.us-east-1.s3".equals(l.getPrefixListName())));
|
||||
assertTrue(east.stream().anyMatch(l -> "corp".equals(l.getPrefixListName())));
|
||||
|
||||
// The customer list belongs to us-east-1; only the AWS-managed pair shows up elsewhere.
|
||||
// The customer list belongs to us-east-1; only the AWS-managed lists show up elsewhere.
|
||||
List<ManagedPrefixList> west = service.describeManagedPrefixLists("us-west-2", List.of(), Map.of());
|
||||
assertEquals(2, west.size());
|
||||
assertEquals(3, west.size());
|
||||
assertTrue(west.stream().allMatch(ManagedPrefixList::isAwsManaged));
|
||||
assertTrue(west.stream().anyMatch(l -> "com.amazonaws.us-west-2.s3".equals(l.getPrefixListName())));
|
||||
}
|
||||
@@ -8120,20 +8156,80 @@ class Ec2ServiceTest {
|
||||
assertEquals("PrefixListVersionMismatch", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void awsManagedListsCannotBeModifiedOrDeleted() {
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"pl-63a5400a", "pl-3b927c52"})
|
||||
void awsManagedListsCannotBeModifiedOrDeleted(String prefixListId) {
|
||||
Ec2Service service = prefixListService();
|
||||
|
||||
AwsException modifyError = assertThrows(AwsException.class, () ->
|
||||
service.modifyManagedPrefixList("us-east-1", "pl-63a5400a", null, "hijacked", null,
|
||||
service.modifyManagedPrefixList("us-east-1", prefixListId, null, "hijacked", null,
|
||||
List.of(), List.of()));
|
||||
assertEquals("UnsupportedOperation", modifyError.getErrorCode());
|
||||
|
||||
AwsException deleteError = assertThrows(AwsException.class, () ->
|
||||
service.deleteManagedPrefixList("us-east-1", "pl-63a5400a"));
|
||||
service.deleteManagedPrefixList("us-east-1", prefixListId));
|
||||
assertEquals("UnsupportedOperation", deleteError.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void cloudFrontOriginFacingListExistsInEveryCommercialRegion() {
|
||||
Ec2Service service = prefixListService();
|
||||
Map<String, List<String>> byName = Map.of("prefix-list-name",
|
||||
List.of("com.amazonaws.global.cloudfront.origin-facing"));
|
||||
|
||||
for (String region : List.of("us-east-1", "eu-west-1", "ap-southeast-2")) {
|
||||
List<ManagedPrefixList> found = service.describeManagedPrefixLists(region, List.of(), byName);
|
||||
assertEquals(1, found.size(), region);
|
||||
ManagedPrefixList list = found.getFirst();
|
||||
assertEquals("pl-3b927c52", list.getPrefixListId());
|
||||
assertEquals("AWS", list.getOwnerId());
|
||||
assertTrue(list.isAwsManaged());
|
||||
assertEquals("IPv4", list.getAddressFamily());
|
||||
assertEquals(49, list.getMaxEntries());
|
||||
assertEquals("arn:aws:ec2:" + region + ":aws:prefix-list/pl-3b927c52", list.getPrefixListArn());
|
||||
}
|
||||
|
||||
List<String> cidrs = service.getManagedPrefixListEntries("us-east-1", "pl-3b927c52", null).stream()
|
||||
.map(PrefixListEntry::getCidr)
|
||||
.toList();
|
||||
assertTrue(cidrs.containsAll(List.of("130.176.0.0/18", "15.158.0.0/16", "64.252.64.0/18")), cidrs.toString());
|
||||
assertEquals(49, cidrs.size(), cidrs.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void cloudFrontOriginFacingListIsAbsentOutsideTheCommercialPartition() {
|
||||
Ec2Service service = prefixListService();
|
||||
|
||||
for (String region : List.of("cn-north-1", "us-gov-west-1")) {
|
||||
assertTrue(service.describeManagedPrefixLists(region, List.of(), Map.of()).stream()
|
||||
.noneMatch(l -> "pl-3b927c52".equals(l.getPrefixListId())), region);
|
||||
assertEquals("InvalidPrefixListID.NotFound", assertThrows(AwsException.class,
|
||||
() -> service.getManagedPrefixListEntries(region, "pl-3b927c52", null)).getErrorCode());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUnknownRegionTakesTheDeploymentPartitionForTheCloudFrontList() {
|
||||
String unknown = "polygondwanaland-west-1";
|
||||
assertTrue(AwsPartitions.forRegion(unknown).isEmpty());
|
||||
Map<String, String> expectedPartitions = Map.of(
|
||||
"us-gov-west-1", "aws-us-gov",
|
||||
"cn-north-1", "aws-cn",
|
||||
"us-east-1", "aws");
|
||||
|
||||
for (Map.Entry<String, String> deployment : expectedPartitions.entrySet()) {
|
||||
Ec2Service service = prefixListService();
|
||||
service.regionResolver = new RegionResolver(deployment.getKey(), "000000000000");
|
||||
List<ManagedPrefixList> lists = service.describeManagedPrefixLists(unknown, List.of(), Map.of());
|
||||
|
||||
boolean commercial = "aws".equals(deployment.getValue());
|
||||
assertEquals(commercial, lists.stream().anyMatch(l -> "pl-3b927c52".equals(l.getPrefixListId())),
|
||||
deployment.getKey());
|
||||
assertTrue(lists.stream().allMatch(l -> l.getPrefixListArn().startsWith(
|
||||
"arn:" + deployment.getValue() + ":ec2:" + unknown + ":aws:prefix-list/")), lists.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteRemovesTheListFromDescribe() {
|
||||
Ec2Service service = prefixListService();
|
||||
|
||||
Reference in new issue
Block a user