Skip to content

Commit b93defd

Browse files
committed
delete legacy denyall acls when upgrading to v1.13.x (#4742)
the acls in v1.13.x are in tier 2 rather than tier 0 in v1.12.x, which results that legacy denyall sg will drop all traffics if a pod bound a sg, because acls in tier 0 have the higest priority. we should recreate acls in denyall sg when upgrading to v1.13.x. Signed-off-by: Rain Suo <[email protected]>
1 parent a80490a commit b93defd

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

pkg/ovs/ovn-nb-acl.go

+26
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,32 @@ func (c *OVNNbClient) CreateNodeACL(pgName, nodeIPStr, joinIPStr string) error {
277277
func (c *OVNNbClient) CreateSgDenyAllACL(sgName string) error {
278278
pgName := GetSgPortGroupName(sgName)
279279

280+
// for upgrading from v1.12.x to v1.13.x
281+
// see https://github.com/kubeovn/kube-ovn/issues/4742
282+
oldIngressACL, err := c.GetACL(pgName, ovnnb.ACLDirectionToLport, util.SecurityGroupDropPriority, fmt.Sprintf("outport == @%s && ip", pgName), true)
283+
if err != nil {
284+
klog.Error(err)
285+
return err
286+
}
287+
if oldIngressACL != nil && oldIngressACL.Tier == util.DefaultACLTier {
288+
if err := c.DeleteACL(pgName, portGroupKey, ovnnb.ACLDirectionToLport, util.SecurityGroupDropPriority, fmt.Sprintf("outport == @%s && ip", pgName)); err != nil {
289+
klog.Errorf("delete legacy acl from port group %s: %v", pgName, err)
290+
return err
291+
}
292+
}
293+
oldEgressACL, err := c.GetACL(pgName, ovnnb.ACLDirectionFromLport, util.SecurityGroupDropPriority, fmt.Sprintf("inport == @%s && ip", pgName), true)
294+
if err != nil {
295+
klog.Error(err)
296+
return err
297+
}
298+
if oldEgressACL != nil && oldEgressACL.Tier == util.DefaultACLTier {
299+
if err := c.DeleteACL(pgName, portGroupKey, ovnnb.ACLDirectionFromLport, util.SecurityGroupDropPriority, fmt.Sprintf("inport == @%s && ip", pgName)); err != nil {
300+
klog.Errorf("delete legacy acl from port group %s: %v", pgName, err)
301+
return err
302+
}
303+
}
304+
305+
// create new acls for deny all sg
280306
ingressACL, err := c.newACL(pgName, ovnnb.ACLDirectionToLport, util.SecurityGroupDropPriority, fmt.Sprintf("outport == @%s && ip", pgName), ovnnb.ACLActionDrop, util.NetpolACLTier)
281307
if err != nil {
282308
klog.Error(err)

pkg/ovs/ovn-nb-acl_test.go

+43
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,49 @@ func (suite *OvnClientTestSuite) testCreateSgDenyAllACL() {
612612
require.Contains(t, pg.ACLs, egressACL.UUID)
613613
})
614614

615+
t.Run("upgrading create sg deny all acl", func(t *testing.T) {
616+
sgName := "test_create_deny_all_acl_pg"
617+
pgName := GetSgPortGroupName(sgName)
618+
619+
err := nbClient.CreatePortGroup(pgName, nil)
620+
require.NoError(t, err)
621+
622+
// init legacy acls
623+
legacyIngressACL, err := nbClient.newACL(pgName, ovnnb.ACLDirectionToLport, util.SecurityGroupDropPriority, fmt.Sprintf("outport == @%s && ip", pgName), ovnnb.ACLActionDrop, util.DefaultACLTier)
624+
require.NoError(t, err)
625+
626+
legacyEgressACL, err := nbClient.newACL(pgName, ovnnb.ACLDirectionFromLport, util.SecurityGroupDropPriority, fmt.Sprintf("inport == @%s && ip", pgName), ovnnb.ACLActionDrop, util.DefaultACLTier)
627+
require.NoError(t, err)
628+
629+
err = nbClient.CreateAcls(pgName, portGroupKey, legacyIngressACL, legacyEgressACL)
630+
require.NoError(t, err)
631+
632+
// create deny all acls normally
633+
err = nbClient.CreateSgDenyAllACL(sgName)
634+
require.NoError(t, err)
635+
636+
pg, err := nbClient.GetPortGroup(pgName, false)
637+
require.NoError(t, err)
638+
639+
// ingress acl
640+
match := fmt.Sprintf("outport == @%s && ip", pgName)
641+
ingressACL, err := nbClient.GetACL(pgName, ovnnb.ACLDirectionToLport, util.SecurityGroupDropPriority, match, false)
642+
require.NoError(t, err)
643+
expect := newACL(pgName, ovnnb.ACLDirectionToLport, util.SecurityGroupDropPriority, match, ovnnb.ACLActionDrop, util.NetpolACLTier)
644+
expect.UUID = ingressACL.UUID
645+
require.Equal(t, expect, ingressACL)
646+
require.Contains(t, pg.ACLs, ingressACL.UUID)
647+
648+
// egress acl
649+
match = fmt.Sprintf("inport == @%s && ip", pgName)
650+
egressACL, err := nbClient.GetACL(pgName, ovnnb.ACLDirectionFromLport, util.SecurityGroupDropPriority, match, false)
651+
require.NoError(t, err)
652+
expect = newACL(pgName, ovnnb.ACLDirectionFromLport, util.SecurityGroupDropPriority, match, ovnnb.ACLActionDrop, util.NetpolACLTier)
653+
expect.UUID = egressACL.UUID
654+
require.Equal(t, expect, egressACL)
655+
require.Contains(t, pg.ACLs, egressACL.UUID)
656+
})
657+
615658
t.Run("should print log err when sg name does not exist", func(t *testing.T) {
616659
sgName := "test_nonexist_pg"
617660
err := nbClient.CreateSgDenyAllACL(sgName)

pkg/util/const.go

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ const (
157157
AnpMaxPriority = 99
158158
AnpACLMaxPriority = 30000
159159
BanpACLMaxPriority = 1800
160+
DefaultACLTier = 0
160161
AnpACLTier = 1
161162
NetpolACLTier = 2
162163
BanpACLTier = 3

0 commit comments

Comments
 (0)