Skip to content

Commit

Permalink
Merge release branch 4.18 to main
Browse files Browse the repository at this point in the history
* 4.18:
  SSVM: 'allow from' private IP in other SSVMs if the public IP is in allowed internal sites cidrs (#7288)
  eof added to StorPoolStatsCollector (#7754)
  • Loading branch information
DaanHoogland committed Jul 20, 2023
2 parents 729e6d1 + 56d98ea commit afec876
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
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 @@ -185,4 +185,4 @@ private void getClusterStats(JsonArray data, Map<String, Pair<Long, Long>> map)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,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 @@ -388,6 +382,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 @@ -412,6 +420,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 @@ -441,6 +452,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 @@ -461,6 +473,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

0 comments on commit afec876

Please sign in to comment.