Skip to content

Commit 7c58e37

Browse files
committed
Drop exception proposal and move to endport
Signed-off-by: Ricardo Pchevuzinske Katz <[email protected]>
1 parent 2710f62 commit 7c58e37

File tree

2 files changed

+51
-102
lines changed

2 files changed

+51
-102
lines changed

keps/sig-network/2079-network-policy-port-range/README.md

Lines changed: 50 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -90,27 +90,23 @@ So for the user:
9090
``ports`` array
9191
* To make an exception needs a declaration of all ports but the exception
9292

93-
Adding a new ``PortRange`` field inside the ``ports`` will allow a simpler
93+
Adding a new ``endPort`` field inside the ``ports`` will allow a simpler
9494
creation of NetworkPolicy to the user.
9595

9696
### Goals
9797

98-
Add Port Range field in a NetworkPolicy
98+
Add an endPort field in ``NetworkPolicyPort``
9999

100100
### Non-Goals
101101

102-
N/A
102+
* Support specific ``Exception`` field.
103+
* Support ``endPort`` when the starting ``port`` is a named port.
103104

104105
## Proposal
105106

106-
In NetworkPolicy specification, inside ``NetworkPolicyIngressRule`` and
107-
``NetworkPolicyEgressRule`` object struct specify a new ``PortRanges`` field
108-
composed of the minimum and maximum ports inside the range, and the exceptions
109-
within this range.
110-
111-
If both ``Port`` and ``Range`` are specified, they are cumulative and no further
112-
validation might occur. It's up to the CNI to summarize both of the fields in a
113-
single rule.
107+
In NetworkPolicy specification, inside ``NetworkPolicyPort`` specify a new
108+
``endPort`` field composed of a numbered port that defines if this is a range
109+
and when it ends.
114110

115111
### User Stories
116112

@@ -132,7 +128,7 @@ I can be compliant with the company's policy.
132128
#### Story 3 - Containerized Passive FTP Server
133129
As a Kubernetes User, I've received a demand from my boss to run our FTP server in an
134130
existing Kubernetes cluster, to support some of my legacy applications.
135-
his FTP Server must be acessible from inside the cluster and outside the cluster,
131+
This FTP Server must be acessible from inside the cluster and outside the cluster,
136132
but I still need to keep the basic security policies from my company, that demands
137133
the existence of a default deny rule for all workloads and allowing only specific ports.
138134

@@ -154,95 +150,31 @@ of the new field.
154150
## Design Details
155151

