Skip to content

Commit b109128

Browse files
authored
Merge pull request #363 from TheBeeZee/pr-ports-doc-update
Update docs to match port/protocol schema changes in v1alpha2
2 parents 4c0c9a6 + abc9f64 commit b109128

7 files changed

Lines changed: 172 additions & 154 deletions

npeps/npep-126-egress-traffic-control.md

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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

88
This 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`
8787
to be able to explicitly select nodes (based on the node's labels) in the cluster.
8888
This ensures that if the list of IPs on a node OR list of nodes change, the users
8989
don't need to manually intervene to include those new IPs. The label selectors will
9090
take care of this automatically. Note that the nodeIPs that this type of peer matches
9191
on 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-
117111
Example: Admin wants to deny egress traffic from tenants who don't have
118112
`restricted`, `confidential` or `internal` level security clearance
119113
to control-plane nodes at 443 and 6443 ports in the cluster
120114

121115
```
122116
apiVersion: policy.networking.k8s.io/v1alpha1
123-
kind: AdminNetworkPolicy
117+
kind: ClusterNetworkPolicy
124118
metadata:
125119
name: node-as-egress-peer
126120
spec:
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`
151146
to be able to select destination CIDRs. This is provided to be able to select entities
152147
outside 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.
187182
Example: Let's define ANP and BANP that refer to some CIDR networks:
188183
```
189184
apiVersion: policy.networking.k8s.io/v1alpha1
190-
kind: AdminNetworkPolicy
185+
kind: ClusterNetworkPolicy
191186
metadata:
192187
name: network-as-egress-peer
193188
spec:
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
---
229225
apiVersion: policy.networking.k8s.io/v1alpha1
230-
kind: BaselineAdminNetworkPolicy
226+
kind: ClusterNetworkPolicy
231227
metadata:
232228
name: default
233229
spec:
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
253250
define 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

