Skip to content

Commit 150775e

Browse files
committed
[UDN isolation] Fix ACLs tier: move to the highest-prio Primary tier.
Start using new BuildACL for all functions that need non-default tier. Signed-off-by: Nadia Pinaeva <[email protected]>
1 parent 23c3b5a commit 150775e

File tree

3 files changed

+76
-17
lines changed

3 files changed

+76
-17
lines changed

go-controller/pkg/libovsdb/util/acl.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ func BuildACL(dbIDs *libovsdbops.DbObjectIDs, priority int, match, action string
135135
}
136136

137137
func BuildANPACL(dbIDs *libovsdbops.DbObjectIDs, priority int, match, action string, aclT ACLPipelineType, logLevels *ACLLoggingLevels) *nbdb.ACL {
138-
anpACL := BuildACLWithDefaultTier(dbIDs, priority, match, action, logLevels, aclT)
139-
anpACL.Tier = GetACLTier(dbIDs)
138+
anpACL := BuildACL(dbIDs, priority, match, action, logLevels, aclT, GetACLTier(dbIDs))
140139
return anpACL
141140
}
142141

go-controller/pkg/ovn/udn_isolation.go

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const (
3030
DenySecondaryACL = "DenySecondary"
3131
// OpenPortACLPrefix is used to build per-pod ACLs, pod name should be added to the prefix to build a unique name
3232
OpenPortACLPrefix = "OpenPort-"
33+
// the same tier is used for all UDN isolation ACLs
34+
isolationTier = types.PrimaryACLTier
3335
)
3436