156152
API changes to NetworkPolicy:
157-
* Add a new struct called ``NetworkPolicyPortRange`` as the following:
153+
* Add a new field called ``EndPort`` inside ``NetworkPolicyPort`` as the following:
158154
```
159-
// NetworkPolicyPortRange describes the range of ports to be used in a
160-
// NetworkPolicyPort struct
161-
type NetworkPolicyPortRange struct {
162-
// From defines the start of the port range
163-
From uint16
164-
165-
// To defines the end of the port range, being the end included within the
166-
// range
167-
To uint16
168-
169-
// Except defines all the exceptions in the port range
170-
+optional
171-
Except []uint16
172-
}
173-
```
174-
* Add a new field ``PortRanges`` that defines an array of
175-
``NetworkPolicyPortRange`` in both ``NetworkPolicyIngressRule`` and
176-
``NetworkPolicyEgressRule``
177-
178-
```
179-
// NetworkPolicyIngressRule describes a particular set of traffic that is allowed to the pods
180-
// matched by a NetworkPolicySpec's podSelector. The traffic must match both ports and from.
181-
type NetworkPolicyIngressRule struct {
182-
// List of ports which should be made accessible on the pods selected for this
183-
// rule. Each item in this list is combined using a logical OR. If this field is
184-
// empty or missing, this rule matches all ports (traffic not restricted by port).
185-
// If this field is present and contains at least one item, then this rule allows
186-
// traffic only if the traffic matches at least one port in the list.
187-
// +optional
188-
Ports []NetworkPolicyPort
189-
190-
// List of sources which should be able to access the pods selected for this rule.
191-
// Items in this list are combined using a logical OR operation. If this field is
192-
// empty or missing, this rule matches all sources (traffic not restricted by
193-
// source). If this field is present and contains at least one item, this rule
194-
// allows traffic only if the traffic matches at least one item in the from list.
195-
// +optional
196-
From []NetworkPolicyPeer
197-
198-
// List of port ranges which should be made accessible on the pods selected for this
199-
// rule. Each item in this list is combined using a logical OR. If this field is
200-
// empty or missing, AND the Ports field is also empty or missing,
201-
// this rule matches all ports (traffic not restricted by port).
202-
// If this field is present and contains at least one item, then this rule allows
203-
// traffic only if the traffic matches at least one port in the list.
204-
// +optional
205-
PortRanges []NetworkPolicyPortRange
206-
}
207-
208-
// NetworkPolicyEgressRule describes a particular set of traffic that is allowed out of pods
209-
// matched by a NetworkPolicySpec's podSelector. The traffic must match both ports and to.
210-
// This type is beta-level in 1.8
211-
type NetworkPolicyEgressRule struct {
212-
// List of destination ports for outgoing traffic.
213-
// Each item in this list is combined using a logical OR. If this field is
214-
// empty or missing, this rule matches all ports (traffic not restricted by port).
215-
// If this field is present and contains at least one item, then this rule allows
216-
// traffic only if the traffic matches at least one port in the list.
155+
// NetworkPolicyPort describes a port to allow traffic on
156+
type NetworkPolicyPort struct {
157+
// The protocol (TCP, UDP, or SCTP) which traffic must match. If not specified, this
158+
// field defaults to TCP.
217159
// +optional
218-
Ports []NetworkPolicyPort
160+
Protocol *v1.Protocol `json:"protocol,omitempty" protobuf:"bytes,1,opt,name=protocol,casttype=k8s.io/api/core/v1.Protocol"`
219161
220-
// List of destinations for outgoing traffic of pods selected for this rule.
221-
// Items in this list are combined using a logical OR operation. If this field is
222-
// empty or missing, this rule matches all destinations (traffic not restricted by
223-
// destination). If this field is present and contains at least one item, this rule
224-
// allows traffic only if the traffic matches at least one item in the to list.
225-
// +optional
226-
To []NetworkPolicyPeer
227-
228-
// List of destination port ranges for outgoing traffic.
229-
// Each item in this list is combined using a logical OR. If this field is
230-
// empty or missing AND the Ports field is also empty or missing,
231-
// this rule matches all ports (traffic not restricted by port).
232-
// If this field is present and contains at least one item, then this rule allows
233-
// traffic only if the traffic matches at least one port inside this range.
162+
// The port on the given protocol. This can either be a numerical or named port on
163+
// a pod. If this field is not provided, this matches all port names and numbers.
234164
// +optional
235-
PortRanges []NetworkPolicyPortRange
165+
Port *intstr.IntOrString `json:"port,omitempty" protobuf:"bytes,2,opt,name=port"`
236166
167+
// To defines the end of the port range, being the end included within the
168+
// range
169+
// +optional
170+
EndPort uint16 `json:"port,omitempty" protobuf:"bytes,2,opt,name=endPort"`
237171
}
238172
```
239173

240174
### Validations
241-
The range will need to be validated, with the following scenarios:
242-
* ``From`` needs to be less than or equal to ``To``
243-
* All the ports in the ``Except`` array must be inside the defined range.
244-
* If ``PortRange`` is defined but no ``Ports`` is defined, the old behavior of
245-
matching all Ports should be changed to match only PortRange ports.
175+
The ``NetworkPolicyPort`` will need to be validated, with the following scenarios:
176+
* If an ``EndPort`` is specified a ``Port`` must also be specified
177+
* If ``Port`` is a string ``EndPort`` cannot be specified
246178

247179
### Test Plan
248180

