1- # NPEP-126: Add northbound traffic support in (B)ANP API
1+ # NPEP-126: Add northbound traffic support in ClusterNetworkPolicy API
22
33* Issue: [ #126 ] ( https://github.com/kubernetes-sigs/network-policy-api/issues/126 )
44* Status: Experimental
55
66## TLDR
77
88This NPEP proposes adding support for cluster egress (northbound) traffic control
9- in the ` AdminNetworkPolicy ` and ` BaselineAdminNetworkPolicy ` API objects .
9+ in the ` ClusterNetworkPolicy ` API object .
1010
1111## Goals
1212
@@ -15,9 +15,9 @@ in the `AdminNetworkPolicy` and `BaselineAdminNetworkPolicy` API objects.
1515 - Currently the behaviour for policies defined around traffic from cluster
1616 workloads (non-hostNetworked pods) towards nodes in the
1717 cluster is undefined. See https://github.com/kubernetes-sigs/network-policy-api/issues/73 .
18- - ANP currently supports only east-west traffic and this traffic flow cuts from
18+ - KCNP currently supports only east-west traffic and this traffic flow cuts from
1919 overlay to underlay which makes this part of the egress (northbound) use case.
20- - Let's provide a defined behaviour in ANP to explicitly achieve the use case.
20+ - Let's provide a defined behaviour in KCNP to explicitly achieve the use case.
2121 - NOTE: Traffic towards nodes here includes traffic towards host-networked pods on that node
2222 because a "node" resource encompasses all objects that share the host-networking resources
2323* Implement egress traffic control towards k8s-apiservers
@@ -32,10 +32,10 @@ in the `AdminNetworkPolicy` and `BaselineAdminNetworkPolicy` API objects.
3232 - Currently the behaviour for policies defined around traffic from cluster
3333 workloads (non-hostNetworked pods) towards hostNetworked pods in the
3434 cluster is undefined. See https://github.com/kubernetes-sigs/network-policy-api/issues/73 .
35- - ANP currently supports only east-west traffic and this traffic flow cuts from
35+ - KCNP currently supports only east-west traffic and this traffic flow cuts from
3636 overlay to underlay which makes this part of the egress (northbound) use case.
3737 - NOTE: Currently there are no user stories for ` CNI pod to arbitrarily chosen hostNetworked pods ` .
38- Let's provide a defined behaviour in ANP to explicitly achieve the use case in the future if we have
38+ Let's provide a defined behaviour in KCNP to explicitly achieve the use case in the future if we have
3939 user stories for this outside of the k8s-apiserver usecase which is already covered in the goals.
4040 If that happens, this can be moved to goals.
4141
@@ -83,21 +83,21 @@ Proof of Concept for the API design details can be found here:
8383
8484### Implementing egress traffic control towards cluster nodes
8585
86- This NPEP proposes to add a new type of ` AdminNetworkPolicyEgressPeer ` called ` Nodes `
86+ This NPEP proposes to add a new type of ` ClusterNetworkPolicyEgressPeer ` called ` Nodes `
8787to be able to explicitly select nodes (based on the node's labels) in the cluster.
8888This ensures that if the list of IPs on a node OR list of nodes change, the users
8989don't need to manually intervene to include those new IPs. The label selectors will
9090take care of this automatically. Note that the nodeIPs that this type of peer matches
9191on are the IPs present in ` Node.Status.Addresses ` field of the node.
9292
9393```
94- // AdminNetworkPolicyEgressPeer defines a peer to allow traffic to.
94+ // ClusterNetworkPolicyEgressPeer defines a peer to allow traffic to.
9595// Exactly one of the selector pointers must be set for a given peer. If a
9696// consumer observes none of its fields are set, they must assume an unknown
9797// option has been specified and fail closed.
9898// +kubebuilder:validation:MaxProperties=1
9999// +kubebuilder:validation:MinProperties=1
100- type AdminNetworkPolicyEgressPeer struct {
100+ type ClusterNetworkPolicyEgressPeer struct {
101101 <snipped>
102102 // Nodes defines a way to select a set of nodes in
103103 // in the cluster. This field follows standard label selector
@@ -108,23 +108,18 @@ type AdminNetworkPolicyEgressPeer struct {
108108}
109109```
110110
111- Note that ` AdminNetworkPolicyPeer ` will be changed to
112- ` AdminNetworkPolicyEgressPeer ` and ` AdminNetworkPolicyIngressPeer ` since ingress and
113- egress peers have started to diverge at this point and it is easy to
114- maintain it with two sets of peer definitions.
115- This ensures nodes can be referred to only as "egress peers".
116-
117111Example: Admin wants to deny egress traffic from tenants who don't have
118112` restricted ` , ` confidential ` or ` internal ` level security clearance
119113to control-plane nodes at 443 and 6443 ports in the cluster
120114
121115```
122116apiVersion: policy.networking.k8s.io/v1alpha1
123- kind: AdminNetworkPolicy
117+ kind: ClusterNetworkPolicy
124118metadata:
125119 name: node-as-egress-peer
126120spec:
127121 priority: 55
122+ tier: Admin
128123 subject:
129124 namespaces:
130125 matchExpressions:
@@ -136,30 +131,30 @@ spec:
136131 - nodes:
137132 matchLabels:
138133 node-role.kubernetes.io/control-plane:
139- ports :
140- - portNumber :
141- protocol: TCP
142- port : 443
143- - portNumber :
144- protocol: TCP
145- port : 6443
134+ protocols :
135+ - tcp :
136+ destinationPort:
137+ number : 443
138+ - tcp :
139+ destinationPort:
140+ number : 6443
146141```
147142
148143### Implementing egress traffic control towards CIDRs
149144
150- This NPEP proposes to add a new type of ` AdminNetworkPolicyEgressPeer ` called ` Networks `
145+ This NPEP proposes to add a new type of ` ClusterNetworkPolicyEgressPeer ` called ` Networks `
151146to be able to select destination CIDRs. This is provided to be able to select entities
152147outside the cluster that cannot be selected using the other peer types.
153- This peer type will not be supported in ` AdminNetworkPolicyIngressPeer ` .
148+ This peer type will not be supported in ` ClusterNetworkPolicyIngressPeer ` .
154149
155150```
156- // AdminNetworkPolicyEgressPeer defines a peer to allow traffic to.
151+ // ClusterNetworkPolicyEgressPeer defines a peer to allow traffic to.
157152// Exactly one of the selector pointers must be set for a given peer. If a
158153// consumer observes none of its fields are set, they must assume an unknown
159154// option has been specified and fail closed.
160155// +kubebuilder:validation:MaxProperties=1
161156// +kubebuilder:validation:MinProperties=1
162- type AdminNetworkPolicyEgressPeer struct {
157+ type ClusterNetworkPolicyEgressPeer struct {
163158 <snipped>
164159 // Networks defines a way to select peers via CIDR blocks. This is
165160 // intended for representing entities that live outside the cluster,
@@ -187,11 +182,12 @@ destination.
187182Example: Let's define ANP and BANP that refer to some CIDR networks:
188183```
189184apiVersion: policy.networking.k8s.io/v1alpha1
190- kind: AdminNetworkPolicy
185+ kind: ClusterNetworkPolicy
191186metadata:
192187 name: network-as-egress-peer
193188spec:
194189 priority: 70
190+ tier: Admin
195191 subject:
196192 namespaces: {}
197193 egress:
@@ -202,10 +198,10 @@ spec:
202198 - 194.0.2.0/24
203199 - 205.0.113.15/32
204200 - 199.51.100.10/32
205- ports :
206- - portNumber :
207- protocol: UDP
208- port : 53
201+ protocols :
202+ - udp :
203+ destinationPort:
204+ number : 53
209205 - name: "allow-all-egress-to-intranet"
210206 action: "Allow"
211207 to:
@@ -227,10 +223,11 @@ spec:
227223 - 0.0.0.0/0
228224---
229225apiVersion: policy.networking.k8s.io/v1alpha1
230- kind: BaselineAdminNetworkPolicy
226+ kind: ClusterNetworkPolicy
231227metadata:
232228 name: default
233229spec:
230+ tier: Baseline
234231 subject:
235232 namespaces: {}
236233 egress:
@@ -251,17 +248,16 @@ This allows admins to specify rules that define:
251248
252249* Instead of adding CIDR peer directly into the main object, we can
253250define a new object called ` NetworkSet ` and use selectors or
254- name of that object to be referred to from AdminNetworkPolicy and
255- BaselineAdminNetworkPolicy objects. This is particularly useful
256- if CIDR ranges are prone to changes versus the current model is
257- is better if the set of CIDRs are mostly a constant and are only referred
258- to from one or two egress rules. It increases readability. However the
259- drawback is if the CIDRs do change, then one has to ensure to update all
260- the relevant ANPs and BANP accordingly. In order to see whether we need
261- a new object to be able to define CIDRs in addition to the in-line peer,
262- we have another NPEP where that is being discussed
263- https://github.com/kubernetes-sigs/network-policy-api/pull/183 . The scope
264- of this NPEP is limited to inline CIDR peers.
251+ name of that object to be referred to from the ClusterNetworkPolicy
252+ object. This is particularly useful if CIDR ranges are prone to changes
253+ versus the current model is is better if the set of CIDRs are mostly a
254+ constant and are only referred to from one or two egress rules. It
255+ increases readability. However the drawback is if the CIDRs do change,
256+ then one has to ensure to update all the relevant KCNPs accordingly.
257+ In order to see whether we need a new object to be able to define CIDRs
258+ in addition to the in-line peer, we have another NPEP where that is being
259+ discussed https://github.com/kubernetes-sigs/network-policy-api/pull/183 .
260+ The scope of this NPEP is limited to inline CIDR peers.
265261
266262## References
267263
0 commit comments