diff --git a/src/main/java/io/github/hectorvent/floci/config/TlsConfigSource.java b/src/main/java/io/github/hectorvent/floci/config/TlsConfigSource.java index e02467957c..fdfee24d4b 100644 --- a/src/main/java/io/github/hectorvent/floci/config/TlsConfigSource.java +++ b/src/main/java/io/github/hectorvent/floci/config/TlsConfigSource.java @@ -49,6 +49,11 @@ public class TlsConfigSource implements ConfigSource { private static final String TLS_DIR = "tls"; private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + // host.docker.internal: how Lambda containers reach Floci when it runs on the host (not in a container). + private static final List DEFAULT_SAN_HOSTNAMES = List.of( + "localhost", "127.0.0.1", "0.0.0.0", "*.localhost", + "localhost.floci.io", "*.localhost.floci.io", "host.docker.internal"); + private final Map properties = new HashMap<>(); public TlsConfigSource() { @@ -77,8 +82,7 @@ public class TlsConfigSource implements ConfigSource { // Extract current hostname configuration List customHostnames = extractCustomHostnames(); List currentHostnames = new ArrayList<>(); - currentHostnames.addAll(List.of("localhost", "127.0.0.1", "0.0.0.0", "*.localhost", - "localhost.floci.io", "*.localhost.floci.io")); + currentHostnames.addAll(DEFAULT_SAN_HOSTNAMES); currentHostnames.addAll(customHostnames); // Regenerate when the hostname config changed, or when the existing certificate @@ -170,8 +174,7 @@ public class TlsConfigSource implements ConfigSource { // Extract custom hostnames and combine with defaults List customHostnames = extractCustomHostnames(); List allSans = new ArrayList<>(); - allSans.addAll(List.of("localhost", "127.0.0.1", "0.0.0.0", "*.localhost", - "localhost.floci.io", "*.localhost.floci.io")); + allSans.addAll(DEFAULT_SAN_HOSTNAMES); allSans.addAll(customHostnames); CertificateGenerator gen = new CertificateGenerator(); diff --git a/src/test/java/io/github/hectorvent/floci/config/TlsCertificateHostnameTest.java b/src/test/java/io/github/hectorvent/floci/config/TlsCertificateHostnameTest.java index 3c348e266c..51bdb4955c 100644 --- a/src/test/java/io/github/hectorvent/floci/config/TlsCertificateHostnameTest.java +++ b/src/test/java/io/github/hectorvent/floci/config/TlsCertificateHostnameTest.java @@ -229,7 +229,7 @@ class TlsCertificateHostnameTest { List sans = extractSansFromCertificate(cert); Set expectedSans = Set.of("localhost", "127.0.0.1", "0.0.0.0", "*.localhost", - "localhost.floci.io", "*.localhost.floci.io"); + "localhost.floci.io", "*.localhost.floci.io", "host.docker.internal"); Set actualSans = new HashSet<>(sans); assertEquals(expectedSans, actualSans, @@ -252,7 +252,7 @@ class TlsCertificateHostnameTest { List sans = extractSansFromCertificate(cert); Set expectedSans = Set.of("localhost", "127.0.0.1", "0.0.0.0", "*.localhost", - "localhost.floci.io", "*.localhost.floci.io"); + "localhost.floci.io", "*.localhost.floci.io", "host.docker.internal"); Set actualSans = new HashSet<>(sans); assertEquals(expectedSans, actualSans, diff --git a/src/test/java/io/github/hectorvent/floci/config/TlsConfigSourceCertificateGenerationTest.java b/src/test/java/io/github/hectorvent/floci/config/TlsConfigSourceCertificateGenerationTest.java index 1c18e5228e..0cd44ad27c 100644 --- a/src/test/java/io/github/hectorvent/floci/config/TlsConfigSourceCertificateGenerationTest.java +++ b/src/test/java/io/github/hectorvent/floci/config/TlsConfigSourceCertificateGenerationTest.java @@ -158,9 +158,12 @@ class TlsConfigSourceCertificateGenerationTest { assertTrue(sans.contains("0.0.0.0"), "Certificate SANs should include default '0.0.0.0'"); + assertTrue(sans.contains("host.docker.internal"), + "Certificate SANs should include default 'host.docker.internal'"); + // Should not contain any custom hostnames - assertEquals(6, sans.size(), - "Certificate SANs should contain exactly 6 default entries (localhost, 127.0.0.1, 0.0.0.0, *.localhost, localhost.floci.io, *.localhost.floci.io)"); + assertEquals(7, sans.size(), + "Certificate SANs should contain exactly 7 default entries (localhost, 127.0.0.1, 0.0.0.0, *.localhost, localhost.floci.io, *.localhost.floci.io, host.docker.internal)"); } /** diff --git a/src/test/java/io/github/hectorvent/floci/config/TlsConfigSourceMetadataPersistenceTest.java b/src/test/java/io/github/hectorvent/floci/config/TlsConfigSourceMetadataPersistenceTest.java index 59dbceb880..1f51b561b7 100644 --- a/src/test/java/io/github/hectorvent/floci/config/TlsConfigSourceMetadataPersistenceTest.java +++ b/src/test/java/io/github/hectorvent/floci/config/TlsConfigSourceMetadataPersistenceTest.java @@ -83,6 +83,8 @@ class TlsConfigSourceMetadataPersistenceTest { "Metadata should contain 'localhost.floci.io'"); assertTrue(metadata.getHostnames().contains("*.localhost.floci.io"), "Metadata should contain '*.localhost.floci.io'"); + assertTrue(metadata.getHostnames().contains("host.docker.internal"), + "Metadata should contain 'host.docker.internal'"); } /**