Skip to content

Commit e645f72

Browse files
Pearl1594nvazquez
authored andcommitted
NSX: Fix custom ACL check (#2)
* NSX: Fix custom ACL check * NSX: Fix custom ACL check
1 parent 5a4f38c commit e645f72

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

server/src/main/java/com/cloud/network/vpc/NetworkACLServiceImpl.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Collections;
2121
import java.util.Comparator;
2222
import java.util.List;
23+
import java.util.Locale;
2324
import java.util.Map;
2425
import java.util.Objects;
2526

@@ -344,7 +345,7 @@ public NetworkACLItem createNetworkACLItem(CreateNetworkACLCmd createNetworkACLC
344345
if (isGlobalAcl(acl.getVpcId()) && !Account.Type.ADMIN.equals(caller.getType())) {
345346
throw new PermissionDeniedException("Only Root Admins can create rules for a global ACL.");
346347
}
347-
validateNsxConstraints(acl.getVpcId(), icmpType);
348+
validateNsxConstraints(acl.getVpcId(), protocol, icmpType, icmpCode, sourcePortStart, sourcePortEnd);
348349
validateAclRuleNumber(createNetworkACLCmd, acl);
349350

350351
NetworkACLItem.Action ruleAction = validateAndCreateNetworkAclRuleAction(action);
@@ -435,18 +436,27 @@ protected void validateNetworkAcl(NetworkACL acl) {
435436
}
436437
}
437438

438-
private void validateNsxConstraints(Long vpcId, Integer icpmType) {
439+
private void validateNsxConstraints(long vpcId, String protocol, Integer icmpType,
440+
Integer icmpCode, Integer sourcePortStart, Integer sourcePortEnd) {
439441
VpcVO vpc = _vpcDao.findById(vpcId);
440442
final DataCenter dc = _entityMgr.findById(DataCenter.class, vpc.getZoneId());
441443
final NsxProviderVO nsxProvider = nsxProviderDao.findByZoneId(dc.getId());
442444
if (Objects.isNull(nsxProvider)) {
443445
return;
444446
}
445-
if (icpmType == -1) {
447+
448+
if (NetUtils.ICMP_PROTO.equals(protocol.toLowerCase(Locale.ROOT)) && (icmpType == -1 || icmpCode == -1)) {
446449
String errorMsg = "Passing -1 for ICMP type is not supported for NSX enabled zones";
447450
s_logger.error(errorMsg);
448451
throw new InvalidParameterValueException(errorMsg);
449452
}
453+
454+
if (List.of(NetUtils.TCP_PROTO, NetUtils.UDP_PROTO).contains(protocol.toLowerCase(Locale.ROOT)) &&
455+
(Objects.isNull(sourcePortStart) || Objects.isNull(sourcePortEnd))) {
456+
String errorMsg = "Source start and end ports are required to be passed";
457+
s_logger.error(errorMsg);
458+
throw new InvalidParameterValueException(errorMsg);
459+
}
450460
}
451461

452462
/**
@@ -838,7 +848,8 @@ public NetworkACLItem updateNetworkACLItem(UpdateNetworkACLItemCmd updateNetwork
838848

839849
NetworkACL acl = _networkAclMgr.getNetworkACL(networkACLItemVo.getAclId());
840850
validateNetworkAcl(acl);
841-
validateNsxConstraints(acl.getVpcId(), networkACLItemVo.getIcmpType());
851+
validateNsxConstraints(acl.getVpcId(), networkACLItemVo.getProtocol(), networkACLItemVo.getIcmpType(),
852+
networkACLItemVo.getIcmpCode(), networkACLItemVo.getSourcePortStart(), networkACLItemVo.getSourcePortEnd());
842853
Account account = CallContext.current().getCallingAccount();
843854
validateGlobalAclPermissionAndAclAssociatedToVpc(acl, account, "Only Root Admins can update global ACLs.");
844855

0 commit comments

Comments
 (0)