mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Automatic merge from release/2.4.0 -> release/2.5.0
* commit 'b63e32a8d467a9faa4fae7763c7787831752fd14': update aws secrule sync
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"net"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
@@ -157,6 +158,34 @@ func IntVal(s *int64) int64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
// SecurityRuleSet to allow list
|
||||
// 将安全组规则全部转换为等价的allow规则
|
||||
func SecurityRuleSetToAllowSet(srs secrules.SecurityRuleSet) secrules.SecurityRuleSet {
|
||||
inRuleSet := secrules.SecurityRuleSet{}
|
||||
outRuleSet := secrules.SecurityRuleSet{}
|
||||
|
||||
for _, rule := range srs {
|
||||
if rule.Direction == secrules.SecurityRuleIngress {
|
||||
inRuleSet = append(inRuleSet, rule)
|
||||
}
|
||||
|
||||
if rule.Direction == secrules.SecurityRuleEgress {
|
||||
outRuleSet = append(outRuleSet, rule)
|
||||
}
|
||||
}
|
||||
|
||||
sort.Sort(inRuleSet)
|
||||
sort.Sort(outRuleSet)
|
||||
|
||||
inRuleSet = inRuleSet.AllowList()
|
||||
outRuleSet = outRuleSet.AllowList()
|
||||
|
||||
ret := secrules.SecurityRuleSet{}
|
||||
ret = append(ret, inRuleSet...)
|
||||
ret = append(ret, outRuleSet...)
|
||||
return ret
|
||||
}
|
||||
|
||||
func isAwsPermissionAllPorts(p ec2.IpPermission) bool {
|
||||
if p.FromPort == nil || p.ToPort == nil {
|
||||
return false
|
||||
|
||||
@@ -146,6 +146,7 @@ func (self *SRegion) SyncSecurityGroup(secgroupId string, vpcId string, name str
|
||||
secgroupId = fmt.Sprintf("%s-%s", vpcId, secgroupId)
|
||||
}
|
||||
|
||||
rules = SecurityRuleSetToAllowSet(rules)
|
||||
if secgroup, err := self.getSecurityGroupById(vpcId, secgroupId); err != nil {
|
||||
if len(desc) == 0 {
|
||||
desc = fmt.Sprintf("security group %s for vpc %s", name, vpcId)
|
||||
|
||||
Reference in New Issue
Block a user