Skip to content

Commit c3b66e1

Browse files
committed
fix(vmm): use custom gateway URL for dashboard when VM has custom kms/gw endpoints
When a VM is configured with custom gateway_urls, the dashboard URL (app_url) should use the custom gateway's host and port instead of the global gateway config. This fixes the issue where VMs with custom kms/gw endpoints would show incorrect dashboard URLs pointing to the default gateway. The fix parses the first gateway URL from the VM's custom gateway_urls and extracts the host and port to construct the correct dashboard URL.
1 parent 9e273d0 commit c3b66e1

1 file changed

Lines changed: 28 additions & 6 deletions

File tree

vmm/src/app/qemu.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ fn create_shared_disk(disk_path: impl AsRef<Path>, shared_dir: impl AsRef<Path>)
162162
impl VmInfo {
163163
pub fn to_pb(&self, gw: &GatewayConfig, brief: bool) -> pb::VmInfo {
164164
let workdir = VmWorkDir::new(&self.workdir);
165+
let vm_config = workdir.manifest();
166+
let custom_gateway_urls = vm_config
167+
.as_ref()
168+
.map(|c| c.gateway_urls.clone())
169+
.unwrap_or_default();
165170
pb::VmInfo {
166171
id: self.manifest.id.clone(),
167172
name: self.manifest.name.clone(),
@@ -174,15 +179,10 @@ impl VmInfo {
174179
configuration: if brief {
175180
None
176181
} else {
177-
let vm_config = workdir.manifest();
178182
let kms_urls = vm_config
179183
.as_ref()
180184
.map(|c| c.kms_urls.clone())
181185
.unwrap_or_default();
182-
let gateway_urls = vm_config
183-
.as_ref()
184-
.map(|c| c.gateway_urls.clone())
185-
.unwrap_or_default();
186186
let no_tee = vm_config
187187
.as_ref()
188188
.map(|c| c.no_tee)
@@ -227,7 +227,7 @@ impl VmInfo {
227227
.collect(),
228228
}),
229229
kms_urls,
230-
gateway_urls,
230+
gateway_urls: custom_gateway_urls.clone(),
231231
stopped,
232232
no_tee,
233233
})
@@ -237,6 +237,28 @@ impl VmInfo {
237237
.then_some(self.instance_id.as_ref())
238238
.flatten()
239239
.map(|id| {
240+
// Use custom gateway URL if available, otherwise fall back to global config
241+
if let Some(custom_gw_url) = custom_gateway_urls.first() {
242+
// Parse the gateway URL to extract host and port
243+
// Expected format: https://hostname[:port]
244+
if let Some(stripped) = custom_gw_url.strip_prefix("https://") {
245+
let (host, port) = if let Some((h, p)) = stripped.split_once(':') {
246+
// Remove any path component from port
247+
let port_str = p.split('/').next().unwrap_or(p);
248+
(h, port_str.parse().unwrap_or(443u16))
249+
} else {
250+
// Remove any path component from host
251+
let h = stripped.split('/').next().unwrap_or(stripped);
252+
(h, 443u16)
253+
};
254+
if port == 443 {
255+
return format!("https://{id}-{}.{}", gw.agent_port, host);
256+
} else {
257+
return format!("https://{id}-{}.{}:{}", gw.agent_port, host, port);
258+
}
259+
}
260+
}
261+
// Fall back to global gateway config
240262
if gw.port == 443 {
241263
format!("https://{id}-{}.{}", gw.agent_port, gw.base_domain)
242264
} else {

0 commit comments

Comments
 (0)