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

@@ -1545,6 +1545,18 @@ public interface EmulatorConfig {
@WithDefault("true")
boolean enabled();
/**
* When true, DescribeInstances and IMDS report each instance's CFN- and
* subnet-allocated private IP (AWS-faithful) instead of the Docker
* container's bridge IP (#1983). Default false keeps the bridge IP as the
* reported private address, which lets instances reach each other at that
* address on the shared Docker network. Routing/IMDS always use the
* container bridge IP regardless of this flag; only the reported
* PrivateIpAddress changes.
*/
@WithDefault("false")
boolean awsFaithfulPrivateIp();
/** Port on the Floci host for the IMDS HTTP server (169.254.169.254 equivalent). */
@WithDefault("9169")
int imdsPort();
@@ -192,7 +192,7 @@ public class Ec2ContainerManager {
String containerIp = waitForContainerBridgeIp(containerId, instanceId);
if (containerIp != null && !containerIp.isBlank()) {
instance.setContainerBridgeIp(containerIp);
exposeReachablePrivateAddress(instance, containerIp);
exposeReachablePrivateAddress(instance, containerIp, config.services().ec2().awsFaithfulPrivateIp());
metadataServer.registerContainer(containerIp, instanceId, instance);
}
else {
@@ -321,7 +321,7 @@ public class Ec2ContainerManager {
String containerIp = waitForContainerBridgeIp(containerId, instanceId);
if (containerIp != null && !containerIp.isBlank()) {
instance.setContainerBridgeIp(containerIp);
exposeReachablePrivateAddress(instance, containerIp);
exposeReachablePrivateAddress(instance, containerIp, config.services().ec2().awsFaithfulPrivateIp());
metadataServer.registerContainer(containerIp, instanceId, instance);
}
} catch (InterruptedException e) {
@@ -361,15 +361,29 @@ public class Ec2ContainerManager {
metadataServer.unregisterContainer(previousContainerIp, instance);
}
instance.setContainerBridgeIp(containerIp);
exposeReachablePrivateAddress(instance, containerIp);
exposeReachablePrivateAddress(instance, containerIp, config.services().ec2().awsFaithfulPrivateIp());
metadataServer.registerContainer(containerIp, instance.getInstanceId(), instance);
return true;
}
static void exposeReachablePrivateAddress(Instance instance, String privateIp) {
exposeReachablePrivateAddress(instance, privateIp, false);
}
/**
* Overwrite the instance's reported private address with the container's
* reachable bridge IP — unless {@code awsFaithful} is true (#1983), in which
* case the CFN/subnet-allocated private IP set at launch is left untouched.
* The container bridge IP is tracked separately (setContainerBridgeIp) and
* used for routing/IMDS regardless of this flag.
*/
static void exposeReachablePrivateAddress(Instance instance, String privateIp, boolean awsFaithful) {
if (instance == null || privateIp == null || privateIp.isBlank()) {
return;
}
if (awsFaithful) {
return;
}
String privateDnsName = "ip-" + privateIp.replace('.', '-') + ".ec2.internal";
instance.setPrivateIpAddress(privateIp);