Skip to content

Commit 55bd023

Browse files
committed
fix(vm): preserve guest TLS hostname
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent f819f7d commit 55bd023

3 files changed

Lines changed: 21 additions & 9 deletions

File tree

crates/openshell-driver-vm/scripts/openshell-vm-sandbox-init.sh

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ BOOT_START=$(date +%s%3N 2>/dev/null || date +%s)
1717
# gvproxy's TCP/UDP/ICMP forwarder. Use this address
1818
# (or any of the host.* hostnames below) to reach a
1919
# service the host is listening on.
20-
# The host.containers.internal / host.docker.internal DNS records served
21-
# by gvproxy's embedded resolver point at 192.168.127.254. We mirror that
22-
# in /etc/hosts so the supervisor can reach the gateway even when
23-
# gvproxy's DNS is not in resolv.conf (e.g. DHCP failed and we fell
24-
# back to 8.8.8.8).
20+
# The host.openshell.internal / host.containers.internal /
21+
# host.docker.internal DNS records served by gvproxy's embedded resolver
22+
# point at 192.168.127.254. We mirror that in /etc/hosts so the supervisor
23+
# can reach the gateway even when gvproxy's DNS is not in resolv.conf
24+
# (e.g. DHCP failed and we fell back to 8.8.8.8).
2525
GVPROXY_GATEWAY_IP="192.168.127.1"
2626
GVPROXY_HOST_LOOPBACK_IP="192.168.127.254"
2727
GATEWAY_IP="$GVPROXY_GATEWAY_IP"
@@ -419,7 +419,12 @@ rewrite_openshell_endpoint_if_needed() {
419419
if [ "${GATEWAY_IP}" != "${GVPROXY_GATEWAY_IP}" ]; then
420420
fallback_ip="$GATEWAY_IP"
421421
fi
422-
for candidate in host.openshell.internal host.containers.internal host.docker.internal "$fallback_ip"; do
422+
local candidates="host.openshell.internal host.containers.internal host.docker.internal"
423+
if [ "$scheme" != "https" ]; then
424+
candidates="${candidates} ${fallback_ip}"
425+
fi
426+
427+
for candidate in $candidates; do
423428
if [ "$candidate" = "$host" ]; then
424429
continue
425430
fi
@@ -435,6 +440,11 @@ rewrite_openshell_endpoint_if_needed() {
435440
fi
436441
done
437442

443+
if [ "$scheme" = "https" ]; then
444+
ts "WARNING: could not preflight HTTPS OpenShell endpoint ${host}:${port}; preserving hostname for TLS verification"
445+
return 0
446+
fi
447+
438448
ts "WARNING: could not reach OpenShell endpoint ${host}:${port}"
439449
}
440450

crates/openshell-driver-vm/src/driver.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ const OPENSHELL_HOST_GATEWAY_ALIAS: &str = "host.openshell.internal";
9191
/// resolves even when gvproxy's DNS is not in resolv.conf;
9292
/// * keeping a recognisable hostname makes log messages clearer than a bare
9393
/// 192.168.127.254 reference;
94-
/// * `host.docker.internal` works the same way for Docker-flavoured tooling.
94+
/// * package-managed gateway certificates include this SAN for guest mTLS.
9595
///
9696
/// Both names ultimately route through the gvproxy NAT path on
9797
/// `GVPROXY_HOST_LOOPBACK_IP` — they do **not** go through the gateway IP.
98-
const GVPROXY_HOST_LOOPBACK_ALIAS: &str = "host.containers.internal";
98+
const GVPROXY_HOST_LOOPBACK_ALIAS: &str = OPENSHELL_HOST_GATEWAY_ALIAS;
9999
const GUEST_SSH_SOCKET_PATH: &str = "/run/openshell/ssh.sock";
100100
const GUEST_TLS_CA_PATH: &str = "/opt/openshell/tls/ca.crt";
101101
const GUEST_TLS_CERT_PATH: &str = "/opt/openshell/tls/tls.crt";
@@ -3392,7 +3392,7 @@ fn merged_environment(sandbox: &Sandbox) -> HashMap<String, String> {
33923392
/// not the host's. Inside the guest we need a name that gvproxy will translate
33933393
/// into the host's loopback address.
33943394
///
3395-
/// We rewrite to `host.containers.internal`, which gvproxy's embedded DNS resolves
3395+
/// We rewrite to `host.openshell.internal`, which gvproxy's embedded DNS resolves
33963396
/// to the host-loopback IP `192.168.127.254`. gvproxy installs a default NAT entry
33973397
/// rewriting that destination to the host's `127.0.0.1` and dialing out from the
33983398
/// host process, so any port the host is listening on becomes reachable. The

crates/openshell-driver-vm/src/rootfs.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ fn prepare_sandbox_rootfs(rootfs: &Path) -> Result<(), String> {
379379
.map_err(|e| format!("write sandbox rootfs marker: {e}"))?;
380380
ensure_sandbox_guest_user(rootfs)?;
381381
create_sandbox_mountpoint(&rootfs.join("sandbox"))?;
382+
create_sandbox_mountpoint(&rootfs.join("image-cache"))?;
382383
create_sandbox_mountpoint(&rootfs.join("lower"))?;
383384
create_sandbox_mountpoint(&rootfs.join("overlay"))?;
384385
create_sandbox_mountpoint(&rootfs.join("newroot"))?;
@@ -941,6 +942,7 @@ mod tests {
941942
assert!(rootfs.join("srv/openshell-vm-sandbox-init.sh").is_file());
942943
assert!(rootfs.join("opt/openshell/bin/umoci").is_file());
943944
assert!(rootfs.join("sandbox").is_dir());
945+
assert!(rootfs.join("image-cache").is_dir());
944946
assert!(rootfs.join("lower").is_dir());
945947
assert!(rootfs.join("overlay").is_dir());
946948
assert!(rootfs.join("newroot").is_dir());

0 commit comments

Comments
 (0)