Skip to content

Commit fb32a49

Browse files
committed
backpeddle on the exclude rule and discuss w the broader group
Fixes and reworked proposal to modify networkpolicyPeer matchName yaml format change add feature gates note add feature gates note
1 parent f6830ed commit fb32a49

File tree

1 file changed

+61
-46
lines changed

1 file changed

+61
-46
lines changed

keps/sig-network/20201014-NamespaceAsName.md

+61-46
Original file line numberDiff line numberDiff line change
@@ -150,29 +150,34 @@ We thus conclude that, even though targetting an object using its name is not no
150150

151151
### Goals
152152

153-
- Add a `matchName` option (which is additive to the current `matchLabels` selector).
154-
- Add an additional semantic mechanism to "allow all" namespaces while excluding a finite, specific, list of namespaces (concretely, this might involve blocking the `kube-system` namespace, as this is an obvious security boundary which most clusters would prefer).
153+
- Add a `namespace` option (which is additive to the current `matchLabels` selector).
154+
- Allow multiple `matchName` values, so that many namespaces can be allowed using the same field
155155

156156
### Non-Goals
157157

158158
- Support matching of wildcard namespaces
159+
- Changing the internal details of how namespaceSelector works with arbitrary syntax
160+
- Depending on more sophisticated features (like virtual labels) to accomplish this feature without changing the API (note that, if someone were
161+
to write a virtualLabels KEP, however, it might change the trajectory of this KEP, which is worth discussing)
159162

160163
## Proposal
161164

162-
In NetworkPolicy specification, inside `namespaceSelector` specify a new `Name` field. One possible implementation of this would be:
165+
In NetworkPolicy specification, inside `NetworkPolicyPeer` specify a new `namespaceNames` field.
163166

164-
```
165-
type NamespaceSelector struct {
166-
names []string
167-
labels *metav1.LabelSelector
168-
}
169-
```
170-
171-
which is referenced from the namespaceSelector:
167+
1) One simple way to implement this feature is to modify the NetworkPolicyPeer object, like so. Since this
168+
doesn't involve modifying a go type (i.e. were not replacing a labelSelector with a different type, we expect it
169+
to be a cleaner implementation:
172170

