mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
feat(ec2): support egress-only internet gateways (#5822)
* feat(ec2): support egress-only internet gateways CreateEgressOnlyInternetGateway fell through to UnsupportedOperation, so aws_egress_only_internet_gateway could not be created, and DescribeEgressOnlyInternetGateways always answered an empty set. Egress-only gateways are now stored (ec2-egress-only-internet-gateways.json, through StorageFactory) and created attached to an existing VPC, with TagSpecification and CreateTags applied. Describe filters by ID, egress-only-internet-gateway-id, attachment.vpc-id, attachment.state and tags; Delete returns returnCode. DeleteVpc reports DependencyViolation while one is attached. The three actions are added to EC2 query routing, which removes DescribeEgressOnlyInternetGateways from the known gaps. * fix(ec2): settle Qodo findings on egress-only internet gateways - CreateEgressOnlyInternetGateway validates TagSpecification tags before it creates anything, so an aws: key no longer leaves an attached gateway behind. Tags are applied with the gateway, under the topology lock. - A ClientToken replay compares the creation tags as well as VpcId: changed tags fail with IdempotentParameterMismatch, and a matching replay returns the gateway unchanged instead of re-tagging it. - DescribeEgressOnlyInternetGateways honours MaxResults (5 to 255 in the EC2 model) and NextToken, ordered by ID, using the service's existing token codec. - DeleteEgressOnlyInternetGateway takes the resource lock createSystemTags takes, and leaves routes that targeted the gateway in place as blackhole, the state AWS documents for a route whose target is gone. * fix(ec2): DeleteEgressOnlyInternetGateway without an id is MissingParameter The EC2 model marks EgressOnlyInternetGatewayId required. A request without it answered InvalidGatewayID.NotFound for 'null'; it now gets the same MissingParameter the other EC2 handlers return. An unknown id still fails with InvalidGatewayID.NotFound.
This commit is contained in:
1 parent
f031e4052d
commit
708dc32fa1
10 files changed
+802
-39
No files matched your search
@@ -222,7 +222,7 @@ Floci seeds the following resources on first use in each region so Terraform, th
|
||||
|--------|-------------|
|
||||
| CreateVpc | Creates a VPC with the requested CIDR block. `InstanceTenancy` accepts `default` or `dedicated`; `host` is rejected with `InvalidParameterValue`, as on AWS. |
|
||||
| DescribeVpcs | Lists or returns stored VPCs. |
|
||||
| DeleteVpc | Deletes a VPC from the local EC2 store, together with its default security group and rules, main route table and default network ACL. Fails with `DependencyViolation` while the VPC still has a subnet, a security group, route table or network ACL other than those defaults, a VPC endpoint, an attached internet gateway, a transit gateway attachment, or anything still holding a network interface in one of its subnets: an instance that is not terminated, a NAT gateway that is not deleted or failed, a standalone network interface, or an interface endpoint. |
|
||||
| DeleteVpc | Deletes a VPC from the local EC2 store, together with its default security group and rules, main route table and default network ACL. Fails with `DependencyViolation` while the VPC still has a subnet, a security group, route table or network ACL other than those defaults, a VPC endpoint, an attached internet gateway or egress-only internet gateway, a transit gateway attachment, or anything still holding a network interface in one of its subnets: an instance that is not terminated, a NAT gateway that is not deleted or failed, a standalone network interface, or an interface endpoint. |
|
||||
| ModifyVpcAttribute | Updates supported VPC attributes. |
|
||||
| DescribeVpcAttribute | Returns a supported VPC attribute. |
|
||||
| DescribeVpcEndpointServices | Lists common AWS interface endpoint services and S3 (gateway and interface) in every availability zone, named per partition (see [Partitions](../configuration/partitions.md)). A `ServiceName` filter is echoed back as asked. |
|
||||
@@ -231,15 +231,12 @@ Floci seeds the following resources on first use in each region so Terraform, th
|
||||
| ModifyVpcEndpoint | Associates or disassociates route tables, subnets and security groups, sets or resets the endpoint policy, and updates stored `IpAddressType` metadata. Omitting the type preserves its current value; malformed types are rejected before changes are applied. `SubnetConfiguration.N` replaces the addresses pinned for a subnet, under the same address validation as CreateVpcEndpoint. `DnsOptions` is accepted and ignored. |
|
||||
| DeleteVpcEndpoints | Deletes VPC endpoint records. |
|
||||
| DescribeVpnGateways | Validates filters and returns empty discovery results; explicit IDs return not-found errors. |
|
||||
| DescribeEgressOnlyInternetGateways | Validates filters and pagination parameters and returns an empty set, including for explicit IDs, as AWS does. |
|
||||
| CreateDefaultVpc | Creates or returns the default VPC for the region. |
|
||||
| AssociateVpcCidrBlock | Adds a secondary CIDR block association to a VPC. |
|
||||
| DisassociateVpcCidrBlock | Removes a secondary CIDR block association from a VPC. |
|
||||
|
||||
The two describe-only network actions above provide discovery compatibility when no
|
||||
resources exist. Egress-only gateway discovery validates its pagination parameters before
|
||||
returning an empty page. Neither models virtual private gateway or egress-only internet
|
||||
gateway lifecycles.
|
||||
`DescribeVpnGateways` provides discovery compatibility when no resources exist; virtual
|
||||
private gateway lifecycles are not modelled.
|
||||
|
||||
### Subnets
|
||||
|
||||
@@ -317,6 +314,9 @@ Nested launch-template tags follow AWS's case-sensitive check: `aws:` is rejecte
|
||||
| DeleteInternetGateway | Deletes an internet gateway. |
|
||||
| AttachInternetGateway | Attaches an internet gateway to a VPC. |
|
||||
| DetachInternetGateway | Detaches an internet gateway from a VPC. |
|
||||
| CreateEgressOnlyInternetGateway | Creates an egress-only internet gateway attached to an existing VPC (`InvalidVpcID.NotFound` otherwise). Tags are validated before the gateway is created, so a rejected tag leaves nothing behind. A retry with the same `ClientToken` returns the gateway the first call created, unchanged; the same token with a different `VpcId` or different `TagSpecification` tags fails with `IdempotentParameterMismatch`. |
|
||||
| DescribeEgressOnlyInternetGateways | Lists stored egress-only internet gateways, filtered by ID and by the `egress-only-internet-gateway-id`, `attachment.vpc-id`, `attachment.state` and tag filters. An unknown ID returns an empty set, as AWS does. `MaxResults` (5 to 255) pages the results, ordered by ID, with `NextToken`. |
|
||||
| DeleteEgressOnlyInternetGateway | Deletes an egress-only internet gateway; an unknown ID fails with `InvalidGatewayID.NotFound`. Routes that targeted it stay in their route tables with state `blackhole`. |
|
||||
|
||||
### Route Tables
|
||||
|
||||
|
||||
@@ -202,6 +202,8 @@ public class AwsQueryController {
|
||||
"CreateTags", "DeleteTags", "DescribeTags",
|
||||
"CreateInternetGateway", "DescribeInternetGateways", "DeleteInternetGateway",
|
||||
"AttachInternetGateway", "DetachInternetGateway",
|
||||
"CreateEgressOnlyInternetGateway", "DescribeEgressOnlyInternetGateways",
|
||||
"DeleteEgressOnlyInternetGateway",
|
||||
"CreateRouteTable", "DescribeRouteTables", "DeleteRouteTable",
|
||||
"AssociateRouteTable", "DisassociateRouteTable", "CreateRoute", "ReplaceRoute", "DeleteRoute",
|
||||
"CreateNetworkAcl", "DescribeNetworkAcls", "DeleteNetworkAcl",
|
||||
|
||||
@@ -167,8 +167,10 @@ public class Ec2QueryHandler {
|
||||
case "ReplaceTransitGatewayRoute" -> handleReplaceTransitGatewayRoute(params, region);
|
||||
case "SearchTransitGatewayRoutes" -> handleSearchTransitGatewayRoutes(params, region);
|
||||
case "ExportTransitGatewayRoutes" -> handleExportTransitGatewayRoutes(params, region);
|
||||
case "CreateEgressOnlyInternetGateway" -> handleCreateEgressOnlyInternetGateway(params, region);
|
||||
case "DescribeEgressOnlyInternetGateways" ->
|
||||
handleDescribeEgressOnlyInternetGateways(params);
|
||||
handleDescribeEgressOnlyInternetGateways(params, region);
|
||||
case "DeleteEgressOnlyInternetGateway" -> handleDeleteEgressOnlyInternetGateway(params, region);
|
||||
case "CreateDefaultVpc" -> handleCreateDefaultVpc(params, region);
|
||||
case "AssociateVpcCidrBlock" -> handleAssociateVpcCidrBlock(params, region);
|
||||
case "DisassociateVpcCidrBlock" -> handleDisassociateVpcCidrBlock(params, region);
|
||||
@@ -2947,25 +2949,50 @@ public class Ec2QueryHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private Response handleDescribeEgressOnlyInternetGateways(MultivaluedMap<String, String> p) {
|
||||
validateEmptyDiscoveryPagination(p, 255);
|
||||
service.describeEgressOnlyInternetGatewayIds(getFilters(p));
|
||||
return emptyDescribeResponse(
|
||||
"DescribeEgressOnlyInternetGateways", "egressOnlyInternetGatewaySet");
|
||||
private Response handleCreateEgressOnlyInternetGateway(MultivaluedMap<String, String> p, String region) {
|
||||
// Tags are validated before anything is created, so a rejected tag leaves no gateway behind.
|
||||
List<Tag> resourceTags = parseTagsForResource(p, "egress-only-internet-gateway");
|
||||
EgressOnlyInternetGateway eigw = service.createEgressOnlyInternetGateway(
|
||||
region, p.getFirst("VpcId"), p.getFirst("ClientToken"), resourceTags);
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.start("CreateEgressOnlyInternetGatewayResponse", AwsNamespaces.EC2)
|
||||
.elem("requestId", UUID.randomUUID().toString());
|
||||
if (p.getFirst("ClientToken") != null) {
|
||||
xml.elem("clientToken", p.getFirst("ClientToken"));
|
||||
}
|
||||
xml.start("egressOnlyInternetGateway").raw(eigwXml(eigw)).end("egressOnlyInternetGateway")
|
||||
.end("CreateEgressOnlyInternetGatewayResponse");
|
||||
return xmlResponse(xml.build());
|
||||
}
|
||||
|
||||
private void validateEmptyDiscoveryPagination(MultivaluedMap<String, String> p, int maximum) {
|
||||
String rawMaxResults = p.getFirst("MaxResults");
|
||||
if (rawMaxResults != null) {
|
||||
int maxResults = parseIntParam(p, "MaxResults", 0);
|
||||
if (maxResults < 5 || maxResults > maximum) {
|
||||
throw new AwsException("InvalidMaxResults",
|
||||
"The specified value for MaxResults is not valid.", 400);
|
||||
}
|
||||
private Response handleDescribeEgressOnlyInternetGateways(MultivaluedMap<String, String> p, String region) {
|
||||
EgressOnlyInternetGatewayListResult result = service.describeEgressOnlyInternetGateways(
|
||||
region, getList(p, "EgressOnlyInternetGatewayId"), getFilters(p),
|
||||
p.getFirst("MaxResults") == null ? null : parseIntParam(p, "MaxResults", 0),
|
||||
p.getFirst("NextToken"));
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.start("DescribeEgressOnlyInternetGatewaysResponse", AwsNamespaces.EC2)
|
||||
.elem("requestId", UUID.randomUUID().toString())
|
||||
.start("egressOnlyInternetGatewaySet");
|
||||
for (EgressOnlyInternetGateway eigw : result.egressOnlyInternetGateways()) {
|
||||
xml.start("item").raw(eigwXml(eigw)).end("item");
|
||||
}
|
||||
if (p.getFirst("NextToken") != null) {
|
||||
throw new AwsException("InvalidParameterValue", "Invalid NextToken", 400);
|
||||
xml.end("egressOnlyInternetGatewaySet");
|
||||
if (result.nextToken() != null) {
|
||||
xml.elem("nextToken", result.nextToken());
|
||||
}
|
||||
xml.end("DescribeEgressOnlyInternetGatewaysResponse");
|
||||
return xmlResponse(xml.build());
|
||||
}
|
||||
|
||||
private Response handleDeleteEgressOnlyInternetGateway(MultivaluedMap<String, String> p, String region) {
|
||||
service.deleteEgressOnlyInternetGateway(region, requiredParam(p, "EgressOnlyInternetGatewayId"));
|
||||
return xmlResponse(new XmlBuilder()
|
||||
.start("DeleteEgressOnlyInternetGatewayResponse", AwsNamespaces.EC2)
|
||||
.elem("requestId", UUID.randomUUID().toString())
|
||||
.elem("returnCode", "true")
|
||||
.end("DeleteEgressOnlyInternetGatewayResponse")
|
||||
.build());
|
||||
}
|
||||
|
||||
private Response emptyDescribeResponse(String action, String resultSet) {
|
||||
@@ -3806,9 +3833,8 @@ public class Ec2QueryHandler {
|
||||
String destPrefixList = p.getFirst("DestinationPrefixListId");
|
||||
String gwId = p.getFirst("GatewayId");
|
||||
String natGwId = p.getFirst("NatGatewayId");
|
||||
// The gateway itself is not modelled (CreateEgressOnlyInternetGateway is still
|
||||
// unimplemented), but the id the caller sent is stored and reported back so an IPv6
|
||||
// egress route is not silently rewritten into a targetless one.
|
||||
// The gateway id is stored as sent, not checked against the egress-only gateways that
|
||||
// exist, so an IPv6 egress route is not silently rewritten into a targetless one.
|
||||
String eigwId = p.getFirst("EgressOnlyInternetGatewayId");
|
||||
String pcxId = p.getFirst("VpcPeeringConnectionId");
|
||||
String instanceId = p.getFirst("InstanceId");
|
||||
@@ -5039,6 +5065,21 @@ public class Ec2QueryHandler {
|
||||
return xml.build();
|
||||
}
|
||||
|
||||
private String eigwXml(EgressOnlyInternetGateway eigw) {
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.elem("egressOnlyInternetGatewayId", eigw.getEgressOnlyInternetGatewayId())
|
||||
.start("attachmentSet");
|
||||
for (InternetGatewayAttachment att : eigw.getAttachments()) {
|
||||
xml.start("item")
|
||||
.elem("state", att.getState())
|
||||
.elem("vpcId", att.getVpcId())
|
||||
.end("item");
|
||||
}
|
||||
xml.end("attachmentSet")
|
||||
.raw(tagSetXml(eigw.getTags()));
|
||||
return xml.build();
|
||||
}
|
||||
|
||||
private String routeTableXml(RouteTable rt) {
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.elem("routeTableId", rt.getRouteTableId())
|
||||
|
||||
@@ -25,6 +25,8 @@ import io.github.hectorvent.floci.services.ec2.model.Address;
|
||||
import io.github.hectorvent.floci.services.ec2.model.BlockDeviceMapping;
|
||||
import io.github.hectorvent.floci.services.ec2.model.CapacityReservation;
|
||||
import io.github.hectorvent.floci.services.ec2.model.EbsBlockDevice;
|
||||
import io.github.hectorvent.floci.services.ec2.model.EgressOnlyInternetGateway;
|
||||
import io.github.hectorvent.floci.services.ec2.model.EgressOnlyInternetGatewayListResult;
|
||||
import io.github.hectorvent.floci.services.ec2.model.GroupIdentifier;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Host;
|
||||
import io.github.hectorvent.floci.services.ec2.model.IamInstanceProfileAssociation;
|
||||
@@ -277,6 +279,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
private final StorageBackend<String, List<Tag>> tags;
|
||||
private final StorageBackend<String, CapacityReservation> capacityReservations;
|
||||
private final StorageBackend<String, Host> hosts;
|
||||
private final StorageBackend<String, EgressOnlyInternetGateway> egressOnlyInternetGateways;
|
||||
// Serialises a launch onto a host against ModifyHosts/ReleaseHosts, so a host cannot be
|
||||
// released between the launch's availability check and the store of its instance.
|
||||
private final Object hostLock = new Object();
|
||||
@@ -514,7 +517,9 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
requestContextInstance, iamService, volumeBlockDeviceManager,
|
||||
storageFactory.create("ec2", "ec2-hosts.json", new TypeReference<Map<String, Host>>() {}),
|
||||
storageFactory.create("ec2", "ec2-transit-gateway-peering-attachments.json",
|
||||
new TypeReference<Map<String, TransitGatewayPeeringAttachment>>() {}));
|
||||
new TypeReference<Map<String, TransitGatewayPeeringAttachment>>() {}),
|
||||
storageFactory.create("ec2", "ec2-egress-only-internet-gateways.json",
|
||||
new TypeReference<Map<String, EgressOnlyInternetGateway>>() {}));
|
||||
}
|
||||
|
||||
// Package-private for hermetic tests (pass in-memory or temp-dir-backed StorageBackends directly).
|
||||
@@ -722,11 +727,12 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
transitGatewayPropagations, transitGatewayRoutes, vpcPeeringConnections,
|
||||
networkInterfaces, capacityReservations, volumeModifications,
|
||||
requestContextInstance, iamService, volumeBlockDeviceManager, new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>());
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>());
|
||||
}
|
||||
|
||||
// The terminal constructor. Dedicated Hosts and transit gateway peering attachments ride on
|
||||
// their own parameters so the shorter overloads above keep their arity for existing fixtures.
|
||||
// The terminal constructor. Dedicated Hosts, transit gateway peering attachments and egress-only
|
||||
// internet gateways ride on their own parameters so the shorter overloads above keep their
|
||||
// arity for existing fixtures.
|
||||
Ec2Service(EmulatorConfig config, Ec2ContainerManager containerManager,
|
||||
Ec2PortForwardManager portForwardManager,
|
||||
AmiImageResolver amiImageResolver, Ec2ImageCatalog imageCatalog,
|
||||
@@ -763,8 +769,10 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
IamService iamService,
|
||||
Ec2VolumeBlockDeviceManager volumeBlockDeviceManager,
|
||||
StorageBackend<String, Host> hosts,
|
||||
StorageBackend<String, TransitGatewayPeeringAttachment> transitGatewayPeeringAttachments) {
|
||||
StorageBackend<String, TransitGatewayPeeringAttachment> transitGatewayPeeringAttachments,
|
||||
StorageBackend<String, EgressOnlyInternetGateway> egressOnlyInternetGateways) {
|
||||
this.hosts = hosts;
|
||||
this.egressOnlyInternetGateways = egressOnlyInternetGateways;
|
||||
this.transitGatewayPeeringAttachments = transitGatewayPeeringAttachments;
|
||||
this.iamService = iamService;
|
||||
this.volumeBlockDeviceManager = volumeBlockDeviceManager;
|
||||
@@ -4788,11 +4796,120 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
return List.of();
|
||||
}
|
||||
|
||||
// ─── Egress-only Internet Gateways ─────────────────────────────────────────
|
||||
|
||||
// Created already attached: AWS has no attach/detach call for this gateway, the VPC is fixed at creation.
|
||||
// ClientToken replays return the gateway the first call made, unchanged; a reused token with
|
||||
// another VpcId or other creation tags fails with IdempotentParameterMismatch, as the EC2
|
||||
// idempotency guide documents. Tags are applied here, with the gateway, so a replay never re-tags.
|
||||
public EgressOnlyInternetGateway createEgressOnlyInternetGateway(String region, String vpcId,
|
||||
String clientToken, List<Tag> tagList) {
|
||||
ensureDefaultResources(region);
|
||||
if (vpcId == null || vpcId.isBlank()) {
|
||||
throw new AwsException("MissingParameter",
|
||||
"The request must contain the parameter vpcId", 400);
|
||||
}
|
||||
String token = clientToken != null && !clientToken.isBlank() ? clientToken : null;
|
||||
synchronized (attachmentTopologyLock(region)) {
|
||||
if (token != null) {
|
||||
for (EgressOnlyInternetGateway existing : egressOnlyInternetGateways.scan(
|
||||
k -> k.startsWith(region + "::"))) {
|
||||
if (token.equals(existing.getClientToken())) {
|
||||
if (!vpcId.equals(existing.getAttachments().get(0).getVpcId())
|
||||
|| !tagMap(tagList).equals(tagMap(existing.getCreationTags()))) {
|
||||
throw new AwsException("IdempotentParameterMismatch",
|
||||
"The client token '" + token + "' was already used with different parameters", 400);
|
||||
}
|
||||
return existing;
|
||||
}
|
||||
}
|
||||
}
|
||||
getRequiredVpc(region, vpcId);
|
||||
EgressOnlyInternetGateway eigw = new EgressOnlyInternetGateway();
|
||||
eigw.setEgressOnlyInternetGatewayId("eigw-" + randomHex(17));
|
||||
eigw.setRegion(region);
|
||||
eigw.setClientToken(token);
|
||||
eigw.getAttachments().add(new InternetGatewayAttachment(vpcId, "attached"));
|
||||
eigw.setCreationTags(new ArrayList<>(tagList));
|
||||
eigw.setTags(new ArrayList<>(tagList));
|
||||
if (!tagList.isEmpty()) {
|
||||
tags.put(eigw.getEgressOnlyInternetGatewayId(), new ArrayList<>(tagList));
|
||||
}
|
||||
egressOnlyInternetGateways.put(key(region, eigw.getEgressOnlyInternetGatewayId()), eigw);
|
||||
return eigw;
|
||||
}
|
||||
}
|
||||
|
||||
// AWS answers an unknown egress-only gateway ID with an empty set, not an error; callers such as
|
||||
// the Terraform provider treat the empty result as "not found".
|
||||
public List<String> describeEgressOnlyInternetGatewayIds(Map<String, List<String>> filters) {
|
||||
public List<EgressOnlyInternetGateway> describeEgressOnlyInternetGateways(String region, List<String> ids,
|
||||
Map<String, List<String>> filters) {
|
||||
requireSupportedFilters(filters.keySet(), EGRESS_ONLY_INTERNET_GATEWAY_FILTERS);
|
||||
return List.of();
|
||||
return egressOnlyInternetGateways.scan(k -> k.startsWith(region + "::")).stream()
|
||||
.filter(eigw -> ids.isEmpty() || ids.contains(eigw.getEgressOnlyInternetGatewayId()))
|
||||
.filter(eigw -> matchesFilters(eigw, filters, region))
|
||||
.sorted(Comparator.comparing(EgressOnlyInternetGateway::getEgressOnlyInternetGatewayId))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* The paginated form. MaxResults is 5 to 255 in the EC2 model; null means the request left it
|
||||
* out and gets every match in one page.
|
||||
*/
|
||||
public EgressOnlyInternetGatewayListResult describeEgressOnlyInternetGateways(
|
||||
String region, List<String> ids, Map<String, List<String>> filters, Integer maxResults,
|
||||
String nextToken) {
|
||||
if (maxResults != null && (maxResults < 5 || maxResults > 255)) {
|
||||
throw new AwsException("InvalidMaxResults",
|
||||
"Value (" + maxResults + ") for parameter MaxResults is invalid. "
|
||||
+ "Expecting a value between 5 and 255.", 400);
|
||||
}
|
||||
int offset = decodeToken(nextToken);
|
||||
List<EgressOnlyInternetGateway> all = describeEgressOnlyInternetGateways(region, ids, filters);
|
||||
int total = all.size();
|
||||
int toIndex = maxResults != null ? Math.min(offset + maxResults, total) : total;
|
||||
List<EgressOnlyInternetGateway> page = offset < total
|
||||
? new ArrayList<>(all.subList(offset, toIndex))
|
||||
: new ArrayList<>();
|
||||
return new EgressOnlyInternetGatewayListResult(page, toIndex < total ? encodeToken(toIndex) : null);
|
||||
}
|
||||
|
||||
private static Map<String, String> tagMap(List<Tag> tagList) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
for (Tag tag : tagList == null ? List.<Tag>of() : tagList) {
|
||||
map.put(tag.getKey(), tag.getValue());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
// Under the gateway's resource lock, the one createSystemTags takes, so a concurrent tag write
|
||||
// cannot put the gateway back after it is gone. A route that targeted the gateway stays in its
|
||||
// table as a blackhole: AWS documents that state for a route whose target is no longer available.
|
||||
public void deleteEgressOnlyInternetGateway(String region, String eigwId) {
|
||||
synchronized (lockFor(key(region, eigwId))) {
|
||||
if (egressOnlyInternetGateways.get(key(region, eigwId)).isEmpty()) {
|
||||
throw new AwsException("InvalidGatewayID.NotFound",
|
||||
"The eigw ID '" + eigwId + "' does not exist", 400);
|
||||
}
|
||||
egressOnlyInternetGateways.delete(key(region, eigwId));
|
||||
tags.delete(eigwId);
|
||||
}
|
||||
for (RouteTable table : routeTables.scan(k -> k.startsWith(region + "::"))) {
|
||||
if (table.getRoutes().stream().noneMatch(r -> eigwId.equals(r.getEgressOnlyInternetGatewayId()))) {
|
||||
continue;
|
||||
}
|
||||
synchronized (lockFor(key(region, table.getRouteTableId()))) {
|
||||
RouteTable current = routeTables.get(key(region, table.getRouteTableId())).orElse(null);
|
||||
if (current == null) {
|
||||
continue;
|
||||
}
|
||||
current.getRoutes().stream()
|
||||
.filter(r -> eigwId.equals(r.getEgressOnlyInternetGatewayId()))
|
||||
.forEach(r -> r.setState("blackhole"));
|
||||
routeTables.put(key(region, current.getRouteTableId()), current);
|
||||
notifyRouteTableUpdated(region, current);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void requireSupportedFilters(Collection<String> filterNames, Set<String> supportedFilters) {
|
||||
@@ -4847,6 +4964,9 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
|| internetGateways.scan(k -> k.startsWith(region + "::")).stream()
|
||||
.anyMatch(igw -> igw.getAttachments().stream()
|
||||
.anyMatch(attachment -> vpcId.equals(attachment.getVpcId())))
|
||||
|| egressOnlyInternetGateways.scan(k -> k.startsWith(region + "::")).stream()
|
||||
.anyMatch(eigw -> eigw.getAttachments().stream()
|
||||
.anyMatch(attachment -> vpcId.equals(attachment.getVpcId())))
|
||||
|| vpcEndpoints.scan(k -> k.startsWith(region + "::")).stream()
|
||||
.anyMatch(endpoint -> vpcId.equals(endpoint.getVpcId()));
|
||||
if (hasDependents) {
|
||||
@@ -8091,6 +8211,12 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
if (sgRule != null) { sgRule.setTags(new ArrayList<>(tagList)); securityGroupRules.put(storeKey, sgRule); return; }
|
||||
InternetGateway igw = internetGateways.get(storeKey).orElse(null);
|
||||
if (igw != null) { igw.setTags(new ArrayList<>(tagList)); internetGateways.put(storeKey, igw); return; }
|
||||
EgressOnlyInternetGateway eigw = egressOnlyInternetGateways.get(storeKey).orElse(null);
|
||||
if (eigw != null) {
|
||||
eigw.setTags(new ArrayList<>(tagList));
|
||||
egressOnlyInternetGateways.put(storeKey, eigw);
|
||||
return;
|
||||
}
|
||||
RouteTable rt = routeTables.get(storeKey).orElse(null);
|
||||
if (rt != null) { rt.setTags(new ArrayList<>(tagList)); routeTables.put(storeKey, rt); return; }
|
||||
KeyPair kp = keyPairs.get(storeKey).orElse(null);
|
||||
@@ -8232,6 +8358,9 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
if (resourceId.startsWith("igw-")) {
|
||||
return "internet-gateway";
|
||||
}
|
||||
if (resourceId.startsWith("eigw-")) {
|
||||
return "egress-only-internet-gateway";
|
||||
}
|
||||
if (resourceId.startsWith("rtb-")) {
|
||||
return "route-table";
|
||||
}
|
||||
@@ -10282,6 +10411,16 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
default -> true;
|
||||
};
|
||||
}
|
||||
if (resource instanceof EgressOnlyInternetGateway eigw) {
|
||||
return switch (filterName) {
|
||||
case "egress-only-internet-gateway-id" -> matchesValue(values, eigw.getEgressOnlyInternetGatewayId());
|
||||
case "attachment.vpc-id" -> eigw.getAttachments().stream()
|
||||
.anyMatch(a -> matchesValue(values, a.getVpcId()));
|
||||
case "attachment.state" -> eigw.getAttachments().stream()
|
||||
.anyMatch(a -> matchesValue(values, a.getState()));
|
||||
default -> true;
|
||||
};
|
||||
}
|
||||
if (resource instanceof RouteTable rt) {
|
||||
return switch (filterName) {
|
||||
case "route-table-id" -> matchesValue(values, rt.getRouteTableId());
|
||||
@@ -10471,6 +10610,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
if (resource instanceof Subnet subnet) return subnet.getTags();
|
||||
if (resource instanceof SecurityGroup sg) return sg.getTags();
|
||||
if (resource instanceof InternetGateway igw) return igw.getTags();
|
||||
if (resource instanceof EgressOnlyInternetGateway eigw) return eigw.getTags();
|
||||
if (resource instanceof RouteTable rt) return rt.getTags();
|
||||
if (resource instanceof KeyPair kp) return kp.getTags();
|
||||
if (resource instanceof Address addr) return addr.getTags();
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package io.github.hectorvent.floci.services.ec2.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class EgressOnlyInternetGateway {
|
||||
|
||||
private String egressOnlyInternetGatewayId;
|
||||
private String region;
|
||||
private String clientToken;
|
||||
private List<InternetGatewayAttachment> attachments = new ArrayList<>();
|
||||
private List<Tag> tags = new ArrayList<>();
|
||||
// The tags the create request carried, kept apart from later tag changes so a ClientToken
|
||||
// replay is compared with the original request rather than the gateway's current tags.
|
||||
private List<Tag> creationTags = new ArrayList<>();
|
||||
|
||||
public EgressOnlyInternetGateway() {}
|
||||
|
||||
public String getEgressOnlyInternetGatewayId() { return egressOnlyInternetGatewayId; }
|
||||
public void setEgressOnlyInternetGatewayId(String egressOnlyInternetGatewayId) {
|
||||
this.egressOnlyInternetGatewayId = egressOnlyInternetGatewayId;
|
||||
}
|
||||
|
||||
public String getRegion() { return region; }
|
||||
public void setRegion(String region) { this.region = region; }
|
||||
|
||||
public String getClientToken() { return clientToken; }
|
||||
public void setClientToken(String clientToken) { this.clientToken = clientToken; }
|
||||
|
||||
public List<InternetGatewayAttachment> getAttachments() { return attachments; }
|
||||
public void setAttachments(List<InternetGatewayAttachment> attachments) { this.attachments = attachments; }
|
||||
|
||||
public List<Tag> getTags() { return tags; }
|
||||
public void setTags(List<Tag> tags) { this.tags = tags; }
|
||||
|
||||
public List<Tag> getCreationTags() { return creationTags; }
|
||||
public void setCreationTags(List<Tag> creationTags) { this.creationTags = creationTags; }
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package io.github.hectorvent.floci.services.ec2.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* One page of {@code DescribeEgressOnlyInternetGateways}, with the cursor for the next page or
|
||||
* {@code null} when there is none.
|
||||
*/
|
||||
public record EgressOnlyInternetGatewayListResult(
|
||||
List<EgressOnlyInternetGateway> egressOnlyInternetGateways,
|
||||
String nextToken
|
||||
) {}
|
||||
+450
@@ -0,0 +1,450 @@
|
||||
package io.github.hectorvent.floci.services.ec2;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.path.xml.XmlPath;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
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 java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.matchesPattern;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* The calls aws_egress_only_internet_gateway makes: create with a VPC and TagSpecification, read
|
||||
* back by ID, tag, delete. Every read goes through a separate DescribeEgressOnlyInternetGateways
|
||||
* rather than trusting the create response.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class Ec2EgressOnlyInternetGatewayIntegrationTest {
|
||||
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/ec2/aws4_request";
|
||||
private static final String ITEM =
|
||||
"DescribeEgressOnlyInternetGatewaysResponse.egressOnlyInternetGatewaySet.item";
|
||||
|
||||
private static String vpcId;
|
||||
private static String eigwId;
|
||||
|
||||
private static RequestSpecification ec2() {
|
||||
return given().header("Authorization", AUTH_HEADER);
|
||||
}
|
||||
|
||||
private static ValidatableResponse describeById() {
|
||||
return ec2()
|
||||
.formParam("Action", "DescribeEgressOnlyInternetGateways")
|
||||
.formParam("EgressOnlyInternetGatewayId.1", eigwId)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createAttachesTheGatewayToTheVpcAndAppliesTags() {
|
||||
vpcId = ec2()
|
||||
.formParam("Action", "CreateVpc")
|
||||
.formParam("CidrBlock", "198.51.100.0/24")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().path("CreateVpcResponse.vpc.vpcId");
|
||||
|
||||
String created = "CreateEgressOnlyInternetGatewayResponse.egressOnlyInternetGateway";
|
||||
eigwId = ec2()
|
||||
.formParam("Action", "CreateEgressOnlyInternetGateway")
|
||||
.formParam("VpcId", vpcId)
|
||||
.formParam("TagSpecification.1.ResourceType", "egress-only-internet-gateway")
|
||||
.formParam("TagSpecification.1.Tag.1.Key", "Name")
|
||||
.formParam("TagSpecification.1.Tag.1.Value", "ipv6-egress")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(created + ".egressOnlyInternetGatewayId", matchesPattern("eigw-[0-9a-f]{17}"))
|
||||
.body(created + ".attachmentSet.item.vpcId", equalTo(vpcId))
|
||||
.body(created + ".attachmentSet.item.state", equalTo("attached"))
|
||||
.extract().path(created + ".egressOnlyInternetGatewayId");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void describeReturnsTheStoredGateway() {
|
||||
describeById()
|
||||
.body(ITEM + ".size()", equalTo(1))
|
||||
.body(ITEM + ".egressOnlyInternetGatewayId", equalTo(eigwId))
|
||||
.body(ITEM + ".attachmentSet.item.vpcId", equalTo(vpcId))
|
||||
.body(ITEM + ".attachmentSet.item.state", equalTo("attached"))
|
||||
.body(ITEM + ".tagSet.item.find { it.key == 'Name' }.value", equalTo("ipv6-egress"));
|
||||
|
||||
ec2()
|
||||
.formParam("Action", "DescribeEgressOnlyInternetGateways")
|
||||
.formParam("Filter.1.Name", "attachment.vpc-id")
|
||||
.formParam("Filter.1.Value.1", vpcId)
|
||||
.formParam("Filter.2.Name", "tag:Name")
|
||||
.formParam("Filter.2.Value.1", "ipv6-egress")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(ITEM + ".size()", equalTo(1))
|
||||
.body(ITEM + ".egressOnlyInternetGatewayId", equalTo(eigwId));
|
||||
|
||||
ec2()
|
||||
.formParam("Action", "DescribeEgressOnlyInternetGateways")
|
||||
.formParam("Filter.1.Name", "attachment.vpc-id")
|
||||
.formParam("Filter.1.Value.1", "vpc-00000000000000000")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(ITEM + ".size()", equalTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void createTagsReachesTheGateway() {
|
||||
ec2()
|
||||
.formParam("Action", "CreateTags")
|
||||
.formParam("ResourceId.1", eigwId)
|
||||
.formParam("Tag.1.Key", "Owner")
|
||||
.formParam("Tag.1.Value", "TeamA")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
describeById()
|
||||
.body(ITEM + ".tagSet.item.find { it.key == 'Owner' }.value", equalTo("TeamA"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void theVpcCannotBeDeletedWhileTheGatewayIsAttached() {
|
||||
ec2()
|
||||
.formParam("Action", "DeleteVpc")
|
||||
.formParam("VpcId", vpcId)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("DependencyViolation"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void createRejectsAnUnknownVpc() {
|
||||
ec2()
|
||||
.formParam("Action", "CreateEgressOnlyInternetGateway")
|
||||
.formParam("VpcId", "vpc-00000000000000000")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("InvalidVpcID.NotFound"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void createAndDeleteWithoutTheRequiredIdAreMissingParameter() {
|
||||
ec2()
|
||||
.formParam("Action", "CreateEgressOnlyInternetGateway")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("MissingParameter"));
|
||||
|
||||
ec2()
|
||||
.formParam("Action", "DeleteEgressOnlyInternetGateway")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("MissingParameter"))
|
||||
.body("Response.Errors.Error.Message",
|
||||
equalTo("The request must contain the parameter EgressOnlyInternetGatewayId"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void deleteRemovesTheGateway() {
|
||||
ec2()
|
||||
.formParam("Action", "DeleteEgressOnlyInternetGateway")
|
||||
.formParam("EgressOnlyInternetGatewayId", eigwId)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DeleteEgressOnlyInternetGatewayResponse.returnCode", equalTo("true"));
|
||||
|
||||
describeById().body(ITEM + ".size()", equalTo(0));
|
||||
|
||||
ec2()
|
||||
.formParam("Action", "DeleteEgressOnlyInternetGateway")
|
||||
.formParam("EgressOnlyInternetGatewayId", eigwId)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("InvalidGatewayID.NotFound"));
|
||||
|
||||
ec2()
|
||||
.formParam("Action", "DeleteVpc")
|
||||
.formParam("VpcId", vpcId)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void aRetriedCreateWithTheSameClientTokenReturnsTheFirstGateway() {
|
||||
String vpc = createVpc("198.51.100.0/25");
|
||||
String first = createWithToken(vpc, "eigw-retry-token")
|
||||
.statusCode(200)
|
||||
.extract().path("CreateEgressOnlyInternetGatewayResponse.egressOnlyInternetGateway"
|
||||
+ ".egressOnlyInternetGatewayId");
|
||||
String second = createWithToken(vpc, "eigw-retry-token")
|
||||
.statusCode(200)
|
||||
.extract().path("CreateEgressOnlyInternetGatewayResponse.egressOnlyInternetGateway"
|
||||
+ ".egressOnlyInternetGatewayId");
|
||||
assertEquals(first, second);
|
||||
|
||||
ec2()
|
||||
.formParam("Action", "DescribeEgressOnlyInternetGateways")
|
||||
.formParam("Filter.1.Name", "attachment.vpc-id")
|
||||
.formParam("Filter.1.Value.1", vpc)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(ITEM + ".size()", equalTo(1))
|
||||
.body(ITEM + ".egressOnlyInternetGatewayId", equalTo(first));
|
||||
|
||||
String otherVpc = createVpc("198.51.100.128/25");
|
||||
createWithToken(otherVpc, "eigw-retry-token")
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("IdempotentParameterMismatch"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void aReplayedClientTokenWithOtherTagsIsRejectedAndLeavesTheGatewayUntouched() {
|
||||
String vpc = createVpc("198.51.100.0/26");
|
||||
String first = createWithTokenAndName(vpc, "eigw-tag-token", "original")
|
||||
.statusCode(200)
|
||||
.extract().path("CreateEgressOnlyInternetGatewayResponse.egressOnlyInternetGateway"
|
||||
+ ".egressOnlyInternetGatewayId");
|
||||
|
||||
createWithTokenAndName(vpc, "eigw-tag-token", "changed")
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("IdempotentParameterMismatch"));
|
||||
|
||||
String replayed = createWithTokenAndName(vpc, "eigw-tag-token", "original")
|
||||
.statusCode(200)
|
||||
.extract().path("CreateEgressOnlyInternetGatewayResponse.egressOnlyInternetGateway"
|
||||
+ ".egressOnlyInternetGatewayId");
|
||||
assertEquals(first, replayed);
|
||||
|
||||
ec2()
|
||||
.formParam("Action", "DescribeEgressOnlyInternetGateways")
|
||||
.formParam("EgressOnlyInternetGatewayId.1", first)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(ITEM + ".tagSet.item.size()", equalTo(1))
|
||||
.body(ITEM + ".tagSet.item.value", equalTo("original"));
|
||||
deleteGateway(first);
|
||||
deleteVpc(vpc);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void aRejectedCreationTagLeavesNoGatewayBehind() {
|
||||
String vpc = createVpc("198.51.100.64/26");
|
||||
ec2()
|
||||
.formParam("Action", "CreateEgressOnlyInternetGateway")
|
||||
.formParam("VpcId", vpc)
|
||||
.formParam("TagSpecification.1.ResourceType", "egress-only-internet-gateway")
|
||||
.formParam("TagSpecification.1.Tag.1.Key", "aws:reserved")
|
||||
.formParam("TagSpecification.1.Tag.1.Value", "x")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("Response.Errors.Error.Code", equalTo("InvalidParameterValue"));
|
||||
|
||||
ec2()
|
||||
.formParam("Action", "DescribeEgressOnlyInternetGateways")
|
||||
.formParam("Filter.1.Name", "attachment.vpc-id")
|
||||
.formParam("Filter.1.Value.1", vpc)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(ITEM + ".size()", equalTo(0));
|
||||
|
||||
deleteVpc(vpc);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void describePagesThroughMaxResults() {
|
||||
String vpc = createVpc("198.51.100.192/26");
|
||||
Set<String> created = new HashSet<>();
|
||||
for (int i = 0; i < 6; i++) {
|
||||
created.add(createWithToken(vpc, "eigw-page-" + i)
|
||||
.statusCode(200)
|
||||
.extract().path("CreateEgressOnlyInternetGatewayResponse.egressOnlyInternetGateway"
|
||||
+ ".egressOnlyInternetGatewayId"));
|
||||
}
|
||||
Set<String> seen = new HashSet<>();
|
||||
String token = null;
|
||||
int pages = 0;
|
||||
do {
|
||||
RequestSpecification request = ec2()
|
||||
.formParam("Action", "DescribeEgressOnlyInternetGateways")
|
||||
.formParam("Filter.1.Name", "attachment.vpc-id")
|
||||
.formParam("Filter.1.Value.1", vpc)
|
||||
.formParam("MaxResults", "5");
|
||||
if (token != null) {
|
||||
request.formParam("NextToken", token);
|
||||
}
|
||||
XmlPath page = request.when().post("/").then().statusCode(200)
|
||||
.extract().xmlPath();
|
||||
List<String> ids = page.getList(ITEM + ".egressOnlyInternetGatewayId");
|
||||
assertEquals(pages == 0 ? 5 : 1, ids.size());
|
||||
seen.addAll(ids);
|
||||
token = page.getString("DescribeEgressOnlyInternetGatewaysResponse.nextToken");
|
||||
token = token == null || token.isEmpty() ? null : token;
|
||||
pages++;
|
||||
} while (token != null && pages < 5);
|
||||
assertEquals(2, pages);
|
||||
assertEquals(created, seen);
|
||||
created.forEach(Ec2EgressOnlyInternetGatewayIntegrationTest::deleteGateway);
|
||||
deleteVpc(vpc);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void aRouteToADeletedGatewayBecomesABlackhole() {
|
||||
String vpc = createVpc("198.51.100.32/27");
|
||||
String gateway = createWithToken(vpc, "eigw-route-token")
|
||||
.statusCode(200)
|
||||
.extract().path("CreateEgressOnlyInternetGatewayResponse.egressOnlyInternetGateway"
|
||||
+ ".egressOnlyInternetGatewayId");
|
||||
String table = ec2()
|
||||
.formParam("Action", "CreateRouteTable")
|
||||
.formParam("VpcId", vpc)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().path("CreateRouteTableResponse.routeTable.routeTableId");
|
||||
ec2()
|
||||
.formParam("Action", "CreateRoute")
|
||||
.formParam("RouteTableId", table)
|
||||
.formParam("DestinationIpv6CidrBlock", "::/0")
|
||||
.formParam("EgressOnlyInternetGatewayId", gateway)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
String route = "DescribeRouteTablesResponse.routeTableSet.item.routeSet.item"
|
||||
+ ".find { it.egressOnlyInternetGatewayId == '" + gateway + "' }";
|
||||
describeRouteTable(table).body(route + ".state", equalTo("active"));
|
||||
|
||||
deleteGateway(gateway);
|
||||
|
||||
describeRouteTable(table)
|
||||
.body(route + ".state", equalTo("blackhole"))
|
||||
.body(route + ".destinationIpv6CidrBlock", equalTo("::/0"));
|
||||
|
||||
ec2()
|
||||
.formParam("Action", "DeleteRouteTable")
|
||||
.formParam("RouteTableId", table)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
deleteVpc(vpc);
|
||||
}
|
||||
|
||||
private static void deleteVpc(String vpc) {
|
||||
ec2()
|
||||
.formParam("Action", "DeleteVpc")
|
||||
.formParam("VpcId", vpc)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
private static ValidatableResponse describeRouteTable(String table) {
|
||||
return ec2()
|
||||
.formParam("Action", "DescribeRouteTables")
|
||||
.formParam("RouteTableId.1", table)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
private static void deleteGateway(String gateway) {
|
||||
ec2()
|
||||
.formParam("Action", "DeleteEgressOnlyInternetGateway")
|
||||
.formParam("EgressOnlyInternetGatewayId", gateway)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
private static ValidatableResponse createWithTokenAndName(String vpc, String token, String name) {
|
||||
return ec2()
|
||||
.formParam("Action", "CreateEgressOnlyInternetGateway")
|
||||
.formParam("VpcId", vpc)
|
||||
.formParam("ClientToken", token)
|
||||
.formParam("TagSpecification.1.ResourceType", "egress-only-internet-gateway")
|
||||
.formParam("TagSpecification.1.Tag.1.Key", "Name")
|
||||
.formParam("TagSpecification.1.Tag.1.Value", name)
|
||||
.when()
|
||||
.post("/")
|
||||
.then();
|
||||
}
|
||||
|
||||
private static String createVpc(String cidr) {
|
||||
return ec2()
|
||||
.formParam("Action", "CreateVpc")
|
||||
.formParam("CidrBlock", cidr)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().path("CreateVpcResponse.vpc.vpcId");
|
||||
}
|
||||
|
||||
private static ValidatableResponse createWithToken(String vpc, String token) {
|
||||
return ec2()
|
||||
.formParam("Action", "CreateEgressOnlyInternetGateway")
|
||||
.formParam("VpcId", vpc)
|
||||
.formParam("ClientToken", token)
|
||||
.when()
|
||||
.post("/")
|
||||
.then();
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -89,12 +89,12 @@ class Ec2ServicePersistenceTest {
|
||||
void emptyNetworkDiscoverySurvivesRestart(@TempDir Path dir) {
|
||||
Ec2Service first = newService(dir);
|
||||
assertTrue(first.describeVpnGatewayIds(List.of(), Map.of()).isEmpty());
|
||||
assertTrue(first.describeEgressOnlyInternetGatewayIds(Map.of()).isEmpty());
|
||||
assertTrue(first.describeEgressOnlyInternetGateways("us-east-1", List.of(), Map.of()).isEmpty());
|
||||
|
||||
Ec2Service restarted = newService(dir);
|
||||
assertTrue(restarted.describeVpnGatewayIds(
|
||||
List.of(), Map.of("attachment.vpc-id", List.of("vpc-0123456789abcdef0"))).isEmpty());
|
||||
assertTrue(restarted.describeEgressOnlyInternetGatewayIds(Map.of("tag:Owner", List.of("TeamA"))).isEmpty());
|
||||
assertTrue(restarted.describeEgressOnlyInternetGateways("us-east-1", List.of(), Map.of("tag:Owner", List.of("TeamA"))).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -12,6 +12,7 @@ import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Address;
|
||||
import io.github.hectorvent.floci.services.ec2.model.BlockDeviceMapping;
|
||||
import io.github.hectorvent.floci.services.ec2.model.EbsBlockDevice;
|
||||
import io.github.hectorvent.floci.services.ec2.model.EgressOnlyInternetGateway;
|
||||
import io.github.hectorvent.floci.services.ec2.model.GroupIdentifier;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Image;
|
||||
import io.github.hectorvent.floci.services.ec2.model.Instance;
|
||||
@@ -69,6 +70,7 @@ import org.mockito.InOrder;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.interfaces.RSAPrivateCrtKey;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
@@ -761,18 +763,92 @@ class Ec2ServiceTest {
|
||||
"tag-value", List.of("TeamA"));
|
||||
|
||||
for (Map.Entry<String, List<String>> filter : supportedFilters.entrySet()) {
|
||||
assertTrue(service.describeEgressOnlyInternetGatewayIds(
|
||||
assertTrue(service.describeEgressOnlyInternetGateways("us-east-1", List.of(),
|
||||
Map.of(filter.getKey(), filter.getValue())).isEmpty());
|
||||
}
|
||||
|
||||
AwsException filterError = assertThrows(AwsException.class,
|
||||
() -> service.describeEgressOnlyInternetGatewayIds(
|
||||
() -> service.describeEgressOnlyInternetGateways("us-east-1", List.of(),
|
||||
Map.of("unsupported", List.of("value"))));
|
||||
assertEquals("InvalidParameterValue", filterError.getErrorCode());
|
||||
assertEquals("The filter 'unsupported' is invalid", filterError.getMessage());
|
||||
assertEquals(400, filterError.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void egressOnlyInternetGatewayDeleteWaitsForTheLockTagWritesTake() throws Exception {
|
||||
Ec2Service service = new Ec2Service(mockConfig(true), mock(Ec2ContainerManager.class),
|
||||
mock(Ec2PortForwardManager.class),
|
||||
mock(AmiImageResolver.class), mock(Ec2ImageCatalog.class), new Ec2InstanceTypeCatalog(),
|
||||
new InMemoryStorageFactory());
|
||||
String region = "us-east-1";
|
||||
String vpcId = service.createVpc(region, "10.43.0.0/16", false).getVpcId();
|
||||
String eigwId = service.createEgressOnlyInternetGateway(region, vpcId, null, List.of())
|
||||
.getEgressOnlyInternetGatewayId();
|
||||
Method lockFor = Ec2Service.class.getDeclaredMethod("lockFor", String.class);
|
||||
lockFor.setAccessible(true);
|
||||
Object tagLock = lockFor.invoke(service, region + "::" + eigwId);
|
||||
AtomicReference<Thread> deleter = new AtomicReference<>();
|
||||
ExecutorService worker = Executors.newSingleThreadExecutor();
|
||||
try {
|
||||
Future<?> deleting;
|
||||
synchronized (tagLock) {
|
||||
deleting = worker.submit(() -> {
|
||||
deleter.set(Thread.currentThread());
|
||||
service.deleteEgressOnlyInternetGateway(region, eigwId);
|
||||
});
|
||||
Awaitility.await().atMost(Duration.ofSeconds(5)).until(() -> deleting.isDone()
|
||||
|| (deleter.get() != null && deleter.get().getState() == Thread.State.BLOCKED));
|
||||
assertFalse(deleting.isDone(), "delete must take the gateway's tag lock");
|
||||
}
|
||||
deleting.get(5, TimeUnit.SECONDS);
|
||||
assertTrue(service.describeEgressOnlyInternetGateways(region, List.of(eigwId), Map.of()).isEmpty());
|
||||
} finally {
|
||||
worker.shutdownNow();
|
||||
assertTrue(worker.awaitTermination(5, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void egressOnlyInternetGatewayIsCreatedDescribedAndDeleted() {
|
||||
Ec2Service service = new Ec2Service(mockConfig(true), mock(Ec2ContainerManager.class),
|
||||
mock(Ec2PortForwardManager.class),
|
||||
mock(AmiImageResolver.class), mock(Ec2ImageCatalog.class), new Ec2InstanceTypeCatalog(),
|
||||
new InMemoryStorageFactory());
|
||||
String region = "us-east-1";
|
||||
String vpcId = service.createVpc(region, "10.42.0.0/16", false).getVpcId();
|
||||
|
||||
AwsException noVpc = assertThrows(AwsException.class,
|
||||
() -> service.createEgressOnlyInternetGateway(region, "vpc-00000000000000000", null, List.of()));
|
||||
assertEquals("InvalidVpcID.NotFound", noVpc.getErrorCode());
|
||||
|
||||
String eigwId = service.createEgressOnlyInternetGateway(region, vpcId, null, List.of())
|
||||
.getEgressOnlyInternetGatewayId();
|
||||
assertTrue(eigwId.matches("eigw-[0-9a-f]{17}"), eigwId);
|
||||
service.createTags(region, List.of(eigwId), List.of(new Tag("Owner", "TeamA")));
|
||||
|
||||
List<EgressOnlyInternetGateway> found = service.describeEgressOnlyInternetGateways(region, List.of(eigwId), Map.of());
|
||||
assertEquals(1, found.size());
|
||||
assertEquals(vpcId, found.getFirst().getAttachments().getFirst().getVpcId());
|
||||
assertEquals("attached", found.getFirst().getAttachments().getFirst().getState());
|
||||
assertEquals("TeamA", found.getFirst().getTags().getFirst().getValue());
|
||||
assertEquals(1, service.describeEgressOnlyInternetGateways(region, List.of(),
|
||||
Map.of("attachment.vpc-id", List.of(vpcId), "tag:Owner", List.of("TeamA"))).size());
|
||||
assertTrue(service.describeEgressOnlyInternetGateways(region, List.of(),
|
||||
Map.of("attachment.state", List.of("detached"))).isEmpty());
|
||||
assertTrue(service.describeEgressOnlyInternetGateways("eu-west-1", List.of(eigwId), Map.of()).isEmpty());
|
||||
|
||||
AwsException vpcInUse = assertThrows(AwsException.class, () -> service.deleteVpc(region, vpcId));
|
||||
assertEquals("DependencyViolation", vpcInUse.getErrorCode());
|
||||
|
||||
service.deleteEgressOnlyInternetGateway(region, eigwId);
|
||||
assertTrue(service.describeEgressOnlyInternetGateways(region, List.of(eigwId), Map.of()).isEmpty());
|
||||
AwsException gone = assertThrows(AwsException.class,
|
||||
() -> service.deleteEgressOnlyInternetGateway(region, eigwId));
|
||||
assertEquals("InvalidGatewayID.NotFound", gone.getErrorCode());
|
||||
service.deleteVpc(region, vpcId);
|
||||
}
|
||||
|
||||
@Test
|
||||
void mockModeTreatsExistingNonTerminatedInstanceAsRunningContainer() {
|
||||
Ec2ContainerManager containerManager = mock(Ec2ContainerManager.class);
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
# way to land here. A name two services define then goes to the one tried first, which
|
||||
# is a gap when that one does not handle the name.
|
||||
#
|
||||
# 171 entries: 171 unrouted, 0 claimed by another service.
|
||||
# 170 entries: 170 unrouted, 0 claimed by another service.
|
||||
#
|
||||
# Shrink this file, never grow it. Removing a line is the point; adding one needs a
|
||||
# reason in the PR that adds it. AwsQueryActionRoutingParityTest fails on an entry that
|
||||
@@ -43,7 +43,7 @@ cloudformation ActivateOrganizationsAccess sqs
|
||||
cloudformation DescribeOrganizationsAccess sqs
|
||||
cloudformation ListStackSetAutoDeploymentTargets sqs
|
||||
|
||||
# ec2: 83 (83 unrouted, 0 claimed elsewhere)
|
||||
# ec2: 82 (82 unrouted, 0 claimed elsewhere)
|
||||
ec2 AcceptVpcPeeringConnection sqs
|
||||
ec2 AllocateHosts sqs
|
||||
ec2 AllocateIpamPoolCidr sqs
|
||||
@@ -70,7 +70,6 @@ ec2 DeleteTransitGatewayRoute sqs
|
||||
ec2 DeleteTransitGatewayRouteTable sqs
|
||||
ec2 DeleteTransitGatewayVpcAttachment sqs
|
||||
ec2 DeleteVpcPeeringConnection sqs
|
||||
ec2 DescribeEgressOnlyInternetGateways sqs
|
||||
ec2 DescribeHosts sqs
|
||||
ec2 DescribeInstanceCreditSpecifications sqs
|
||||
ec2 DescribeIpamByoasn sqs
|
||||
|
||||
|
Reference in new issue
Block a user