Skip to content

Commit c1f6673

Browse files
author
gitlab
committed
Merge branch 'fix/ZSTAC-79067@@2' into '5.5.12'
<fix>[securitygroup]: remove strict sequential priority restriction See merge request zstackio/zstack!9342
2 parents 44c191f + c7e7de8 commit c1f6673

3 files changed

Lines changed: 26 additions & 53 deletions

File tree

plugin/securityGroup/src/main/java/org/zstack/network/securitygroup/SecurityGroupApiInterceptor.java

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -343,14 +343,6 @@ private void validate(APISetVmNicSecurityGroupMsg msg) {
343343
if (!aoMap.isEmpty()) {
344344
Integer[] priorities = aoMap.keySet().toArray(new Integer[aoMap.size()]);
345345
Arrays.sort(priorities);
346-
if (priorities[0] != 1) {
347-
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10022, "could no set vm nic security group, because invalid priority, priority expects to start at 1, but [%d]", priorities[0]));
348-
}
349-
for (int i = 0; i < priorities.length - 1; i++) {
350-
if (priorities[i] + 1 != priorities[i + 1]) {
351-
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10023, "could no set vm nic security group, because invalid priority, priority[%d] and priority[%d] expected to be consecutive", priorities[i], priorities[i + 1]));
352-
}
353-
}
354346
}
355347

356348

@@ -386,19 +378,6 @@ private void validate(APISetVmNicSecurityGroupMsg msg) {
386378

387379
msg.setRefs(newAOs);
388380
}
389-
} else {
390-
if (!adminIntegers.isEmpty()) {
391-
Integer[] priorities = adminIntegers.toArray(new Integer[adminIntegers.size()]);
392-
Arrays.sort(priorities);
393-
if (priorities[0] != 1) {
394-
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10024, "could no set vm nic security group, because admin security group priority[%d] must be higher than users", priorities[0]));
395-
}
396-
for (int i = 0; i < priorities.length - 1; i++) {
397-
if (priorities[i] + 1 != priorities[i + 1]) {
398-
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10025, "could no set vm nic security group, because admin security group priority[%d] must be higher than users", priorities[i + 1]));
399-
}
400-
}
401-
}
402381
}
403382
}
404383

@@ -498,8 +477,9 @@ private void validate(APIUpdateSecurityGroupRulePriorityMsg msg) {
498477
rvos.stream().filter(rvo -> rvo.getUuid().equals(ao.getRuleUuid())).findFirst().orElseThrow(() ->
499478
new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10041, "could not update security group rule priority, because rule[uuid:%s] not in security group[uuid:%s]", ao.getRuleUuid(), msg.getSecurityGroupUuid())));
500479

501-
rvos.stream().filter(rvo -> rvo.getPriority() == ao.getPriority()).findFirst().orElseThrow(() ->
502-
new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10042, "could not update security group rule priority, because priority[%d] not in security group[uuid:%s]", ao.getPriority(), msg.getSecurityGroupUuid())));
480+
if (ao.getPriority() < 1 || ao.getPriority() > SecurityGroupGlobalConfig.SECURITY_GROUP_RULES_NUM_LIMIT.value(Integer.class)) {
481+
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10042, "could not update security group rule priority, because priority[%d] is out of valid range [1, %d]", ao.getPriority(), SecurityGroupGlobalConfig.SECURITY_GROUP_RULES_NUM_LIMIT.value(Integer.class)));
482+
}
503483
}
504484

