mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(ec2): reject subnet IPv4 prefixes outside /16 to /28 (#5439)
* fix(ec2): reject subnet IPv4 prefixes outside /16 to /28 * test(ec2): store the /30 endpoint subnet directly and quote the guide's subnet wording CreateSubnet now refuses prefixes outside /16 to /28, so the interface endpoint test seeds its /30 subnet through the subnet store, as the stored-endpoint test does. Quote the VPC guide's subnet sentence rather than its VPC block sentence.
This commit is contained in:
1 parent
22c4c32e3a
commit
b1bb016b6e
2 files changed
+65
-4
No files matched your search
@@ -5625,6 +5625,8 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
+ "IPv6 CIDR block. VPC " + vpcId + " has none.", 400);
|
||||
}
|
||||
|
||||
rejectOutOfRangeSubnetPrefix(cidrBlock);
|
||||
|
||||
String zoneName = resolveSubnetZoneName(region, availabilityZone, availabilityZoneId);
|
||||
|
||||
String subnetId = "subnet-" + randomHex(8);
|
||||
@@ -5687,6 +5689,23 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The VPC User Guide limits an IPv4 subnet to a prefix between /16 and /28 ("The allowed IPv4
|
||||
* CIDR block size for a subnet is between a /28 netmask and /16 netmask."), and AWS answers
|
||||
* anything else with InvalidSubnet.Range. Requests with no IPv4 CIDR, or one that does not parse, are left to the
|
||||
* checks that already handle them.
|
||||
*/
|
||||
private void rejectOutOfRangeSubnetPrefix(String cidrBlock) {
|
||||
int[] range = cidrRange(cidrBlock);
|
||||
if (range == null) {
|
||||
return;
|
||||
}
|
||||
int prefix = range[1];
|
||||
if (prefix < 16 || prefix > 28) {
|
||||
throw new AwsException("InvalidSubnet.Range", "The CIDR '" + cidrBlock + "' is invalid.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* AWS refuses a subnet whose IPv4 CIDR overlaps another subnet's in the same VPC. CreateSubnet
|
||||
* carries no idempotency token, so this check is also what stops an SDK transport retry after
|
||||
|
||||
Reference in new issue
Block a user