Skip to content

Commit e80879c

Browse files
袁又袁yuanliu
authored andcommitted
add base sg rules for ports (#2365)
Co-authored-by: yuanliu <yuanliu@cmss.chinamobile.com>
1 parent f90aa39 commit e80879c

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

pkg/controller/security_group.go

+6
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ func (c *Controller) handleAddOrUpdateSg(key string) error {
254254
c.patchSgStatus(sg)
255255
return err
256256
}
257+
if err := c.ovnLegacyClient.CreateSgBaseIngressACL(sg.Name); err != nil {
258+
return err
259+
}
257260
sg.Status.IngressMd5 = newIngressMd5
258261
sg.Status.IngressLastSyncSuccess = true
259262
c.patchSgStatus(sg)
@@ -264,6 +267,9 @@ func (c *Controller) handleAddOrUpdateSg(key string) error {
264267
c.patchSgStatus(sg)
265268
return err
266269
}
270+
if err := c.ovnLegacyClient.CreateSgBaseEgressACL(sg.Name); err != nil {
271+
return err
272+
}
267273
sg.Status.EgressMd5 = newEgressMd5
268274
sg.Status.EgressLastSyncSuccess = true
269275
c.patchSgStatus(sg)

pkg/ovs/ovn-nbctl-legacy.go

+59
Original file line numberDiff line numberDiff line change
@@ -2377,6 +2377,65 @@ func (c LegacyClient) CreateSgDenyAllACL() error {
23772377
return nil
23782378
}
23792379

2380+
func (c LegacyClient) CreateSgBaseEgressACL(sgName string) error {
2381+
portGroupName := GetSgPortGroupName(sgName)
2382+
klog.Infof("add base egress acl, sg: %s", portGroupName)
2383+
// allow arp
2384+
if _, err := c.ovnNbCommand(MayExist, "--type=port-group", "acl-add", portGroupName, string(SgAclEgressDirection), util.SecurityGroupBasePriority,
2385+
fmt.Sprintf("outport==@%s && arp", portGroupName), "allow-related"); err != nil {
2386+
return err
2387+
}
2388+
2389+
// icmpv6
2390+
if _, err := c.ovnNbCommand(MayExist, "--type=port-group", "acl-add", portGroupName, string(SgAclEgressDirection), util.SecurityGroupBasePriority,
2391+
fmt.Sprintf("outport==@%s && icmp6.type=={130, 133, 135, 136} && icmp6.code == 0 && ip.ttl == 255", portGroupName), "allow-related"); err != nil {
2392+
return err
2393+
}
2394+
2395+
// dhcpv4 res
2396+
if _, err := c.ovnNbCommand(MayExist, "--type=port-group", "acl-add", portGroupName, string(SgAclEgressDirection), util.SecurityGroupBasePriority,
2397+
fmt.Sprintf("outport==@%s && udp.src==68 && udp.dst==67 && ip4", portGroupName), "allow-related"); err != nil {
2398+
return err
2399+
}
2400+
2401+
// dhcpv6 res
2402+
if _, err := c.ovnNbCommand(MayExist, "--type=port-group", "acl-add", portGroupName, string(SgAclEgressDirection), util.SecurityGroupBasePriority,
2403+
fmt.Sprintf("outport==@%s && udp.src==546 && udp.dst==547 && ip6", portGroupName), "allow-related"); err != nil {
2404+
return err
2405+
}
2406+
return nil
2407+
}
2408+
2409+
func (c LegacyClient) CreateSgBaseIngressACL(sgName string) error {
2410+
portGroupName := GetSgPortGroupName(sgName)
2411+
klog.Infof("add base ingress acl, sg: %s", portGroupName)
2412+
// allow arp
2413+
if _, err := c.ovnNbCommand(MayExist, "--type=port-group", "acl-add", portGroupName, string(SgAclIngressDirection), util.SecurityGroupBasePriority,
2414+
fmt.Sprintf("inport==@%s && arp", portGroupName), "allow-related"); err != nil {
2415+
return err
2416+
}
2417+
2418+
// icmpv6
2419+
if _, err := c.ovnNbCommand(MayExist, "--type=port-group", "acl-add", portGroupName, string(SgAclIngressDirection), util.SecurityGroupBasePriority,
2420+
fmt.Sprintf("inport==@%s && icmp6.type=={130, 134, 135, 136} && icmp6.code == 0 && ip.ttl == 255", portGroupName), "allow-related"); err != nil {
2421+
return err
2422+
}
2423+
2424+
// dhcpv4 offer
2425+
if _, err := c.ovnNbCommand(MayExist, "--type=port-group", "acl-add", portGroupName, string(SgAclIngressDirection), util.SecurityGroupBasePriority,
2426+
fmt.Sprintf("inport==@%s && udp.src==67 && udp.dst==68 && ip4", portGroupName), "allow-related"); err != nil {
2427+
return err
2428+
}
2429+
2430+
// dhcpv6 offer
2431+
if _, err := c.ovnNbCommand(MayExist, "--type=port-group", "acl-add", portGroupName, string(SgAclIngressDirection), util.SecurityGroupBasePriority,
2432+
fmt.Sprintf("inport==@%s && udp.src==547 && udp.dst==546 && ip6", portGroupName), "allow-related"); err != nil {
2433+
return err
2434+
}
2435+
2436+
return nil
2437+
}
2438+
23802439
func (c LegacyClient) UpdateSgACL(sg *kubeovnv1.SecurityGroup, direction AclDirection) error {
23812440
sgPortGroupName := GetSgPortGroupName(sg.Name)
23822441
// clear acl

pkg/util/const.go

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ const (
111111
NodeAllowPriority = "3000"
112112

113113
SecurityGroupHighestPriority = "2300"
114+
SecurityGroupBasePriority = "2005"
114115
SecurityGroupAllowPriority = "2004"
115116
SecurityGroupDropPriority = "2003"
116117

0 commit comments

Comments
 (0)