Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions plugin/kvm/src/main/java/org/zstack/kvm/KVMAgentCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -3805,6 +3805,26 @@ public static class MigrateVmCmd extends AgentCommand implements HasThreadContex
private boolean reload;
@GrayVersion(value = "5.0.0")
private long bandwidth;
@GrayVersion(value = "5.5.12")
private boolean useTls;
@GrayVersion(value = "5.5.12")
private String srcHostManagementIp;

public String getSrcHostManagementIp() {
return srcHostManagementIp;
}

public void setSrcHostManagementIp(String srcHostManagementIp) {
this.srcHostManagementIp = srcHostManagementIp;
}

public boolean isUseTls() {
return useTls;
}

public void setUseTls(boolean useTls) {
this.useTls = useTls;
}

public Integer getDownTime() {
return downTime;
Expand Down
4 changes: 4 additions & 0 deletions plugin/kvm/src/main/java/org/zstack/kvm/KVMGlobalConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ public class KVMGlobalConfig {
@BindResourceConfig({HostVO.class, ClusterVO.class})
public static GlobalConfig RECONNECT_HOST_RESTART_LIBVIRTD_SERVICE = new GlobalConfig(CATEGORY, "reconnect.host.restart.libvirtd.service");

@GlobalConfigValidation(validValues = {"true", "false"})
@GlobalConfigDef(defaultValue = "true", type = Boolean.class, description = "enable TLS encryption for libvirt remote connections (migration/v2v)")
public static GlobalConfig LIBVIRT_TLS_ENABLED = new GlobalConfig(CATEGORY, "libvirt.tls.enabled");

@GlobalConfigValidation
public static GlobalConfig KVMAGENT_PHYSICAL_MEMORY_USAGE_ALARM_THRESHOLD = new GlobalConfig(CATEGORY, "kvmagent.physicalmemory.usage.alarm.threshold");

Expand Down
2 changes: 2 additions & 0 deletions plugin/kvm/src/main/java/org/zstack/kvm/KVMHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -3163,6 +3163,7 @@ public void run(final FlowTrigger trigger, Map data) {
cmd.setDestHostIp(dstHostMigrateIp);
cmd.setSrcHostIp(srcHostMigrateIp);
cmd.setDestHostManagementIp(dstHostMnIp);
cmd.setSrcHostManagementIp(srcHostMnIp);
cmd.setMigrateFromDestination(migrateFromDestination);
cmd.setStorageMigrationPolicy(storageMigrationPolicy == null ? null : storageMigrationPolicy.toString());
cmd.setVmUuid(vmUuid);
Expand All @@ -3174,6 +3175,7 @@ public void run(final FlowTrigger trigger, Map data) {
cmd.setDownTime(s.downTime);
cmd.setBandwidth(s.bandwidth);
cmd.setNics(nicTos);
cmd.setUseTls(KVMGlobalConfig.LIBVIRT_TLS_ENABLED.value(Boolean.class));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Inspect LIBVIRT_TLS_ENABLED declaration =="
fd 'KVMGlobalConfig.java$' | while read -r f; do
  echo "-- $f --"
  rg -n -C4 'LIBVIRT_TLS_ENABLED|ClusterVO|bind' "$f" || true
done

echo
echo "== Inspect current use in KVMHost =="
fd 'KVMHost.java$' | while read -r f; do
  echo "-- $f --"
  rg -n -C3 'setUseTls|LIBVIRT_TLS_ENABLED' "$f" || true
done

echo
echo "== Compare with resource-scoped KVM config reads in KVMHost =="
fd 'KVMHost.java$' | while read -r f; do
  echo "-- $f --"
  rg -n -C1 'rcf\.getResourceConfigValue\(KVMGlobalConfig\.' "$f" || true
done

Repository: MatheMatrix/zstack

Length of output: 8576


配置作用域错误,绕过了集群级别的 TLS 设置

LIBVIRT_TLS_ENABLEDKVMGlobalConfig.java 中被标注为 @BindResourceConfig({ClusterVO.class}),是集群级资源配置。但第 3177 行直接使用 .value(Boolean.class) 读取全局默认值,绕过了集群维度的覆盖值。这导致某集群即使显式配置禁用 TLS,迁移命令仍会沿用默认值,新增的集群级开关失效,也违反了向后兼容原则。

应按照文件中其他资源配置的读取方式(如第 3157 行、3931 行、1782 行等),通过 rcf.getResourceConfigValue() 按 cluster 读取资源配置。

🔧 建议修改
-                        cmd.setUseTls(KVMGlobalConfig.LIBVIRT_TLS_ENABLED.value(Boolean.class));
+                        cmd.setUseTls(rcf.getResourceConfigValue(
+                                KVMGlobalConfig.LIBVIRT_TLS_ENABLED,
+                                self.getClusterUuid(),
+                                Boolean.class
+                        ));
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@plugin/kvm/src/main/java/org/zstack/kvm/KVMHost.java` at line 3177, The call
to KVMGlobalConfig.LIBVIRT_TLS_ENABLED.value(Boolean.class) in KVMHost
(affecting cmd.setUseTls) bypasses cluster-scoped overrides; change it to fetch
the cluster-level value via the resource config facade (use
rcf.getResourceConfigValue) for the host's cluster (use the host/cluster UUID
available in KVMHost) and pass that Boolean into cmd.setUseTls, matching the
pattern used elsewhere in this class (e.g., where rcf.getResourceConfigValue is
used around lines ~3157, ~3931, ~1782).


if (s.diskMigrationMap != null) {
Map<String, VolumeTO> diskMigrationMap = new HashMap<>();
Expand Down