mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
* fix(ec2): assign mock public addresses and displace earlier Elastic IPs In mock mode an instance never received a public IPv4 address, whatever its subnet's MapPublicIpOnLaunch or its launch's AssociatePublicIpAddress said, and an associated Elastic IP never reached DescribeInstances. - A mock instance that asks for a public address gets one when it reaches running, whether DescribeInstances, DescribeInstanceStatus or StartInstances completes the launch. Stop and termination release it. An associated Elastic IP replaces it and survives a stop; disassociating it gives a running instance a new automatic address when its launch asked for one. - AssociateAddress disassociates the Elastic IP an instance already has, including one a retained interface carried onto it, as the AssociateAddress reference describes. - Launches from a template take AssociatePublicIpAddress from its device-index-0 interface (RunInstances, CreateFleet, Auto Scaling), and RunInstances and CreateFleet also take that interface's subnet. - RunInstances refuses an instance-level SubnetId combined with network interfaces, on the request or in its launch template, with InvalidParameterCombination. Split out of #5671 at review. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * fix(ec2): scope Elastic IP displacement and automatic addresses as AWS does - AssociateAddress ignored PrivateIpAddress, so an Elastic IP meant for a secondary private address displaced the one on the primary. The address is now recorded on the private address it names, only an address already on that private address is displaced, the interface shows it there, and in mock mode only the primary's address becomes the instance's public address. - An instance launched on an existing network interface got an automatic public address; AWS assigns one only to an interface the launch creates. - A released automatic address was replaced while a second interface was attached; AWS does not replace it then. - An Elastic IP that a retained interface carried to a new instance stayed without an instance. It now names that instance, which shows the address and keeps it across a stop. - A mock launch could complete over a concurrent stop or termination, and DescribeAddresses could write back an address disassociated meanwhile; both now re-check under the instance's lock. The tests also cover a request's own network interfaces with an instance-level SubnetId, and the template interface docs now say which launches take the subnet. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * fix(ec2): settle second-review findings on mock public addresses - DescribeAddresses re-points associated addresses under the allocation lock, and a mock launch, start or stop reads the instance's Elastic IP under it, so none of them acts on an association written halfway or changed meanwhile. - An Elastic IP that a retained interface carries is found through that interface, also when it is disassociated, instead of being rebound to the next instance at launch, which left a dead InstanceId behind when a container launch failed. - StartInstances leaves a running mock instance alone. - In container mode too, an address on a secondary private address no longer becomes the instance's public address. - The second-interface test associates its address before attaching the interface, since AssociateAddress by InstanceId needs exactly one. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * fix(ec2): keep terminated mock instances down and address reads unblocked - StopInstances leaves a terminated or shutting-down mock instance as it is, re-checked under the lock, so terminate, stop and start no longer revives it with a public address. - DescribeAddresses waits for the allocation lock only when an address is associated with an instance, and the container re-point no longer rewrites an unchanged instance. - A mock start treats a state without a name as settled instead of throwing. Tests now cover the terminated instance and, with a reachable container address, an Elastic IP on a secondary private address leaving the instance's public address alone. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * fix(ec2): settle Qodo findings on mock public addresses - AssociateAddress refuses a PrivateIpAddress that is neither the instance's primary private address nor a secondary address of its primary interface, with InvalidParameterValue and before any association changes, instead of treating it as the primary and displacing the Elastic IP already there. - RunInstances from a launch template whose device-index-0 interface names an existing NetworkInterfaceId launches on that interface, in its subnet and without an automatic public address, as a request naming it would, instead of on a new interface in the default subnet. - The SubnetId-with-interfaces refusal test now launches against a real subnet and checks that the refused request leaves no instance or interface behind. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * fix(ec2): accept a container instance's launch address in AssociateAddress In container mode without AWS-faithful private addresses, the container manager replaces the instance's reported private address with its Docker bridge address once the container runs, and nothing keeps the subnet address RunInstances returned. The new PrivateIpAddress check therefore refused that address with InvalidParameterValue, though callers may still name it. Only mock mode and the AWS-faithful mode, which keep the launch address, now refuse a stray PrivateIpAddress; elsewhere any value means the primary address, as before. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * fix(ec2): decide automatic public addresses the same way with containers The public IPv4 rules were applied to mock instances only. A container-backed instance kept its address after a stop and a termination, got one on an existing network interface, kept its reachable address after its Elastic IP was disassociated even when the launch never asked for one, and had a released address replaced while a second interface was attached. One rule, AutomaticPublicAddress, now decides whether an instance has an automatic address in both modes: the launch asked for one on an interface the launch created (recorded when the instance is built), a stop, a termination or a disassociated Elastic IP releases it, and a replacement is held back while a second interface is attached. An Elastic IP on the primary private address still takes precedence. Only the value differs by mode: the container's reachable address, or an invented one where there is no container. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * fix(ec2): settle review findings on the shared public address rule - DisassociateAddress decides by the association, not by comparing addresses: only an Elastic IP on the instance's primary private address gives way to another one left there, or to an automatic address when one is due. With a container, every Elastic IP points at the one reachable address, so disassociating a secondary one no longer clears the instance's public address, and one a restart moved no longer survives its disassociation. - StartInstances on a stopped container instance releases an automatic address that a stop outside StopInstances, such as Floci's shutdown, left in place, so the start decides afresh. - With a container, these writes no longer wait on the instance's lock while holding the allocation lock, since the port-forward manager holds that lock across Docker calls. - A start test case now keeps an address distinct from the one it expects, and two comments describe the flag as it now is. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * fix(ec2): release only the primary interface's Elastic IP on disassociation - DisassociateAddress treats an Elastic IP as the instance's public one only when it sits on the primary interface, not on a retained interface attached at another device index, so disassociating that one no longer clears the instance's automatic address. - With a container, DescribeAddresses no longer writes a re-pointed address back onto a terminated or shutting-down instance. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * fix(ec2): show a carried Elastic IP on a container instance's launch - An instance launched on a retained interface that still carries an Elastic IP records that address at RunInstances, and the container launch re-points it once the container runs. With containers, such an instance had no public address until a stop and start, since the shared rule gives an existing interface no automatic address. - With a container, TerminateInstances clears the public address under the allocation lock, so a DescribeAddresses re-point already under way cannot write it back onto the terminated instance. - The secondary-interface disassociation test checks the address was still associated before the call and is not after it. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * fix(ec2): re-point a carried Elastic IP at its new instance - DescribeAddresses re-points an Elastic IP that a retained interface carries at the instance that interface is now the primary interface of. With containers, the address otherwise kept the previous container's address for good, since termination clears its instance id. - With a container, StopInstances leaves a terminated or shutting-down instance alone, as mock mode does, instead of stopping it into a startable state and writing its Elastic IP back. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * fix(ec2): give mock instances no invented public address by default Mock instances due an automatic public IPv4 address got a random 54.x.x.x one, a real AWS range, so a tool that connected to it reached someone else's host. The new floci.services.ec2.mock-public-addresses setting (FLOCI_SERVICES_EC2_MOCK_PUBLIC_ADDRESSES) chooses the address: none (the default) gives none, documentation draws distinct addresses from 203.0.113.0/24 as Lightsail and EMR do, and fixed gives every instance mock-public-address (default 127.0.0.1), an address the caller can reach. Only the value changes. The launch still records whether it asked for an address, so the shared rule and Elastic IP precedence work as before, and instances with containers keep reporting their reachable address. Elastic IP allocation still draws from 54.x.x.x, as on main. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * fix(ec2): settle review findings on the mock public address setting A configured mock-public-address with surrounding spaces was reported as is; it is now stripped. The docs and the AutomaticPublicAddress Javadoc no longer describe every mock instance as getting an address, and the test configurations that launch mock instances name the setting instead of leaving it null. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * fix(ec2): allocate Elastic IPs from the documentation range AllocateAddress handed out random 54.x.x.x addresses, a real AWS range, and this branch shows an associated Elastic IP as a mock instance's public address, so even with mock-public-addresses at none a client could reach someone else's host through one. Elastic IPs now come from 203.0.113.0/24 in every mode, distinct from the account's other Elastic IPs and its instances' public addresses; once all 254 are taken AllocateAddress fails with AddressLimitExceeded rather than repeat one, since callers name an Elastic IP by its address. Under mock-public-addresses: fixed, an Elastic IP on a mock instance's primary private address is re-pointed at the configured address, as one on a container instance is at the container's reachable address, and disassociation restores the allocated address. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * fix(ec2): settle review findings on documentation-range Elastic IPs An Elastic IP re-pointed at the fixed address kept it after a restart under another setting; the next read now shows its allocated address again. The re-point Javadoc and the Elastic IP docs no longer claim a 54.x.x.x allocation or addresses that never repeat, the docs say that earlier allocations keep their address until released, and a test now proves an allocation skips the addresses instances hold. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> --------- Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>