505485
List<String> uuidList = new ArrayList<>(priorityMap.values());
@@ -534,8 +514,8 @@ private void validate(APIChangeSecurityGroupRuleMsg msg) {
534514
if (count.intValue() > SecurityGroupGlobalConfig.SECURITY_GROUP_RULES_NUM_LIMIT.value(Integer.class)) {
535515
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10047, "could not change security group rule, because security group %s rules number[%d] is out of max limit[%d]", vo.getType(), count.intValue(), SecurityGroupGlobalConfig.SECURITY_GROUP_RULES_NUM_LIMIT.value(Integer.class)));
536516
}
537-
if (msg.getPriority() > count.intValue()) {
538-
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10048, "could not change security group rule, because the maximum priority of %s rule is [%d]", vo.getType().toString(), count.intValue()));
517+
if (msg.getPriority() > SecurityGroupGlobalConfig.SECURITY_GROUP_RULES_NUM_LIMIT.value(Integer.class)) {
518+
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10048, "could not change security group rule, because the maximum priority of %s rule is [%d]", vo.getType().toString(), SecurityGroupGlobalConfig.SECURITY_GROUP_RULES_NUM_LIMIT.value(Integer.class)));
539519
}
540520
if (msg.getPriority() < 0) {
541521
msg.setPriority(SecurityGroupConstant.LOWEST_RULE_PRIORITY);
@@ -1198,11 +1178,11 @@ private void validate(APIAddSecurityGroupRuleMsg msg) {
11981178
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10119, "could not add security group rule, because security group %s rules number[%d] is out of max limit[%d]",
11991179
SecurityGroupRuleType.Egress, (egressRuleCount + toCreateEgressRuleCount), SecurityGroupGlobalConfig.SECURITY_GROUP_RULES_NUM_LIMIT.value(Integer.class)));
12001180
}
1201-
if (msg.getPriority() > (ingressRuleCount + 1) && toCreateIngressRuleCount > 0) {
1202-
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10120, "could not add security group rule, because priority[%d] must be consecutive, the ingress rule maximum priority is [%d]", msg.getPriority(), ingressRuleCount));
1181+
if (msg.getPriority() > SecurityGroupGlobalConfig.SECURITY_GROUP_RULES_NUM_LIMIT.value(Integer.class) && toCreateIngressRuleCount > 0) {
1182+
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10120, "could not add security group rule, because priority[%d] exceeds the maximum allowed priority [%d]", msg.getPriority(), SecurityGroupGlobalConfig.SECURITY_GROUP_RULES_NUM_LIMIT.value(Integer.class)));
12031183
}
1204-
if (msg.getPriority() > (egressRuleCount + 1) && toCreateEgressRuleCount > 0) {
1205-
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10121, "could not add security group rule, because priority[%d] must be consecutive, the egress rule maximum priority is [%d]", msg.getPriority(), egressRuleCount));
1184+
if (msg.getPriority() > SecurityGroupGlobalConfig.SECURITY_GROUP_RULES_NUM_LIMIT.value(Integer.class) && toCreateEgressRuleCount > 0) {
1185+
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10121, "could not add security group rule, because priority[%d] exceeds the maximum allowed priority [%d]", msg.getPriority(), SecurityGroupGlobalConfig.SECURITY_GROUP_RULES_NUM_LIMIT.value(Integer.class)));
12061186
}
12071187
}
12081188

test/src/test/groovy/org/zstack/test/integration/networkservice/provider/flat/securitygroup/AddSecurityGroupRuleOptimizedCase.groovy

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ class AddSecurityGroupRuleOptimizedCase extends SubCase {
540540
addSecurityGroupRule {
541541
securityGroupUuid = sg3.uuid
542542
rules = [rule_82]
543-
priority = 82
543+
priority = 101
544544
}
545545
}
546546
}
@@ -591,13 +591,12 @@ class AddSecurityGroupRuleOptimizedCase extends SubCase {
591591
rule_13.protocol = "ALL"
592592
rule_13.startPort = -1
593593
rule_13.endPort = -1
594-
expect(AssertionError) {
595-
addSecurityGroupRule {
596-
securityGroupUuid = sg3.uuid
597-
rules = [rule_13]
598-
priority = 13
599-
}
594+
sg3 = addSecurityGroupRule {
595+
securityGroupUuid = sg3.uuid
596+
rules = [rule_13]
597+
priority = 13
600598
}
599+
assert sg3.rules.find { it.allowedCidr == rule_13.allowedCidr && it.priority == 13 } != null
601600

602601
SecurityGroupRuleAO rule_12 = new SecurityGroupRuleAO()
603602
rule_12.dstIpRange = "2.2.2.2-2.2.2.10"
@@ -609,12 +608,10 @@ class AddSecurityGroupRuleOptimizedCase extends SubCase {
609608
ingressRule.protocol = "TCP"
610609
ingressRule.dstPortRange = "12-13"
611610

612-
expect(AssertionError) {
613-
addSecurityGroupRule {
614-
securityGroupUuid = sg3.uuid
615-
rules = [rule_12, ingressRule]
616-
priority = 12
617-
}
611+
sg3 = addSecurityGroupRule {
612+
securityGroupUuid = sg3.uuid
613+
rules = [rule_12, ingressRule]
614+
priority = 12
618615
}
619616

620617
}

test/src/test/groovy/org/zstack/test/integration/networkservice/provider/flat/securitygroup/ChangeSecurityGroupRuleCase.groovy

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -231,17 +231,15 @@ class ChangeSecurityGroupRuleCase extends SubCase {
231231
assert sg3 != null
232232
SecurityGroupRuleInventory rule_1 = sg3.rules.find { it.type == "Ingress" && it.priority == 1 && it.ipVersion == 4 }
233233

234-
expect(AssertionError) {
235-
changeSecurityGroupRule {
236-
uuid = rule_1.uuid
237-
priority = 6
238-
}
234+
changeSecurityGroupRule {
235+
uuid = rule_1.uuid
236+
priority = 6
239237
}
240238

241239
expect(AssertionError) {
242240
changeSecurityGroupRule {
243241
uuid = rule_1.uuid
244-
priority = 7
242+
priority = 101
245243
}
246244
}
247245
}
@@ -307,11 +305,9 @@ class ChangeSecurityGroupRuleCase extends SubCase {
307305
}
308306
}
309307

310-
expect(AssertionError) {
311-
changeSecurityGroupRule {
312-
uuid = rule1.uuid
313-
priority = 3
314-
}
308+
changeSecurityGroupRule {
309+
uuid = rule1.uuid
310+
priority = 3
315311
}
316312

317313
expect(AssertionError) {

0 commit comments

Comments
 (0)