3537
// setupUDNACLs should be called after the node's management port was configured
@@ -63,7 +65,8 @@ func (oc *DefaultNetworkController) setupUDNACLs(mgmtPortIPs []net.IP) error {
6365
pgName := libovsdbutil.GetPortGroupName(pgIDs)
6466
egressDenyIDs := oc.getUDNACLDbIDs(DenySecondaryACL, libovsdbutil.ACLEgress)
6567
match := libovsdbutil.GetACLMatch(pgName, "", libovsdbutil.ACLEgress)
66-
egressDenyACL := libovsdbutil.BuildACLWithDefaultTier(egressDenyIDs, types.PrimaryUDNDenyPriority, match, nbdb.ACLActionDrop, nil, libovsdbutil.LportEgress)
68+
egressDenyACL := libovsdbutil.BuildACL(egressDenyIDs, types.PrimaryUDNDenyPriority, match, nbdb.ACLActionDrop,
69+
nil, libovsdbutil.LportEgress, isolationTier)
6770

6871
getARPMatch := func(direction libovsdbutil.ACLDirection) string {
6972
match := "("
@@ -89,15 +92,18 @@ func (oc *DefaultNetworkController) setupUDNACLs(mgmtPortIPs []net.IP) error {
8992

9093
egressARPIDs := oc.getUDNACLDbIDs(AllowHostARPACL, libovsdbutil.ACLEgress)
9194
match = libovsdbutil.GetACLMatch(pgName, getARPMatch(libovsdbutil.ACLEgress), libovsdbutil.ACLEgress)
92-
egressARPACL := libovsdbutil.BuildACLWithDefaultTier(egressARPIDs, types.PrimaryUDNAllowPriority, match, nbdb.ACLActionAllow, nil, libovsdbutil.LportEgress)
95+
egressARPACL := libovsdbutil.BuildACL(egressARPIDs, types.PrimaryUDNAllowPriority, match, nbdb.ACLActionAllow,
96+
nil, libovsdbutil.LportEgress, isolationTier)
9397

9498
ingressDenyIDs := oc.getUDNACLDbIDs(DenySecondaryACL, libovsdbutil.ACLIngress)
9599
match = libovsdbutil.GetACLMatch(pgName, "", libovsdbutil.ACLIngress)
96-
ingressDenyACL := libovsdbutil.BuildACLWithDefaultTier(ingressDenyIDs, types.PrimaryUDNDenyPriority, match, nbdb.ACLActionDrop, nil, libovsdbutil.LportIngress)
100+
ingressDenyACL := libovsdbutil.BuildACL(ingressDenyIDs, types.PrimaryUDNDenyPriority, match, nbdb.ACLActionDrop,
101+
nil, libovsdbutil.LportIngress, isolationTier)
97102

98103
ingressARPIDs := oc.getUDNACLDbIDs(AllowHostARPACL, libovsdbutil.ACLIngress)
99104
match = libovsdbutil.GetACLMatch(pgName, getARPMatch(libovsdbutil.ACLIngress), libovsdbutil.ACLIngress)
100-
ingressARPACL := libovsdbutil.BuildACLWithDefaultTier(ingressARPIDs, types.PrimaryUDNAllowPriority, match, nbdb.ACLActionAllow, nil, libovsdbutil.LportIngress)
105+
ingressARPACL := libovsdbutil.BuildACL(ingressARPIDs, types.PrimaryUDNAllowPriority, match, nbdb.ACLActionAllow,
106+
nil, libovsdbutil.LportIngress, isolationTier)
101107

102108
ingressAllowIDs := oc.getUDNACLDbIDs(AllowHostSecondaryACL, libovsdbutil.ACLIngress)
103109
match = "("
@@ -114,7 +120,8 @@ func (oc *DefaultNetworkController) setupUDNACLs(mgmtPortIPs []net.IP) error {
114120
}
115121
match += ")"
116122
match = libovsdbutil.GetACLMatch(pgName, match, libovsdbutil.ACLIngress)
117-
ingressAllowACL := libovsdbutil.BuildACLWithDefaultTier(ingressAllowIDs, types.PrimaryUDNAllowPriority, match, nbdb.ACLActionAllowRelated, nil, libovsdbutil.LportIngress)
123+
ingressAllowACL := libovsdbutil.BuildACL(ingressAllowIDs, types.PrimaryUDNAllowPriority, match, nbdb.ACLActionAllowRelated,
124+
nil, libovsdbutil.LportIngress, isolationTier)
118125

119126
ops, err := libovsdbops.CreateOrUpdateACLsOps(oc.nbClient, nil, oc.GetSamplingConfig(), egressDenyACL, egressARPACL, ingressARPACL, ingressDenyACL, ingressAllowACL)
120127
if err != nil {
@@ -199,12 +206,12 @@ func (oc *DefaultNetworkController) setUDNPodOpenPortsOps(podNamespacedName stri
199206
ingressMatch, egressMatch, parseErr := getPortsMatches(podAnnotations, lspName)
200207
// don't return on parseErr, as we need to cleanup potentially present ACLs from the previous config
201208
ingressIDs := oc.getUDNOpenPortDbIDs(podNamespacedName, libovsdbutil.ACLIngress)
202-
ingressACL := libovsdbutil.BuildACLWithDefaultTier(ingressIDs, types.PrimaryUDNAllowPriority,
203-
ingressMatch, nbdb.ACLActionAllowRelated, nil, libovsdbutil.LportIngress)
209+
ingressACL := libovsdbutil.BuildACL(ingressIDs, types.PrimaryUDNAllowPriority,
210+
ingressMatch, nbdb.ACLActionAllowRelated, nil, libovsdbutil.LportIngress, isolationTier)
204211

205212
egressIDs := oc.getUDNOpenPortDbIDs(podNamespacedName, libovsdbutil.ACLEgress)
206-
egressACL := libovsdbutil.BuildACLWithDefaultTier(egressIDs, types.PrimaryUDNAllowPriority,
207-
egressMatch, nbdb.ACLActionAllow, nil, libovsdbutil.LportEgress)
213+
egressACL := libovsdbutil.BuildACL(egressIDs, types.PrimaryUDNAllowPriority,
214+
egressMatch, nbdb.ACLActionAllow, nil, libovsdbutil.LportEgress, isolationTier)
208215

209216
var err error
210217
if ingressMatch == "" && egressMatch == "" || parseErr != nil {
@@ -282,14 +289,14 @@ func BuildAdvertisedNetworkSubnetsDropACL(advertisedNetworkSubnetsAddressSet add
282289
dropMatches = append(dropMatches, fmt.Sprintf("(ip6.src == $%s && ip6.dst == $%s)", v6AddrSet, v6AddrSet))
283290
}
284291

285-
dropACL := libovsdbutil.BuildACLWithDefaultTier(
292+
dropACL := libovsdbutil.BuildACL(
286293
GetAdvertisedNetworkSubnetsDropACLdbIDs(),
287294
types.AdvertisedNetworkDenyPriority,
288295
strings.Join(dropMatches, " || "),
289296
nbdb.ACLActionDrop,
290297
nil,
291-
libovsdbutil.LportEgressAfterLB)
292-
dropACL.Tier = types.PrimaryACLTier
298+
libovsdbutil.LportEgressAfterLB,
299+
isolationTier)
293300
return dropACL
294301
}
295302

@@ -325,14 +332,14 @@ func (bnc *BaseNetworkController) addAdvertisedNetworkIsolation(nodeName string)
325332
ops = append(ops, addrOps...)
326333

327334
if len(passMatches) > 0 {
328-
passACL := libovsdbutil.BuildACLWithDefaultTier(
335+
passACL := libovsdbutil.BuildACL(
329336
GetAdvertisedNetworkSubnetsPassACLdbIDs(bnc.controllerName, bnc.GetNetworkName(), bnc.GetNetworkID()),
330337
types.AdvertisedNetworkPassPriority,
331338
strings.Join(passMatches, " || "),
332339
nbdb.ACLActionPass,
333340
nil,
334-
libovsdbutil.LportEgressAfterLB)
335-
passACL.Tier = types.PrimaryACLTier
341+
libovsdbutil.LportEgressAfterLB,
342+
isolationTier)
336343

337344
ops, err = libovsdbops.CreateOrUpdateACLsOps(bnc.nbClient, ops, nil, passACL)
338345
if err != nil {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package ovn
2+
3+
import (
4+
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/config"
5+
libovsdbops "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/libovsdb/ops"
6+
libovsdbutil "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/libovsdb/util"
7+
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/nbdb"
8+
libovsdbtest "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/testing/libovsdb"
9+
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/types"
10+
11+
. "github.com/onsi/ginkgo/v2"
12+
. "github.com/onsi/gomega"
13+
)
14+
15+
var _ = Describe("UDN Isolation", func() {
16+
BeforeEach(func() {
17+
Expect(config.PrepareTestConfig()).To(Succeed())
18+
})
19+
20+
It("ACLs should be updated to the Primary tier ", func() {
21+
config.OVNKubernetesFeature.EnableMultiNetwork = true
22+
config.OVNKubernetesFeature.EnableNetworkSegmentation = true
23+
fakeController := getFakeController(DefaultNetworkControllerName)
24+
25+
// build port group with one ACL that has default tier
26+
pgIDs := fakeController.getSecondaryPodsPortGroupDbIDs()
27+
pgName := libovsdbutil.GetPortGroupName(pgIDs)
28+
egressDenyIDs := fakeController.getUDNACLDbIDs(DenySecondaryACL, libovsdbutil.ACLEgress)
29+
match := libovsdbutil.GetACLMatch(pgName, "", libovsdbutil.ACLEgress)
30+
// in the real code we use BuildACL here instead of BuildACLWithDefaultTier
31+
egressDenyACL := libovsdbutil.BuildACLWithDefaultTier(egressDenyIDs, types.PrimaryUDNDenyPriority, match, nbdb.ACLActionDrop,
32+
nil, libovsdbutil.LportEgress)
33+
// required to make sure port group correctly references the ACL
34+
egressDenyACL.UUID = egressDenyIDs.String() + "-UUID"
35+
pg := libovsdbutil.BuildPortGroup(pgIDs, nil, []*nbdb.ACL{egressDenyACL})
36+
37+
nbClient, nbCleanup, err := libovsdbtest.NewNBTestHarness(libovsdbtest.TestSetup{
38+
NBData: []libovsdbtest.TestData{egressDenyACL, pg},
39+
}, nil)
40+
Expect(err).NotTo(HaveOccurred())
41+
defer nbCleanup.Cleanup()
42+
fakeController.nbClient = nbClient
43+
44+
// now run the setupUDNACLs function which should create all ACLs and update the existing ACLs to the Primary tier
45+
Expect(fakeController.setupUDNACLs(nil)).To(Succeed())
46+
47+
// verify that the egressDenyACL is updated to the Primary 0
48+
acls, err := libovsdbops.FindACLs(nbClient, []*nbdb.ACL{egressDenyACL})
49+
Expect(err).NotTo(HaveOccurred())
50+
Expect(acls).To(HaveLen(1))
51+
Expect(acls[0].Tier).To(Equal(types.PrimaryACLTier))
52+
})
53+
})

0 commit comments

Comments
 (0)