@@ -263,15 +195,15 @@ validation should be done by CNIs.
263195
- Add validation tests in API
264196

265197
#### Beta
266-
- ``PortRanges`` has been supported for at least 1 minor release
198+
- ``EndPort`` has been supported for at least 1 minor release
267199
- Four commonly used NetworkPolicy (or CNI providers) implement the new field,
268200
with generally positive feedback on its usage.
269201
- Feature Gate is enabled by Default.
270202

271203
#### GA Graduation
272204

273-
- At least **four** NetworkPolicy providers (or CNI providers) support the ``PortRanges`` field
274-
- ``PortRanges`` has been enabled by default for at least 1 minor release
205+
- At least **four** NetworkPolicy providers (or CNI providers) support the ``EndPort`` field
206+
- ``EndPort`` has been enabled by default for at least 1 minor release
275207

276208
### Upgrade / Downgrade Strategy
277209

@@ -289,7 +221,7 @@ _This section must be completed when targeting alpha to a release._
289221

290222
* **How can this feature be enabled / disabled in a live cluster?**
291223
- [X] Feature gate (also fill in values in `kep.yaml`)
292-
- Feature gate name: NetworkPolicyPortRange
224+
- Feature gate name: NetworkPolicyEndPort
293225
- Components depending on the feature gate: Kubernetes API Server
294226

295227
* **Does enabling the feature change any default behavior?**
@@ -313,7 +245,7 @@ _This section must be completed when targeting beta graduation to a release._
313245

314246
* **How can an operator determine if the feature is in use by workloads?**
315247

316-
Operators can determine if NetworkPolicies are making use of Range creating
248+
Operators can determine if NetworkPolicies are making use of EndPort creating
317249
an object specifying the range and validating if the traffic is allowed within
318250
the specified range
319251

@@ -350,7 +282,7 @@ previous answers based on experience in the field._
350282
TBD
351283

352284
* **Will enabling / using this feature result in introducing new API types?**
353-
No, unless the new ``NetworkPolicyPortRange`` is considered a new API type
285+
No, unless the new ``EndPort`` is considered a new API type
354286

355287
* **Will enabling / using this feature result in any new calls to the cloud
356288
provider?**
@@ -359,9 +291,8 @@ provider?**
359291
* **Will enabling / using this feature result in increasing size or count of
360292
the existing API objects?**
361293

362-
- API type(s): NetworkPolicy / NetworkPolicyPorts
363-
- Estimated increase in size: New struct inside the object with two fields of
364-
16 bits each + 16 bits for each port in the ``Except`` array
294+
- API type(s): NetworkPolicyPorts
295+
- Estimated increase in size: 2 bytes for each new ``EndPort`` specified
365296
- Estimated amount of new objects: N/A
366297

367298
* **Will enabling / using this feature result in increasing time taken by any
@@ -432,3 +363,21 @@ type NetworkPolicyPort struct {
432363
But the main design suggested in this Kep seems more clear, so this alternative
433364
has been discarded.
434365

366+
Also it has been proposed that the implementation contains an ``Except``` array and a new
367+
struct to be used in Ingress/Egress rules, but because it would bring much more complexity
368+
than desired the proposal has been dropped right now:
369+
370+
```
371+
// NetworkPolicyPortRange describes the range of ports to be used in a
372+
// NetworkPolicyPort struct
373+
type NetworkPolicyPortRange struct {
374+
// From defines the start of the port range
375+
From uint16
376+
377+
// To defines the end of the port range, being the end included within the
378+
// range
379+
To uint16
380+
// Except defines all the exceptions in the port range
381+
+optional
382+
Except []uint16
383+
```

keps/sig-network/2079-network-policy-port-range/kep.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ milestone:
2929
# The following PRR answers are required at alpha release
3030
# List the feature gate name and the components for which it must be enabled
3131
feature-gates:
32-
- name: NetworkPolicyPortRange
32+
- name: NetworkPolicyEndPort
3333
components:
3434
- kube-apiserver
3535
disable-supported: true

0 commit comments

Comments
 (0)