npeps/npep-133-fqdn-egress-selector.md

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,21 @@ Names](https://www.wikipedia.org/wiki/Fully_qualified_domain_name) (FQDNs).
2929
belong to the domain. While this is definitely undesirable, it is at least
3030
not an unsafe failure.
3131

32-
* Currently only AdminNetworkPolicy is the intended scope for this proposal.
32+
* Currently only Admin tier of ClusterNetworkPolicy is the intended scope for this
33+
proposal.
3334
* Since Kubernetes NetworkPolicy does not have a FQDN selector, adding this
34-
capability to BaselineAdminNetworkPolicy could result in writing baseline
35-
rules that can't be replicated by an overriding NetworkPolicy. For example,
36-
if BANP allows traffic to `example.io`, but the namespace admin installs a
37-
Kubernetes Network Policy, the namespace admin has no way to replicate the
38-
`example.io` selector using just Kubernetes Network Policies.
35+
capability to Baseline tier could result in writing baseline rules that can't
36+
be replicated by an overriding NetworkPolicy. For example, if Baseline tier
37+
allows traffic to `example.io`, but the namespace admin installs a Kubernetes
38+
Network Policy, the namespace admin has no way to replicate the `example.io`
39+
selector using just Kubernetes Network Policies.
3940

4041
## Non-Goals
4142

4243
* This enhancement does not include a FQDN selector for allowing ingress
4344
traffic.
4445
* This enhancement only describes enhancements to the existing L4 filtering as
45-
provided by AdminNetworkPolicy. It does not propose any new L7 matching or
46+
provided by ClusterNetworkPolicy. It does not propose any new L7 matching or
4647
filtering capabilities, like matching HTTP traffic or URL paths.
4748
* This selector should not control what DNS records are resolvable from a
4849
particular workload.
@@ -81,7 +82,7 @@ hampers the readability of the network policies.
8182
* As a cluster admin, I want to allow Pods in the cluster to send traffic to a
8283
entire tree of domains. For example, our CDN has domains of the format
8384
`<session>.<random>.<region>.my-app.cdn.com`. I want to be able to use a
84-
wild-card selector toallow the full tree of subdomains below
85+
wild-card selector to allow the full tree of subdomains below
8586
`**.my-app.cdn.com`.
8687

8788
### Future User Stories
@@ -92,14 +93,14 @@ goal in this case is to ensure we do not make these unimplementable down the
9293
line.
9394

9495
* As a cluster admin, I want to switch the default disposition of the cluster to
95-
be default deny. This is enforced using a `BaselineAdminNetworkPolicy`. I also
96-
want individual namespace owners to be able to specify their egress peers.
96+
be default deny. This is enforced using a `Baseline` tier in ClusterNetworkPolicy`.
97+
I also want individual namespace owners to be able to specify their egress peers.
9798
Namespace admins would then use a FQDN selector in the Kubernetes
9899
`NetworkPolicy` objects to allow `my-service.com`.
99100

100101
## API
101102

102-
This NPEP proposes adding a new type of `AdminNetworkPolicyEgressPeer` called
103+
This NPEP proposes adding a new type of `ClusterNetworkPolicyEgressPeer` called
103104
`FQDNPeerSelector` which allows specifying domain names.
104105

105106
```golang
@@ -126,7 +127,7 @@ This NPEP proposes adding a new type of `AdminNetworkPolicyEgressPeer` called
126127
// +kubebuilder:validation:Pattern=`^(\*\.)?([a-zA-z0-9]([-a-zA-Z0-9_]*[a-zA-Z0-9])?\.)+[a-zA-z0-9]([-a-zA-Z0-9_]*[a-zA-Z0-9])?\.?$`
127128
type DomainName string
128129

129-
type AdminNetworkPolicyEgressPeer struct {
130+
type ClusterNetworkPolicyEgressPeer struct {
130131
<snipped>
131132
// DomainNames provides a way to specify domain names as peers.
132133
//
@@ -151,11 +152,12 @@ type AdminNetworkPolicyEgressPeer struct {
151152

152153
```yaml
153154
apiVersion: policy.networking.k8s.io/v1alpha1
154-
kind: AdminNetworkPolicy
155+
kind: ClusterNetworkPolicy
155156
metadata:
156157
name: allow-my-service-egress
157158
spec:
158159
priority: 55
160+
tier: Admin
159161
subject:
160162
namespaces:
161163
matchLabels:
@@ -167,10 +169,10 @@ spec:
167169
- domainNames:
168170
- "my-service.com"
169171
- "*.cloud-provider.io"
170-
ports:
171-
- portNumber:
172-
protocol: TCP
173-
port: 443
172+
protocols:
173+
- tcp:
174+
destinationPort:
175+
number: 443
174176
```
175177
176178
#### Maintaining an allowlist of domains
@@ -181,11 +183,12 @@ This example, includes the DENY rule in the same ANP object. It's also possible
181183
to use another ANP object with a lower priority (e.g. `100` in this example):
182184
```yaml
183185
apiVersion: policy.networking.k8s.io/v1alpha1
184-
kind: AdminNetworkPolicy
186+
kind: ClusterNetworkPolicy
185187
metadata:
186188
name: allow-my-service-egress
187189
spec:
188190
priority: 55
191+
tier: Admin
189192
subject:
190193
namespaces:
191194
matchLabels:
@@ -197,26 +200,27 @@ spec:
197200
- domainNames:
198201
- "my-service.com"
199202
- "*.cloud-provider.io"
200-
ports:
201-
- portNumber:
202-
protocol: TCP
203-
port: 443
203+
protocols:
204+
- tcp:
205+
destinationPort:
206+
number: 443
204207
- name: "default-deny"
205208
action: "Deny"
206209
to:
207210
- networks:
208211
- "0.0.0.0/0"
209212
```
210213

211-
This example uses a default-deny BaselineAdminNetworkPolicy to create the
214+
This example uses a default-deny Baseline ClusterNetworkPolicy to create the
212215
allowlist:
213216
```yaml
214217
apiVersion: policy.networking.k8s.io/v1alpha1
215-
kind: AdminNetworkPolicy
218+
kind: ClusterNetworkPolicy
216219
metadata:
217220
name: allow-my-service-egress
218221
spec:
219222
priority: 55
223+
tier: Admin
220224
subject:
221225
namespaces:
222226
matchLabels:
@@ -228,16 +232,17 @@ spec:
228232
- domainNames:
229233
- "my-service.com"
230234
- "*.cloud-provider.io"
231-
ports:
232-
- portNumber:
233-
protocol: TCP
234-
port: 443
235+
protocols:
236+
- tcp:
237+
destinationPort:
238+
number: 443
235239
---
236240
apiVersion: policy.networking.k8s.io/v1alpha1
237-
kind: BaselineAdminNetworkPolicy
241+
kind: ClusterNetworkPolicy
238242
metadata:
239243
name: default
240244
spec:
245+
tier: Baseline
241246
subject:
242247
namespaces: {}
243248
ingress:

site-src/api-overview.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,20 @@ before policies with higher priority values in the same tier.
121121
Each CNP should define at least one `Ingress` or `Egress` relevant in-cluster traffic flow
122122
along with the associated Action that should occur. In each `gress` rule the user
123123
should AT THE MINIMUM define an `Action`, and at least one `ClusterNetworkPolicyPeer`.
124-
Optionally the user may also define select `Ports` to filter traffic on and also
124+
Optionally the user may also define select `Protocols` to filter traffic on and also
125125
a name for each rule to make management and reporting easier for Admins.
126126

127+
Within the `Protocols` array, `TCP`, `UDP`, or `SCTP` protocols can be specified, each with an
128+
optional `DestinationPort`. The `DestinationPort` can be a single `Number` or a `Range`
129+
with a `Start` and `End`. If `DestinationPort` is omitted, all ports for the specified
130+
protocol match.
131+
132+
Alternatively, `DestinationNamedPort` can be used to target a port by name. A named port is
133+
defined directly within the ports section of the `Pod` or `Deployment` container spec by assigning
134+
a string to the name field alongside the containerPort. Existing named ports can be located by
135+
inspecting the resource's YAML under `spec.containers[].ports` or by running `kubectl get pod <pod-name> -o jsonpath='{.spec.containers[*].ports[*].name}'`. Using a name instead of a number allows the ClusterNetworkPolicy to remain valid even
136+
if the container’s underlying port number is updated.
137+
127138
### Status
128139

129140
For `v1alpha2` of this API the ANP status field is simply defined as a list of

0 commit comments

Comments
 (0)