make bind address managementserver scoped

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
Abhishek Kumar 2026-04-15 13:45:14 +05:30
parent fac62adfe3
commit 830044d88f
4 changed files with 37 additions and 12 deletions

View File

@ -77,10 +77,17 @@ public class VeeamControlServer {
StringUtils.isNotEmpty(keystorePassword) &&
StringUtils.isNotEmpty(keyManagerPassword) &&
Files.exists(Paths.get(keystorePath));
final String bind = VeeamControlService.BindAddress.value();
long managementServerHostId = veeamControlService.getCurrentManagementServerHostId();
final String bindAddress = VeeamControlService.BindAddress.valueIn(managementServerHostId);
final String bindHost = StringUtils.trimToNull(bindAddress);
final int port = VeeamControlService.Port.value();
final String bindDisplay = bindHost == null ?
String.format("all interfaces, port: %d", port) :
String.format("host: %s, port: %d", bindHost, port);
String ctxPath = VeeamControlService.ContextPath.value();
LOGGER.info("Veeam Control server - bind: {}, port: {}, context: {} with {} handlers", bind, port, ctxPath,
LOGGER.info("Veeam Control server - {}, context: {} with {} handlers",
bindDisplay,
ctxPath,
routeHandlers != null ? routeHandlers.size() : 0);
@ -102,20 +109,20 @@ public class VeeamControlServer {
new SslConnectionFactory(sslContextFactory, "http/1.1"),
new HttpConnectionFactory(https)
);
httpsConnector.setHost(bind);
httpsConnector.setHost(bindHost);
httpsConnector.setPort(port);
server.addConnector(httpsConnector);
LOGGER.info("Veeam Control API server HTTPS enabled on {}:{}", bind, port);
LOGGER.info("Veeam Control API server HTTPS enabled on {}", bindDisplay);
} else {
final HttpConfiguration http = new HttpConfiguration();
final ServerConnector httpConnector = new ServerConnector(server, new HttpConnectionFactory(http));
httpConnector.setHost(bind);
httpConnector.setHost(bindHost);
httpConnector.setPort(port);
server.addConnector(httpConnector);
LOGGER.warn("Veeam Control API server HTTPS is NOT configured (missing keystore path/passwords). " +
"Starting HTTP on {}:{} instead.", bind, port);
"Starting HTTP on {} instead.", bindDisplay);
}
final ServletContextHandler ctx =
@ -140,7 +147,7 @@ public class VeeamControlServer {
server.start();
LOGGER.info("Started Veeam Control API server on {}:{} with context {}", bind, port, ctxPath);
LOGGER.info("Started Veeam Control API server on {}:{} with context {}", bindDisplay, port, ctxPath);
}
@NotNull

View File

@ -31,7 +31,8 @@ public interface VeeamControlService extends PluggableService, Configurable {
ConfigKey<Boolean> Enabled = new ConfigKey<>("Advanced", Boolean.class, "integration.veeam.control.enabled",
"false", "Enable the Veeam Integration REST API server", false);
ConfigKey<String> BindAddress = new ConfigKey<>("Advanced", String.class, "integration.veeam.control.bind.address",
"127.0.0.1", "Bind address for Veeam Integration REST API server", false);
"", "Bind address for Veeam Integration REST API server", false,
ConfigKey.Scope.ManagementServer);
ConfigKey<Integer> Port = new ConfigKey<>("Advanced", Integer.class, "integration.veeam.control.port",
"8090", "Port for Veeam Integration REST API server", false);
ConfigKey<String> ContextPath = new ConfigKey<>("Advanced", String.class, "integration.veeam.control.context.path",
@ -56,6 +57,7 @@ public interface VeeamControlService extends PluggableService, Configurable {
"", "Comma-separated list of CIDR blocks representing clients allowed to access the API. " +
"If empty, all clients will be allowed. Example: '192.168.1.1/24,192.168.2.100/32", true);
long getCurrentManagementServerHostId();
List<String> getAllowedClientCidrs();

View File

@ -21,16 +21,24 @@ import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import javax.inject.Inject;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.utils.cache.SingleCache;
import org.apache.cloudstack.utils.identity.ManagementServerNode;
import org.apache.cloudstack.veeam.utils.DataUtil;
import org.apache.commons.lang3.StringUtils;
import com.cloud.cluster.ManagementServerHostVO;
import com.cloud.cluster.dao.ManagementServerHostDao;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.net.NetUtils;
public class VeeamControlServiceImpl extends ManagerBase implements VeeamControlService {
@Inject
ManagementServerHostDao managementServerHostDao;
private List<RouteHandler> routeHandlers;
private VeeamControlServer veeamControlServer;
private SingleCache<List<String>> allowedClientCidrsCache;
@ -63,6 +71,13 @@ public class VeeamControlServiceImpl extends ManagerBase implements VeeamControl
this.routeHandlers = routeHandlers;
}
@Override
public long getCurrentManagementServerHostId() {
ManagementServerHostVO hostVO =
managementServerHostDao.findByMsid(ManagementServerNode.getManagementServerId());
return hostVO.getId();
}
@Override
public List<String> getAllowedClientCidrs() {
return allowedClientCidrsCache.get();

View File

@ -18,7 +18,6 @@
package org.apache.cloudstack.veeam.api;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@ -40,7 +39,7 @@ import org.apache.cloudstack.veeam.api.dto.SummaryCount;
import org.apache.cloudstack.veeam.api.dto.Version;
import org.apache.cloudstack.veeam.utils.Negotiation;
import com.cloud.utils.UuidUtils;
import com.cloud.user.AccountService;
import com.cloud.utils.component.ManagerBase;
public class ApiRouteHandler extends ManagerBase implements RouteHandler {
@ -49,6 +48,9 @@ public class ApiRouteHandler extends ManagerBase implements RouteHandler {
@Inject
ServerAdapter serverAdapter;
@Inject
AccountService accountService;
@Override
public boolean canHandle(String method, String path) {
return getSanitizedPath(path).startsWith("/api");
@ -97,8 +99,7 @@ public class ApiRouteHandler extends ManagerBase implements RouteHandler {
/* ---------------- Product info ---------------- */
ProductInfo productInfo = new ProductInfo();
productInfo.setInstanceId(UuidUtils.nameUUIDFromBytes(
VeeamControlService.BindAddress.value().getBytes(StandardCharsets.UTF_8)).toString());
productInfo.setInstanceId(accountService.getSystemAccount().getUuid());
productInfo.name = VeeamControlService.PLUGIN_NAME;
productInfo.version = Version.fromPackageAndCSVersion(true);