feat(lambda): support extra /etc/hosts entries on Lambda launch (#2073)

* feat(lambda): support extra /etc/hosts entries via FLOCI_SERVICES_LAMBDA_EXTRA_HOSTS

* feat(lambda): support ipv6 addresses.

---------

Co-authored-by: Florian Overfelt <joverfelt@meso-scale.com>
This commit is contained in:
floverfeltandFlorian Overfelt authored and GitHub committed 2026-08-04 21:50:25 -05:00
1 parent fa96b791b4
commit b543aa4baa
5 files changed
+71

No files matched your search

@@ -88,6 +88,7 @@ class ContainerLauncherTest {
when(config.services()).thenReturn(services);
when(services.lambda()).thenReturn(lambda);
when(lambda.dockerNetwork()).thenReturn(Optional.empty());
lenient().when(lambda.extraHosts()).thenReturn(Optional.empty());
lenient().when(lambda.awsConfigPath()).thenReturn(Optional.empty());
when(config.docker()).thenReturn(docker);
when(docker.logMaxSize()).thenReturn("10m");
@@ -490,6 +491,53 @@ class ContainerLauncherTest {
"AWS_SESSION_TOKEN should not be injected when awsConfigPath is set");
}
@Test
void launchFunction_appliesConfiguredExtraHosts_skippingMalformedEntries() throws Exception {
EmulatorConfig.LambdaServiceConfig lambda = config.services().lambda();
when(lambda.extraHosts()).thenReturn(Optional.of(List.of(
"localhost:host-gateway", "db.internal:10.0.0.5",
"v6.internal:2001:db8::1", "v6end.internal:fd00::",
"malformed", ":9.9.9.9", "trailing:")));
Path codePath = Files.createDirectory(tempDir.resolve("extra-hosts"));
LambdaFunction fn = new LambdaFunction();
fn.setFunctionName("extra-hosts-fn");
fn.setRuntime("nodejs20.x");
fn.setHandler("index.handler");
fn.setCodeLocalPath(codePath.toString());
launcher.launch(fn);
List<String> extraHosts = captureRealContainerSpec().extraHosts();
assertTrue(extraHosts.contains("localhost:host-gateway"),
"configured hostname:host-gateway entry should be applied");
assertTrue(extraHosts.contains("db.internal:10.0.0.5"),
"configured hostname:ip entry should be applied");
assertTrue(extraHosts.contains("v6.internal:2001:db8::1"),
"IPv6 addresses (containing colons) must survive the hostname/ip split");
assertTrue(extraHosts.contains("v6end.internal:fd00::"),
"IPv6 addresses ending in :: must not be classified as missing an ip");
assertEquals(4, extraHosts.size(),
"entries without a hostname and an ip must be skipped, not passed to Docker");
}
@Test
void launchFunction_noExtraHostsByDefault() throws Exception {
Path codePath = Files.createDirectory(tempDir.resolve("no-extra-hosts"));
LambdaFunction fn = new LambdaFunction();
fn.setFunctionName("no-extra-hosts-fn");
fn.setRuntime("nodejs20.x");
fn.setHandler("index.handler");
fn.setCodeLocalPath(codePath.toString());
launcher.launch(fn);
assertTrue(captureRealContainerSpec().extraHosts().isEmpty(),
"no extra hosts when the config is unset (non-Linux host in this test)");
}
@Test
void launchFunction_noAwsConfigPath_noBindMount() throws Exception {
Path codePath = Files.createDirectory(tempDir.resolve("no-aws-config"));