Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ public final class TemplateConstants {

public static final String DEFAULT_SYSTEM_VM_TEMPLATE_PATH = "template/tmpl/1/";

public static final String DEFAULT_SYSTEM_VM_TMPLT_NAME = "routing";

public static final int DEFAULT_TMPLT_COPY_PORT = 80;
public static final String DEFAULT_TMPLT_COPY_INTF = "eth2";
public static final String TMPLT_COPY_INTF_PRIVATE = "eth1";

public static final String DEFAULT_SSL_CERT_DOMAIN = "realhostip.com";
public static final String DEFAULT_HTTP_AUTH_USER = "cloud";

}
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,7 @@ public boolean generateVMSetupCommand(Long ssAHostId) {

SecStorageVMSetupCommand setupCmd = new SecStorageVMSetupCommand();
if (_allowedInternalSites != null) {
List<String> allowedCidrs = new ArrayList<>();
String[] cidrs = _allowedInternalSites.split(",");
for (String cidr : cidrs) {
if (NetUtils.isValidIp4Cidr(cidr) || NetUtils.isValidIp4(cidr) || !cidr.startsWith("0.0.0.0")) {
allowedCidrs.add(cidr);
}
}
List<String> allowedCidrs = getAllowedInternalSiteCidrs();
setupCmd.setAllowedInternalSites(allowedCidrs.toArray(new String[allowedCidrs.size()]));
}
String copyPasswd = _configDao.getValue("secstorage.copy.password");
Expand All @@ -390,6 +384,20 @@ public boolean generateVMSetupCommand(Long ssAHostId) {
}
}

private List<String> getAllowedInternalSiteCidrs() {
List<String> allowedCidrs = new ArrayList<>();
if (_allowedInternalSites == null) {
return allowedCidrs;
}
String[] cidrs = _allowedInternalSites.split(",");
for (String cidr : cidrs) {
if (NetUtils.isValidIp4Cidr(cidr) || NetUtils.isValidIp4(cidr) || !cidr.startsWith("0.0.0.0")) {
allowedCidrs.add(cidr);
}
}
return allowedCidrs;
}

@Override
public Pair<HostVO, SecondaryStorageVmVO> assignSecStorageVm(long zoneId, Command cmd) {
return null;
Expand All @@ -414,6 +422,9 @@ public boolean generateFirewallConfiguration(Long ssAHostId) {
SecStorageFirewallCfgCommand thiscpc = new SecStorageFirewallCfgCommand(true);
thiscpc.addPortConfig(thisSecStorageVm.getPublicIpAddress(), copyPort, true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF);

List<String> allowedCidrs = getAllowedInternalSiteCidrs();
addPortConfigForPrivateIpToCommand(thiscpc, allowedCidrs, thisSecStorageVm.getPrivateIpAddress(), thisSecStorageVm.getPublicIpAddress(), copyPort);

QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
sc.and(sc.entity().getType(), Op.EQ, Host.Type.SecondaryStorageVM);
sc.and(sc.entity().getStatus(), Op.IN, Status.Up, Status.Connecting);
Expand Down Expand Up @@ -443,6 +454,7 @@ public boolean generateFirewallConfiguration(Long ssAHostId) {
continue;
}
allSSVMIpList.addPortConfig(ssvm.getPublicIpAddress(), copyPort, true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF);
addPortConfigForPrivateIpToCommand(allSSVMIpList, allowedCidrs, ssvm.getPrivateIpAddress(), ssvm.getPublicIpAddress(), copyPort);
}

hostName = thisSecStorageVm.getHostName();
Expand All @@ -463,6 +475,16 @@ public boolean generateFirewallConfiguration(Long ssAHostId) {

}

private void addPortConfigForPrivateIpToCommand(SecStorageFirewallCfgCommand command, List<String> allowedCidrs,
String privateIpAddress, String publicIpAddress, String copyPort) {
for (String allowCidr : allowedCidrs) {
if (NetUtils.isIpWithInCidrRange(publicIpAddress, allowCidr)) {
command.addPortConfig(privateIpAddress, copyPort, true, TemplateConstants.TMPLT_COPY_INTF_PRIVATE);
break;
}
}
}

protected boolean isSecondaryStorageVmRequired(long dcId) {
DataCenterVO dc = _dcDao.findById(dcId);
_dcDao.loadDetails(dc);
Expand Down
2 changes: 1 addition & 1 deletion systemvm/agent/scripts/ipfirewall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ config_htaccess() {
}

ips(){
echo "allow from $1" >> $HTACCESS
grep -e "^allow from $1$" $HTACCESS || echo "allow from $1" >> $HTACCESS
result=$?
return $result
}
Expand Down