From 76793f0fa71651d0cf74ed5938669af2d40274b6 Mon Sep 17 00:00:00 2001 From: Abhisar Sinha <63767682+abh1sar@users.noreply.github.com> Date: Fri, 3 Apr 2026 18:09:43 +0530 Subject: [PATCH] enable TLS by default and add listen address to agent.properties --- agent/conf/agent.properties | 12 ++++++----- .../agent/properties/AgentProperties.java | 15 ++++---------- .../resource/LibvirtComputingResource.java | 19 +++++------------- ...virtCreateImageTransferCommandWrapper.java | 20 ++++++++++++------- ...rtFinalizeImageTransferCommandWrapper.java | 8 ++++---- 5 files changed, 33 insertions(+), 41 deletions(-) diff --git a/agent/conf/agent.properties b/agent/conf/agent.properties index f2fcfd83eb1..7a74c908135 100644 --- a/agent/conf/agent.properties +++ b/agent/conf/agent.properties @@ -78,11 +78,13 @@ zone=default # Generated with "uuidgen". local.storage.uuid= -# Enable TLS for image server transfers. -# When enabled, certificate and key paths must both be configured. -# image.server.tls.enabled=false -# image.server.tls.cert.file=/etc/cloudstack/agent/cloud.crt -# image.server.tls.key.file=/etc/cloudstack/agent/cloud.key +# Enable TLS for image server transfers. The keys are read from: +# cert file = /etc/cloudstack/agent/cloud.crt +# key file = /etc/cloudstack/agent/cloud.key +image.server.tls.enabled=true + +# The Address for the network interface that the image server listens on. If not specified, it will listen on the Management network. +#image.server.listen.address= # Location for KVM virtual router scripts. # The path defined in this property is relative to the directory "/usr/share/cloudstack-common/". diff --git a/agent/src/main/java/com/cloud/agent/properties/AgentProperties.java b/agent/src/main/java/com/cloud/agent/properties/AgentProperties.java index 22a25eaa6d8..ec60b541605 100644 --- a/agent/src/main/java/com/cloud/agent/properties/AgentProperties.java +++ b/agent/src/main/java/com/cloud/agent/properties/AgentProperties.java @@ -126,23 +126,16 @@ public class AgentProperties{ /** * Enables TLS on the KVM image server transfer endpoint.
* Data type: Boolean.
- * Default value: false + * Default value: true */ - public static final Property IMAGE_SERVER_TLS_ENABLED = new Property<>("image.server.tls.enabled", false); + public static final Property IMAGE_SERVER_TLS_ENABLED = new Property<>("image.server.tls.enabled", true); /** - * PEM certificate file used by the KVM image server when TLS is enabled.
+ * The IP address that the KVM image server listens on.
* Data type: String.
* Default value: null */ - public static final Property IMAGE_SERVER_TLS_CERT_FILE = new Property<>("image.server.tls.cert.file", null, String.class); - - /** - * PEM private key file used by the KVM image server when TLS is enabled.
- * Data type: String.
- * Default value: null - */ - public static final Property IMAGE_SERVER_TLS_KEY_FILE = new Property<>("image.server.tls.key.file", null, String.class); + public static final Property IMAGE_SERVER_LISTEN_ADDRESS = new Property<>("image.server.listen.address", null, String.class); /** * Directory where Qemu sockets are placed.
diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index 675c9cde266..08d84bb8d6a 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -383,6 +383,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv public static final String CHECKPOINT_DELETE_COMMAND = "virsh checkpoint-delete --domain %s --checkpointname %s --metadata"; public static final int IMAGE_SERVER_DEFAULT_PORT = 54322; + public static final String IMAGE_SERVER_SYSTEMD_UNIT_NAME = "cloudstack-image-server"; protected int qcow2DeltaMergeTimeout; @@ -399,8 +400,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv private String nasBackupPath; private String imageServerPath; private boolean imageServerTlsEnabled = false; - private String imageServerTlsCertFile; - private String imageServerTlsKeyFile; + private String imageServerListenAddress; private String securityGroupPath; private String ovsPvlanDhcpHostPath; private String ovsPvlanVmPath; @@ -823,12 +823,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv return imageServerTlsEnabled; } - public String getImageServerTlsCertFile() { - return imageServerTlsCertFile; - } - - public String getImageServerTlsKeyFile() { - return imageServerTlsKeyFile; + public String getImageServerListenAddress() { + return imageServerListenAddress; } public String getOvsPvlanDhcpHostPath() { @@ -1050,12 +1046,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv cachePath = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.HOST_CACHE_LOCATION); imageServerTlsEnabled = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.IMAGE_SERVER_TLS_ENABLED); - imageServerTlsCertFile = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.IMAGE_SERVER_TLS_CERT_FILE); - imageServerTlsKeyFile = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.IMAGE_SERVER_TLS_KEY_FILE); - - if (imageServerTlsEnabled && (StringUtils.isBlank(imageServerTlsCertFile) || StringUtils.isBlank(imageServerTlsKeyFile))) { - throw new ConfigurationException("image server TLS is enabled but image.server.tls.cert.file or image.server.tls.key.file is missing"); - } + imageServerListenAddress = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.IMAGE_SERVER_LISTEN_ADDRESS); params.put("domr.scripts.dir", domrScriptsDir); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreateImageTransferCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreateImageTransferCommandWrapper.java index 01fd11524bc..7cf05da9b21 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreateImageTransferCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreateImageTransferCommandWrapper.java @@ -40,6 +40,9 @@ import com.cloud.utils.script.Script; public class LibvirtCreateImageTransferCommandWrapper extends CommandWrapper { protected Logger logger = LogManager.getLogger(getClass()); + private static final String IMAGE_SERVER_TLS_CERT_FILE = "/etc/cloudstack/agent/cloud.crt"; + private static final String IMAGE_SERVER_TLS_KEY_FILE = "/etc/cloudstack/agent/cloud.key"; + private void resetService(String unitName) { Script resetScript = new Script("/bin/bash", logger); resetScript.add("-c"); @@ -51,13 +54,12 @@ public class LibvirtCreateImageTransferCommandWrapper extends CommandWrapper