VPC: Add CloudFront, Ground Station and Lattice prefix lists (#6540)

This commit is contained in:
Viren Nadkarni 2023-07-26 03:28:50 +05:30 committed by GitHub
parent 1670471068
commit 5fbb1391e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 28 deletions

View File

@ -135,36 +135,80 @@ class ManagedPrefixListBackend:
managed_pl.state = "modify-complete"
return managed_pl
def _create_aws_managed_prefix_list(
self, name: str, address_family: str, entries: List[Dict[str, str]]
) -> None:
managed_prefix_list = self.create_managed_prefix_list(
address_family=address_family,
entry=entries,
prefix_list_name=name,
owner_id="aws",
)
managed_prefix_list.version = None
managed_prefix_list.max_entries = None
self.managed_prefix_lists[managed_prefix_list.id] = managed_prefix_list
def create_default_pls(self) -> None:
entry = [
{"Cidr": "52.216.0.0/15", "Description": "default"},
{"Cidr": "3.5.0.0/19", "Description": "default"},
{"Cidr": "54.231.0.0/16", "Description": "default"},
]
# See https://docs.aws.amazon.com/vpc/latest/userguide/working-with-aws-managed-prefix-lists.html
managed_prefix_list = self.create_managed_prefix_list(
# S3
self._create_aws_managed_prefix_list(
name=f"com.amazonaws.{self.region_name}.s3", # type: ignore[attr-defined]
address_family="IPv4",
entry=entry,
prefix_list_name=f"com.amazonaws.{self.region_name}.s3", # type: ignore[attr-defined]
owner_id="aws",
entries=[
{"Cidr": "52.216.0.0/15", "Description": "default"},
{"Cidr": "3.5.0.0/19", "Description": "default"},
{"Cidr": "54.231.0.0/16", "Description": "default"},
],
)
managed_prefix_list.version = None
managed_prefix_list.max_entries = None
self.managed_prefix_lists[managed_prefix_list.id] = managed_prefix_list
entry = [
{"Cidr": "3.218.182.0/24", "Description": "default"},
{"Cidr": "3.218.180.0/23", "Description": "default"},
{"Cidr": "52.94.0.0/22", "Description": "default"},
{"Cidr": "52.119.224.0/20", "Description": "default"},
]
managed_prefix_list = self.create_managed_prefix_list(
# DynamoDB
self._create_aws_managed_prefix_list(
name=f"com.amazonaws.{self.region_name}.dynamodb", # type: ignore[attr-defined]
address_family="IPv4",
entry=entry,
prefix_list_name=f"com.amazonaws.{self.region_name}.dynamodb", # type: ignore[attr-defined]
owner_id="aws",
entries=[
{"Cidr": "3.218.182.0/24", "Description": "default"},
{"Cidr": "3.218.180.0/23", "Description": "default"},
{"Cidr": "52.94.0.0/22", "Description": "default"},
{"Cidr": "52.119.224.0/20", "Description": "default"},
],
)
# CloudFront
self._create_aws_managed_prefix_list(
name="com.amazonaws.global.cloudfront.origin-facing",
address_family="IPv4",
entries=[
{"Cidr": "13.124.199.0/24", "Description": "default"},
{"Cidr": "130.176.0.0/18", "Description": "default"},
{"Cidr": "15.158.0.0/16", "Description": "default"},
{"Cidr": "18.68.0.0/16", "Description": "default"},
{"Cidr": "204.246.166.0/24", "Description": "default"},
{"Cidr": "205.251.218.0/24", "Description": "default"},
{"Cidr": "3.172.0.0/18", "Description": "default"},
{"Cidr": "54.239.208.0/21", "Description": "default"},
{"Cidr": "64.252.64.0/18", "Description": "default"},
{"Cidr": "70.132.0.0/18", "Description": "default"},
],
)
# Ground Station
self._create_aws_managed_prefix_list(
name="com.amazonaws.global.groundstation",
address_family="IPv4",
entries=[{"Cidr": "3.2.16.0/20", "Description": "default"}],
)
# VPC Lattice
self._create_aws_managed_prefix_list(
name=f"com.amazonaws.{self.region_name}.vpc-lattice", # type: ignore[attr-defined]
address_family="IPv4",
entries=[{"Cidr": "169.254.171.0/24", "Description": "default"}],
)
# VPC Lattice ipv6
self._create_aws_managed_prefix_list(
name=f"com.amazonaws.{self.region_name}.ipv6.vpc-lattice", # type: ignore[attr-defined]
address_family="IPv6",
entries=[{"Cidr": "fd00:ec2:80::/64", "Description": "default"}],
)
managed_prefix_list.version = None
managed_prefix_list.max_entries = None
self.managed_prefix_lists[managed_prefix_list.id] = managed_prefix_list

View File

@ -177,14 +177,14 @@ def test_describe_prefix_lists():
ec2 = boto3.client("ec2", region_name="us-west-1")
default_lists = ec2.describe_prefix_lists()["PrefixLists"]
assert len(default_lists) == 2
assert len(default_lists) == 6
ec2.create_managed_prefix_list(
PrefixListName="examplelist", MaxEntries=2, AddressFamily="?"
)
all_lists = ec2.describe_prefix_lists()["PrefixLists"]
assert len(all_lists) == 2
assert len(all_lists) == 6
for pl in all_lists:
assert "com.amazonaws" in pl["PrefixListName"]