Skip to content

Commit 365c8cd

Browse files
authored
fix(policy): race condition when listener state is switched from Ignored to Ready (backport of #16323) (#16341)
Automatic cherry-pick of #16323 for branch release-2.12 Generated by [action](https://github.com/kumahq/kuma/actions/runs/24769454777) cherry-picked commit 39e1834 --------- Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
1 parent 93217d7 commit 365c8cd

5 files changed

Lines changed: 83 additions & 8 deletions

File tree

api/mesh/v1alpha1/dataplane_helpers.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,6 @@ func (n *Dataplane_Networking) GetInboundForPort(port uint32) *Dataplane_Network
297297
func (n *Dataplane_Networking) InboundsSelectedBySectionName(sectionName string) []InboundInterface {
298298
var selectedInbounds []InboundInterface
299299
for _, inbound := range n.Inbound {
300-
if inbound.State == Dataplane_Networking_Inbound_Ignored {
301-
continue
302-
}
303300
if sectionName == "" || inbound.GetSectionName() == sectionName {
304301
selectedInbounds = append(selectedInbounds, n.ToInboundInterface(inbound))
305302
}

api/mesh/v1alpha1/dataplane_helpers_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,71 @@ var _ = Describe("Dataplane_Networking", func() {
138138
})
139139
})
140140

141+
Describe("InboundsSelectedBySectionName()", func() {
142+
type testCase struct {
143+
sectionName string
144+
expected []InboundInterface
145+
}
146+
147+
DescribeTable("should select inbounds regardless of their state",
148+
func(given testCase) {
149+
networking := &Dataplane_Networking{
150+
Address: "192.168.0.1",
151+
Inbound: []*Dataplane_Networking_Inbound{
152+
{
153+
Name: "main-port",
154+
Port: 80,
155+
State: Dataplane_Networking_Inbound_Ignored,
156+
},
157+
{
158+
Name: "secondary-port",
159+
Port: 443,
160+
State: Dataplane_Networking_Inbound_Ready,
161+
},
162+
},
163+
}
164+
165+
selectedInbounds := networking.InboundsSelectedBySectionName(given.sectionName)
166+
167+
Expect(selectedInbounds).To(ConsistOf(given.expected))
168+
},
169+
Entry("empty sectionName selects all inbounds", testCase{
170+
expected: []InboundInterface{
171+
{
172+
DataplaneAdvertisedIP: "192.168.0.1",
173+
DataplaneIP: "192.168.0.1",
174+
DataplanePort: 80,
175+
WorkloadIP: "192.168.0.1",
176+
WorkloadPort: 80,
177+
},
178+
{
179+
DataplaneAdvertisedIP: "192.168.0.1",
180+
DataplaneIP: "192.168.0.1",
181+
DataplanePort: 443,
182+
WorkloadIP: "192.168.0.1",
183+
WorkloadPort: 443,
184+
},
185+
},
186+
}),
187+
Entry("matching sectionName selects ignored inbound", testCase{
188+
sectionName: "main-port",
189+
expected: []InboundInterface{
190+
{
191+
DataplaneAdvertisedIP: "192.168.0.1",
192+
DataplaneIP: "192.168.0.1",
193+
DataplanePort: 80,
194+
WorkloadIP: "192.168.0.1",
195+
WorkloadPort: 80,
196+
},
197+
},
198+
}),
199+
Entry("non-matching sectionName selects no inbounds", testCase{
200+
sectionName: "unknown-port",
201+
expected: []InboundInterface{},
202+
}),
203+
)
204+
})
205+
141206
Describe("GetHealthyInbounds()", func() {
142207
It("should return only healty inbounds", func() {
143208
networking := &Dataplane_Networking{

pkg/plugins/policies/core/matchers/dataplane.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,6 @@ func isSupportedProxyType(supportedTypes []common_api.TargetRefProxyType, dppTyp
326326
func inboundsSelectedByTags(tagsSelector mesh_proto.TagSelector, dpp *core_mesh.DataplaneResource, gateway *core_mesh.MeshGatewayResource) ([]core_rules.InboundListener, []core_rules.InboundListenerHostname, bool) {
327327
inbounds := []core_rules.InboundListener{}
328328
for _, inbound := range dpp.Spec.GetNetworking().GetInbound() {
329-
if inbound.State == mesh_proto.Dataplane_Networking_Inbound_Ignored {
330-
continue
331-
}
332329
if tagsSelector.Matches(inbound.Tags) {
333330
intf := dpp.Spec.GetNetworking().ToInboundInterface(inbound)
334331
inbounds = append(inbounds, core_rules.InboundListener{
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1-
items: []
1+
items:
2+
- creationTime: "0001-01-01T00:00:00Z"
3+
mesh: mesh-1
4+
modificationTime: "0001-01-01T00:00:00Z"
5+
name: mtp-1
6+
spec:
7+
from:
8+
- default:
9+
action: Allow
10+
targetRef:
11+
kind: Mesh
12+
targetRef:
13+
kind: MeshServiceSubset
14+
name: web
15+
tags:
16+
version: v1
17+
type: MeshTrafficPermission
218
next: null
319
total: 0

pkg/plugins/policies/core/matchers/testdata/matchedpolicies/dataplanepolicies/07.policies.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 07. policies do not select anything because inbound is ignored
1+
# 07. policies select ignored inbounds by tags
22
type: MeshTrafficPermission
33
mesh: mesh-1
44
name: mtp-1

0 commit comments

Comments
 (0)