-
Notifications
You must be signed in to change notification settings - Fork 336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(kuma-cp): implement possibility to select proxies in policies by new kind Dataplane #12573
Open
Automaat
wants to merge
2
commits into
kumahq:master
Choose a base branch
from
Automaat:feat/kind-dataplane-implem
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -162,6 +162,12 @@ func dppSelectedByPolicy( | |||
return inbounds, gwListeners, gateway, nil | ||||
} | ||||
return []core_rules.InboundListener{}, nil, false, nil | ||||
case common_api.Dataplane: | ||||
if allDataplanesSelected(ref) || isSelectedByName(dpp, ref) || isSelectedByLabels(dpp, ref) { | ||||
inbounds := inboundsSelectedBySectionName(ref.SectionName, dpp) | ||||
return inbounds, nil, false, nil | ||||
} | ||||
return []core_rules.InboundListener{}, nil, false, nil | ||||
case common_api.MeshSubset: | ||||
if isSupportedProxyType(ref.ProxyTypes, resolveDataplaneProxyType(dpp)) { | ||||
inbounds, gwListeners, gateway := inboundsSelectedByTags(ref.Tags, dpp, gateway) | ||||
|
@@ -199,6 +205,44 @@ func dppSelectedByPolicy( | |||
} | ||||
} | ||||
|
||||
func allDataplanesSelected(ref common_api.TargetRef) bool { | ||||
return ref.Name == "" && ref.Namespace == "" && ref.Labels == nil | ||||
} | ||||
|
||||
func inboundsSelectedBySectionName(sectionName string, dpp *core_mesh.DataplaneResource) []core_rules.InboundListener { | ||||
var selectedInbounds []core_rules.InboundListener | ||||
for _, inbound := range dpp.Spec.GetNetworking().Inbound { | ||||
if inbound.State == mesh_proto.Dataplane_Networking_Inbound_Ignored { | ||||
continue | ||||
} | ||||
if sectionName == "" || inbound.Name == sectionName { | ||||
intf := dpp.Spec.GetNetworking().ToInboundInterface(inbound) | ||||
selectedInbounds = append(selectedInbounds, core_rules.InboundListener{ | ||||
Address: intf.DataplaneIP, | ||||
Port: intf.DataplanePort, | ||||
}) | ||||
} | ||||
} | ||||
return selectedInbounds | ||||
} | ||||
|
||||
func isSelectedByLabels(dpp *core_mesh.DataplaneResource, ref common_api.TargetRef) bool { | ||||
if ref.Labels == nil { | ||||
return false | ||||
} | ||||
|
||||
for label, value := range ref.Labels { | ||||
if dpp.GetMeta().GetLabels()[label] != value { | ||||
return false | ||||
} | ||||
} | ||||
return true | ||||
} | ||||
|
||||
func isSelectedByName(dpp *core_mesh.DataplaneResource, ref common_api.TargetRef) bool { | ||||
return core_model.GetDisplayName(dpp.GetMeta()) == ref.Name | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||
} | ||||
|
||||
func dppSelectedByNamespace(meta core_model.ResourceMeta, dpp *core_mesh.DataplaneResource) bool { | ||||
switch core_model.PolicyRole(meta) { | ||||
case mesh_proto.ConsumerPolicyRole, mesh_proto.WorkloadOwnerPolicyRole: | ||||
|
16 changes: 16 additions & 0 deletions
16
...s/testdata/matchedpolicies/dataplanepolicies/dataplane-targetref-by-lables.dataplane.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
type: Dataplane | ||
mesh: mesh-1 | ||
name: dp-1 | ||
labels: | ||
app: demo | ||
networking: | ||
address: 1.1.1.1 | ||
inbound: | ||
- port: 8080 | ||
tags: | ||
kuma.io/service: web | ||
version: v1 | ||
- port: 8081 | ||
tags: | ||
kuma.io/service: web | ||
version: v3 |
18 changes: 18 additions & 0 deletions
18
...hers/testdata/matchedpolicies/dataplanepolicies/dataplane-targetref-by-lables.golden.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
items: | ||
- creationTime: "0001-01-01T00:00:00Z" | ||
mesh: mesh-1 | ||
modificationTime: "0001-01-01T00:00:00Z" | ||
name: mtp-1 | ||
spec: | ||
from: | ||
- default: | ||
action: Deny | ||
targetRef: | ||
kind: Mesh | ||
targetRef: | ||
kind: Dataplane | ||
labels: | ||
app: demo | ||
type: MeshTrafficPermission | ||
next: null | ||
total: 0 |
27 changes: 27 additions & 0 deletions
27
...rs/testdata/matchedpolicies/dataplanepolicies/dataplane-targetref-by-lables.policies.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
type: MeshTrafficPermission | ||
mesh: mesh-1 | ||
name: mtp-1 | ||
spec: | ||
targetRef: | ||
kind: Dataplane | ||
labels: | ||
app: demo | ||
from: | ||
- targetRef: | ||
kind: Mesh | ||
default: | ||
action: Deny | ||
--- | ||
type: MeshTrafficPermission | ||
mesh: mesh-1 | ||
name: mtp-2 | ||
spec: | ||
targetRef: | ||
kind: Dataplane | ||
labels: | ||
app: test | ||
from: | ||
- targetRef: | ||
kind: Mesh | ||
default: | ||
action: Allow |
14 changes: 14 additions & 0 deletions
14
...ers/testdata/matchedpolicies/dataplanepolicies/dataplane-targetref-by-name.dataplane.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
type: Dataplane | ||
mesh: mesh-1 | ||
name: dp-1 | ||
networking: | ||
address: 1.1.1.1 | ||
inbound: | ||
- port: 8080 | ||
tags: | ||
kuma.io/service: web | ||
version: v1 | ||
- port: 8081 | ||
tags: | ||
kuma.io/service: web | ||
version: v3 |
17 changes: 17 additions & 0 deletions
17
...tchers/testdata/matchedpolicies/dataplanepolicies/dataplane-targetref-by-name.golden.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
items: | ||
- creationTime: "0001-01-01T00:00:00Z" | ||
mesh: mesh-1 | ||
modificationTime: "0001-01-01T00:00:00Z" | ||
name: mtp-1 | ||
spec: | ||
from: | ||
- default: | ||
action: Deny | ||
targetRef: | ||
kind: Mesh | ||
targetRef: | ||
kind: Dataplane | ||
name: dp-1 | ||
type: MeshTrafficPermission | ||
next: null | ||
total: 0 |
26 changes: 26 additions & 0 deletions
26
...hers/testdata/matchedpolicies/dataplanepolicies/dataplane-targetref-by-name.policies.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# 01. policies using kind Dataplane selecting Dataplanes by labels | ||
type: MeshTrafficPermission | ||
mesh: mesh-1 | ||
name: mtp-1 | ||
spec: | ||
targetRef: | ||
kind: Dataplane | ||
name: dp-1 | ||
from: | ||
- targetRef: | ||
kind: Mesh | ||
default: | ||
action: Deny | ||
--- | ||
type: MeshTrafficPermission | ||
mesh: mesh-1 | ||
name: mtp-2 | ||
spec: | ||
targetRef: | ||
kind: Dataplane | ||
name: dp-2 | ||
from: | ||
- targetRef: | ||
kind: Mesh | ||
default: | ||
action: Allow |
16 changes: 16 additions & 0 deletions
16
...ies/core/matchers/testdata/matchedpolicies/fromrules/select-single-inbound.dataplane.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
type: Dataplane | ||
mesh: mesh-1 | ||
name: dp-1 | ||
networking: | ||
address: 1.1.1.1 | ||
inbound: | ||
- port: 8080 | ||
name: main-port | ||
tags: | ||
kuma.io/service: web | ||
version: v1 | ||
- port: 8081 | ||
name: secondary-port | ||
tags: | ||
kuma.io/service: web | ||
version: v3 |
39 changes: 39 additions & 0 deletions
39
...licies/core/matchers/testdata/matchedpolicies/fromrules/select-single-inbound.golden.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
Rules: | ||
1.1.1.1:8080: | ||
- BackendRefOriginIndex: {} | ||
Conf: | ||
action: AllowWithShadowDeny | ||
Origin: | ||
- creationTime: "0001-01-01T00:00:00Z" | ||
mesh: mesh-1 | ||
modificationTime: "0001-01-01T00:00:00Z" | ||
name: mtp-1 | ||
type: MeshTrafficPermission | ||
Subset: | ||
- Key: kuma.io/service | ||
Not: false | ||
Value: orders | ||
- BackendRefOriginIndex: {} | ||
Conf: | ||
action: Allow | ||
Origin: | ||
- creationTime: "0001-01-01T00:00:00Z" | ||
mesh: mesh-1 | ||
modificationTime: "0001-01-01T00:00:00Z" | ||
name: mtp-1 | ||
type: MeshTrafficPermission | ||
Subset: | ||
- Key: kuma.io/service | ||
Not: true | ||
Value: orders | ||
1.1.1.1:8081: | ||
- BackendRefOriginIndex: {} | ||
Conf: | ||
action: Deny | ||
Origin: | ||
- creationTime: "0001-01-01T00:00:00Z" | ||
mesh: mesh-1 | ||
modificationTime: "0001-01-01T00:00:00Z" | ||
name: mtp-1 | ||
type: MeshTrafficPermission | ||
Subset: [] |
32 changes: 32 additions & 0 deletions
32
...cies/core/matchers/testdata/matchedpolicies/fromrules/select-single-inbound.policies.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
type: MeshTrafficPermission | ||
mesh: mesh-1 | ||
name: mtp-1 | ||
spec: | ||
targetRef: | ||
kind: Dataplane | ||
name: dp-1 | ||
sectionName: main-port | ||
from: | ||
- targetRef: | ||
kind: Mesh | ||
default: | ||
action: Allow | ||
- targetRef: | ||
kind: MeshService | ||
name: orders | ||
default: | ||
action: AllowWithShadowDeny | ||
--- | ||
type: MeshTrafficPermission | ||
mesh: mesh-1 | ||
name: mtp-1 | ||
spec: | ||
targetRef: | ||
kind: Dataplane | ||
name: dp-1 | ||
sectionName: secondary-port | ||
from: | ||
- targetRef: | ||
kind: Mesh | ||
default: | ||
action: Deny |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I extracted the function that resolves targetRefs to
rules_common
package, I think it should be possible to use it for DPPs as it exactly the same approach (the change is not inmaster
yet):kuma/pkg/plugins/policies/core/rules/common/resolvetargetref.go
Line 33 in 5c48b20