@@ -90,27 +90,23 @@ So for the user:
90
90
`` ports `` array
91
91
* To make an exception needs a declaration of all ports but the exception
92
92
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
94
94
creation of NetworkPolicy to the user.
95
95
96
96
### Goals
97
97
98
- Add Port Range field in a NetworkPolicy
98
+ Add an endPort field in `` NetworkPolicyPort ``
99
99
100
100
### Non-Goals
101
101
102
- N/A
102
+ * Support specific `` Exception `` field.
103
+ * Support `` endPort `` when the starting `` port `` is a named port.
103
104
104
105
## Proposal
105
106
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.
114
110
115
111
### User Stories
116
112
@@ -132,7 +128,7 @@ I can be compliant with the company's policy.
132
128
#### Story 3 - Containerized Passive FTP Server
133
129
As a Kubernetes User, I've received a demand from my boss to run our FTP server in an
134
130
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,
136
132
but I still need to keep the basic security policies from my company, that demands
137
133
the existence of a default deny rule for all workloads and allowing only specific ports.
138
134
@@ -154,95 +150,31 @@ of the new field.
154
150
## Design Details
155
151
156
152
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:
158
154
```
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.
217
159
// +optional
218
- Ports []NetworkPolicyPort
160
+ Protocol *v1.Protocol `json:"protocol,omitempty" protobuf:"bytes,1,opt,name=protocol,casttype=k8s.io/api/core/v1.Protocol"`
219
161
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.
234
164
// +optional
235
- PortRanges []NetworkPolicyPortRange
165
+ Port *intstr.IntOrString `json:"port,omitempty" protobuf:"bytes,2,opt,name=port"`
236
166
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"`
237
171
}
238
172
```
239
173
240
174
### 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
246
178
247
179
### Test Plan
248
180
@@ -263,15 +195,15 @@ validation should be done by CNIs.
263
195
- Add validation tests in API
264
196
265
197
#### Beta
266
- - `` PortRanges `` has been supported for at least 1 minor release
198
+ - `` EndPort `` has been supported for at least 1 minor release
267
199
- Four commonly used NetworkPolicy (or CNI providers) implement the new field,
268
200
with generally positive feedback on its usage.
269
201
- Feature Gate is enabled by Default.
270
202
271
203
#### GA Graduation
272
204
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
275
207
276
208
### Upgrade / Downgrade Strategy
277
209
@@ -289,7 +221,7 @@ _This section must be completed when targeting alpha to a release._
289
221
290
222
* ** How can this feature be enabled / disabled in a live cluster?**
291
223
- [X] Feature gate (also fill in values in ` kep.yaml ` )
292
- - Feature gate name: NetworkPolicyPortRange
224
+ - Feature gate name: NetworkPolicyEndPort
293
225
- Components depending on the feature gate: Kubernetes API Server
294
226
295
227
* ** Does enabling the feature change any default behavior?**
@@ -313,7 +245,7 @@ _This section must be completed when targeting beta graduation to a release._
313
245
314
246
* ** How can an operator determine if the feature is in use by workloads?**
315
247
316
- Operators can determine if NetworkPolicies are making use of Range creating
248
+ Operators can determine if NetworkPolicies are making use of EndPort creating
317
249
an object specifying the range and validating if the traffic is allowed within
318
250
the specified range
319
251
@@ -350,7 +282,7 @@ previous answers based on experience in the field._
350
282
TBD
351
283
352
284
* ** 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
354
286
355
287
* ** Will enabling / using this feature result in any new calls to the cloud
356
288
provider?**
@@ -359,9 +291,8 @@ provider?**
359
291
* ** Will enabling / using this feature result in increasing size or count of
360
292
the existing API objects?**
361
293
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
365
296
- Estimated amount of new objects: N/A
366
297
367
298
* ** Will enabling / using this feature result in increasing time taken by any
@@ -432,3 +363,21 @@ type NetworkPolicyPort struct {
432
363
But the main design suggested in this Kep seems more clear, so this alternative
433
364
has been discarded.
434
365
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
+ ```
0 commit comments