173171
```
174-
+ NamespaceSelector *NamespaceSelector
175-
- NamespacesSelector *metav1.LabelSelector
172+
type NetworkPolicyPeer struct {
173+
// new field
174+
namespaceNames []string
175+
176+
// existing fields...
177+
PodSelector *metav1.LabelSelector `json:"podSelector,omitempty" protobuf:"bytes,1,opt,name=podSelector"`
178+
NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty" protobuf:"bytes,2,opt,name=namespaceSelector"`
179+
IPBlock *IPBlock `json:"ipBlock,omitempty" protobuf:"bytes,3,rep,name=ipBlock"`
180+
}
176181
```
177182

178183
### User Stories (Optional)
@@ -186,7 +191,7 @@ bogged down.
186191

187192
#### Story 1
188193

189-
As an administrator I want to block all users from accessing the kube-system namespace as a fundamental default policy, and I want to do this regardless of labels that might be added or removed from it over time.
194+
As an administrator i want to allow access from monitoring pods in kube-system namespace, into any pod in my cluster, as a fundamental policy.
190195

191196
#### Story 2
192197

@@ -196,21 +201,19 @@ As an user I want to "just add" a namespace to my allow list without having to m
196201

197202
### Risks and Mitigations
198203

199-
- CNIs may not choose, initially, to support this construct, and diligent communication with CNI providers will be needed to make sure it's widely adopted.
200-
- CNIs may not choose, initially to support this construct, and dilligent communication with CNI providers will be needed to make sure its widely adopted.
204+
- CNIs may **NOT** choose, initially to support this construct, and dilligent communication with CNI providers will be needed to make sure its widely adopted.
201205
- We need to make sure that hidden defaults don't break the meaning of existing policys, for example:
202206
- if a namespcee name is retrieved by an api client which doesn't yet support it, the client doesnt crash (and the plugin doesnt crash, either).
203-
- if a namespace name policy doesn't exist (is null), then the policy should behave identically to any policy made before this field was added, that is, the `NetworkPolicyPeer` should be as obvious as possible to interpret in a way that is compatible with the semantics of the v1 policy API **before** this feature was added to it.
207+
- if a namespace name policy doesn't exist (is null), then the policy should behave identically to any policy made before this field was added, that is,
208+
- Both "allow all" and "allow none" could be incorrectly interpretted incorrectly, so we need to make sure that plugins not implementing the feature don't get misled by the new data structure.
209+
210+
the `NetworkPolicyPeer` should be as obvious as possible to interpret in a way that is compatible with the semantics of the v1 policy API **before** this feature was added to it.
204211

205212
## Design Details
206213

207214
- Add a new selector to the network policy peer data structure which can switch between allowing a "matchName" or "matchLabels" implementation, supporting a policy that is expressed like this:
208215

209-
This selector has two, EXCLUSIVE, possible input types:
210-
211-
- A list of conventional namespaces OR
212-
- A `*` with an `exclude` rule as in input to this selector
213-
216+
- A list of conventional namespaces
214217
The "conventional namespaces" will look like so:
215218
```
216219
kind: NetworkPolicy
@@ -223,45 +226,36 @@ spec:
223226
app: mysql
224227
ingress:
225228
- from:
226-
- namespaceSelector:
227-
matchName:
228-
- my-frontend
229-
```
230-
231-
Meanwhile, the "exclude" implementation, will look like this:
232-
233-
```
234-
ingress:
235-
- from:
236-
- namespaceSelector:
237-
matchName:
238-
- *
239-
exclude:
240-
- kube-system
229+
matchName:
230+
- my-frontend
241231
```
242232

243-
244233
### Test Plan
245234

246-
We will add tests for this new api semantic into the exting test/e2e/ network policy test suites in upstream which cover both of these scenarios, using the validation framework outlined in https://github.com/kubernetes/enhancements/blob/master/keps/sig-network/20200204-NetworkPolicy-verification-rearchitecture.md#motivation
235+
We will add tests for this new api semantic into the exting test/e2e/ network policy test suites in upstream which cover both of these scenarios, using the validation framework outlined in https://github.com/kubernetes/enhancements/blob/master/keps/sig-network/20200204-NetworkPolicy-verification-rearchitecture.md#motivation.
247236

248237
### Graduation Criteria
249238

250-
Note that we may not have explicity feature gates for this KEP, because NetworkPolicies typically haven't been implemented with gates. We keep this section for the time being in any case as it organizes our thinking around the general progression of the feature over time.
239+
All new field introductions need gates for at least one release, thus, we would add this feature gate in alpha, so we must use
240+
feature gates idiomatically to implement this change.
241+
242+
Gone are the days of changing the API with reckless abandon.
251243

252244
#### Alpha
253-
- Communicate CNI providers about the new field
245+
- Communicate CNI providers about the new field.
254246
- Add validation tests in API which confirm several positive / negative scenarios in the test matrix for when this field is present/absent
247+
- All new field introductions need gates for at least one release, thus, we would add this feature gate in alpha.
248+
255249

256250
#### Beta
257-
- The name selector has been supported for at least 1 minor release
258-
- Four commonly used CNI providers implement the new field, with generally positive feedback on its usage.
259-
- Feature Gate is enabled by Default
251+
- The name selector has been supported for at least 1 minor release.
252+
- Four commonly used NetworkPolicy (or CNI providers) implement the new field, with generally positive feedback on its usage.
253+
- Feature Gate is enabled by Default.
260254

261255
#### GA Graduation
262256

263-
- At least two CNIs support the The name selector field
264-
- The name selector has been enabled by default for at least 1 minor release
257+
- At least **four** NetworkPolicy providers (or CNI providers) support the The name selector field.
258+
- The name selector has been enabled by default for at least 1 minor release.
265259

266260
### Upgrade / Downgrade Strategy
267261

@@ -342,6 +336,27 @@ We dont want to have > 1 way to select namespaces.
342336

343337
A network policy operator could be created which translated a CRD into many networkpolicys on the fly, by watching namespaces and updating labels dynamically. This would be a privileged container in a cluster and likely would not gain much adoption.
344338

339+
### Alternative API implementation change
340+
341+
Another (possibly more disruptive ) possible implementation of this would be. We include this for completeness, but
342+
are proposing the 1st, simpler option for this KEP. This is interesting because it "folds" into the existing API, thus
343+
paving the way for symmetrical implementation for podSelectors, and so on. However, its increased complexity due to the
344+
fact that it breaks the existing type system by changing the `labels` implementation, makes it less attractive.
345+
346+
```
347+
type NamespaceSelector struct {
348+
names []string
349+
labels *metav1.LabelSelector
350+
}
351+
```
352+
353+
which is referenced from the namespaceSelector:
354+
355+
```
356+
+ NamespaceSelector *NamespaceSelector
357+
- NamespacesSelector *metav1.LabelSelector
358+
```
359+
345360
## Infrastructure Needed (Optional)
346361

347362
A CNI provider that supports network policys

0 commit comments

Comments
 (0)