diff --git a/Cargo.toml b/Cargo.toml index 446954ba..0eec1d1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -163,6 +163,7 @@ tokio = { version = "1.46.1" } tokio-vsock = "0.7.0" sysinfo = "0.35.2" default-net = "0.22.0" +url = "2.5" # Cryptography/Security aes-gcm = "0.10.3" diff --git a/vmm/Cargo.toml b/vmm/Cargo.toml index c5da0b83..95893373 100644 --- a/vmm/Cargo.toml +++ b/vmm/Cargo.toml @@ -53,6 +53,7 @@ size-parser = { workspace = true, features = ["serde"] } fatfs.workspace = true fscommon.workspace = true or-panic.workspace = true +url.workspace = true [dev-dependencies] insta.workspace = true diff --git a/vmm/src/app/qemu.rs b/vmm/src/app/qemu.rs index 735ca785..c4ce2bbb 100644 --- a/vmm/src/app/qemu.rs +++ b/vmm/src/app/qemu.rs @@ -162,6 +162,11 @@ fn create_shared_disk(disk_path: impl AsRef, shared_dir: impl AsRef) impl VmInfo { pub fn to_pb(&self, gw: &GatewayConfig, brief: bool) -> pb::VmInfo { let workdir = VmWorkDir::new(&self.workdir); + let vm_config = workdir.manifest(); + let custom_gateway_urls = vm_config + .as_ref() + .map(|c| c.gateway_urls.clone()) + .unwrap_or_default(); pb::VmInfo { id: self.manifest.id.clone(), name: self.manifest.name.clone(), @@ -174,15 +179,10 @@ impl VmInfo { configuration: if brief { None } else { - let vm_config = workdir.manifest(); let kms_urls = vm_config .as_ref() .map(|c| c.kms_urls.clone()) .unwrap_or_default(); - let gateway_urls = vm_config - .as_ref() - .map(|c| c.gateway_urls.clone()) - .unwrap_or_default(); let no_tee = vm_config .as_ref() .map(|c| c.no_tee) @@ -227,7 +227,7 @@ impl VmInfo { .collect(), }), kms_urls, - gateway_urls, + gateway_urls: custom_gateway_urls.clone(), stopped, no_tee, }) @@ -237,6 +237,19 @@ impl VmInfo { .then_some(self.instance_id.as_ref()) .flatten() .map(|id| { + // Use custom gateway URL if available, otherwise fall back to global config + if let Some(custom_gw_url) = custom_gateway_urls.first() { + if let Ok(url) = url::Url::parse(custom_gw_url) { + let host = url.host_str().unwrap_or(&gw.base_domain); + let port = url.port().unwrap_or(443); + if port == 443 { + return format!("https://{id}-{}.{}", gw.agent_port, host); + } else { + return format!("https://{id}-{}.{}:{}", gw.agent_port, host, port); + } + } + } + // Fall back to global gateway config if gw.port == 443 { format!("https://{id}-{}.{}", gw.agent_port, gw.base_domain) } else {