mirror of
https://github.com/floci-io/floci.git
synced 2026-12-03 10:17:48 -05:00
fix(ec2): prevent deleting the local VPC route and return InvalidRoute.NotFound for missing routes (#5603)
DeleteRoute removed the local route CreateRouteTable seeds for the VPC CIDR and reported success. Since CreateRoute answers RouteAlreadyExists for that destination, the route table was left without intra-VPC routing and with no way to put the route back. DeleteRoute also reported success for a destination the table does not hold, hiding caller mistakes. Reject the seeded local route with InvalidParameterValue and report an unknown destination with InvalidRoute.NotFound, matching AWS. The route is identified by its CreateRouteTable origin, so a route repointed by ReplaceRoute stays undeletable while repointed. The CloudFormation route restore path now tolerates the already-gone InvalidRoute.NotFound case through CfnDeletes.safeDelete. Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
1 parent
fc5e1aea0a
commit
340e727ede
5 files changed
+142
-4
No files matched your search
+2
-1
@@ -180,7 +180,8 @@ public class Ec2NetworkCfnProvisioner implements CfnResourceProvisioner {
|
||||
String prefixList = text(target, "destinationPrefixListId");
|
||||
String egressOnly = text(target, "egressOnlyInternetGatewayId");
|
||||
if (egressOnly != null) {
|
||||
ec2Service.deleteRoute(region, routeTableId, cidr, ipv6, prefixList);
|
||||
CfnDeletes.safeDelete("route", routeTableId, () -> ec2Service.deleteRoute(region, routeTableId, cidr,
|
||||
ipv6, prefixList), "InvalidRoute.NotFound");
|
||||
ec2Service.createRoute(region, routeTableId, cidr, ipv6, prefixList, null, null, egressOnly, null);
|
||||
} else {
|
||||
ec2Service.replaceRoute(region, routeTableId, cidr, ipv6, prefixList,
|
||||
|
||||
@@ -8940,14 +8940,40 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
synchronized (lockFor(key(region, routeTableId))) {
|
||||
RouteTable current = getRequiredRouteTable(region, routeTableId);
|
||||
List<Route> next = new ArrayList<>(current.getRoutes());
|
||||
next.removeIf(r -> matchesDestination(r, canonicalDestinationCidrBlock, destinationIpv6CidrBlock,
|
||||
destinationPrefixListId));
|
||||
List<Route> matched = next.stream()
|
||||
.filter(r -> matchesDestination(r, canonicalDestinationCidrBlock, destinationIpv6CidrBlock,
|
||||
destinationPrefixListId))
|
||||
.toList();
|
||||
if (matched.isEmpty()) {
|
||||
throw new AwsException("InvalidRoute.NotFound",
|
||||
"The route identified by "
|
||||
+ destinationLabel(canonicalDestinationCidrBlock, destinationIpv6CidrBlock,
|
||||
destinationPrefixListId)
|
||||
+ " does not exist", 400);
|
||||
}
|
||||
for (Route route : matched) {
|
||||
if (isLocalRoute(route)) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"cannot remove local route " + route.getDestinationCidrBlock()
|
||||
+ " in route table " + routeTableId, 400);
|
||||
}
|
||||
}
|
||||
next.removeAll(matched);
|
||||
current.setRoutes(next);
|
||||
routeTables.put(key(region, routeTableId), current);
|
||||
notifyRouteTableUpdated(region, current);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The route CreateRouteTable seeds for the VPC CIDR, which AWS refuses to delete. Keyed on the
|
||||
* origin rather than the "local" gateway: ReplaceRoute may repoint the route (NAT gateway, ENI,
|
||||
* peering connection) and keeps its origin, and AWS still refuses to delete it while repointed.
|
||||
*/
|
||||
private static boolean isLocalRoute(Route route) {
|
||||
return "CreateRouteTable".equals(route.getOrigin());
|
||||
}
|
||||
|
||||
private RouteTable getRequiredRouteTable(String region, String routeTableId) {
|
||||
RouteTable rt = routeTables.get(key(region, routeTableId)).orElse(null);
|
||||
if (rt == null)
|
||||
|
||||
Reference in new issue
Block a user