Skip to content

Commit 52a8ec2

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 uses the url crate to parse 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 0f08864 commit 52a8ec2

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ tokio = { version = "1.46.1" }
163163
tokio-vsock = "0.7.0"
164164
sysinfo = "0.35.2"
165165
default-net = "0.22.0"
166+
url = "2.5"
166167

167168
# Cryptography/Security
168169
aes-gcm = "0.10.3"

vmm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ size-parser = { workspace = true, features = ["serde"] }
5353
fatfs.workspace = true
5454
fscommon.workspace = true
5555
or-panic.workspace = true
56+
url.workspace = true
5657

5758
[dev-dependencies]
5859
insta.workspace = true

vmm/src/app/qemu.rs

Lines changed: 19 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,19 @@ 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+
if let Ok(url) = url::Url::parse(custom_gw_url) {
243+
let host = url.host_str().unwrap_or(&gw.base_domain);
244+
let port = url.port().unwrap_or(443);
245+
if port == 443 {
246+
return format!("https://{id}-{}.{}", gw.agent_port, host);
247+
} else {
248+
return format!("https://{id}-{}.{}:{}", gw.agent_port, host, port);
249+
}
250+
}
251+
}
252+
// Fall back to global gateway config
240253
if gw.port == 443 {
241254
format!("https://{id}-{}.{}", gw.agent_port, gw.base_domain)
242255
} else {

0 commit comments

Comments
 (0)