feat(ec2): config toggle to report the AWS-faithful private IP (#2024)

* feat(ec2): config toggle to report the AWS-faithful private IP (#1983)

DescribeInstances reported the Docker container's bridge IP as PrivateIpAddress,
disagreeing with CloudFormation's subnet-allocated IP. Rather than force a
fidelity-vs-reachability tradeoff, this adds an opt-in:

  ec2.aws-faithful-private-ip (default false)

Default (false) is unchanged: the reported private IP is the reachable container
bridge IP, so instances can reach each other at that address on the shared
Docker network. When true, the CFN/subnet-allocated private IP set at launch is
reported instead (AWS-faithful); routing and IMDS always use the container
bridge IP (tracked separately as containerBridgeIp) regardless of the flag.

Wired via a new awsFaithful overload of exposeReachablePrivateAddress; the three
call sites pass the config flag. Test covers both modes.

Fixes #1983.

* docs(ec2): list aws-faithful-private-ip in application.yml and the config table

Every other floci.services.ec2 knob appears in both application.yml files and
the docs configuration table; this one was declared only on EmulatorConfig, so a
user-facing flag was undiscoverable.
This commit is contained in:
lex00 authored and GitHub committed 2026-08-15 18:48:49 -05:00
1 parent 5e01c07b33
commit 33d35b2079
6 files changed
+55 -4

No files matched your search

@@ -47,6 +47,7 @@ import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Answers.RETURNS_SELF;
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.timeout;
@@ -87,6 +88,27 @@ class Ec2ContainerManagerTest {
assertEquals("ip-192-168-215-21.ec2.internal", networkInterface.getPrivateDnsName());
}
@Test
void exposeReachablePrivateAddressPreservesAllocatedIpWhenAwsFaithful() {
// #1983: with awsFaithfulPrivateIp=true, the CFN/subnet-allocated private
// IP set at launch is left untouched — the container bridge IP is not
// reported (routing still uses it via containerBridgeIp, tracked elsewhere).
Instance instance = new Instance();
instance.setPrivateIpAddress("10.82.32.10");
instance.setPrivateDnsName("ip-10-82-32-10.ec2.internal");
InstanceNetworkInterface networkInterface = new InstanceNetworkInterface();
networkInterface.setPrivateIpAddress("10.82.32.10");
networkInterface.setPrivateDnsName("ip-10-82-32-10.ec2.internal");
instance.setNetworkInterfaces(List.of(networkInterface));
Ec2ContainerManager.exposeReachablePrivateAddress(instance, "192.168.215.21", true);
assertEquals("10.82.32.10", instance.getPrivateIpAddress());
assertEquals("ip-10-82-32-10.ec2.internal", instance.getPrivateDnsName());
assertEquals("10.82.32.10", networkInterface.getPrivateIpAddress());
}
@Test
void restoreMetadataRegistrationRegistersRunningPersistedContainer() {
ContainerLifecycleManager lifecycleManager = mock(ContainerLifecycleManager.class);
@@ -107,7 +129,7 @@ class Ec2ContainerManagerTest {
mock(DockerHostResolver.class),
dockerClient,
mock(PortAllocator.class),
mock(EmulatorConfig.class),
mock(EmulatorConfig.class, RETURNS_DEEP_STUBS),
metadataServer,
mock(Ec2PortForwardManager.class));