@@ -298,27 +298,29 @@ to be reported only once in the slice, a device is being identified by
298298
299299### Write Permission
300300
301- To prevent unauthorized or accidental modifications by entities that do not
302- have access to a particular resource, a ` ValidatingAdmissionPolicy ` will be
303- created to validate the entities attempting to update the devices in the
304- ` ResourceClaim.Status ` .
305-
306- The ` ValidatingAdmissionPolicy ` will restrict ` ResourceClaim.Status.Devices `
307- to be set only during updates, as the object will have first to be created and
308- allocated, then configured inside the pods. It will also restrict the
309- ` ResourceClaim.Status.Devices ` to be set only for when the ` ResourceClaim ` is
310- allocated to a node. Additionally, the allocated node where the ` ResourceClaim `
311- is assigned will be used to check if the user/entity updating the
312- ` ResourceClaim.Status.Devices ` is running on the same node.
313-
314- The allocated node for the ` ResourceClaim ` must be unique in the form of
301+ To prevent unauthorized or accidental modifications by entities that do not
302+ have access to a particular resource, a synthetic check in a ` drivers ` resource
303+ will validate the entities attempting to update the devices in the ` ResourceClaim.Status ` .
304+
305+ The new synthetic check will restrict ` ResourceClaim.Status.Devices `
306+ to be set only during updates, as the object will have first to be created andå
307+ allocated, then configured inside the pods. It will also restrict the
308+ ` ResourceClaim.Status.Devices ` to be set only for when the ` ResourceClaim ` is
309+ allocated to a node. Additionally, the allocated node where the ` ResourceClaim `
310+ is assigned will be used to check if the user/entity updating the
311+ ` ResourceClaim.Status.Devices ` is running on the same node. If the user/entity is
312+ not a node component it is assumed to be a cluster wide controller and will be able
313+ to update any allocated ResourceClaim. Cluster wide controllers are also able to use
314+ a wildcard ` * ` as a resource name to be able to update any driver.
315+
316+ The allocated node for the ` ResourceClaim ` must be unique in the form of
315317` nodeSelector.nodeSelectorTerms[0].matchFields[0].values[0] = <NodeName> ` and
316318` nodeSelector.nodeSelectorTerms[0].matchFields[0].key = metadata.name ` and
317319` nodeSelector.nodeSelectorTerms[0].matchFields[0].operator = In ` . Without this
318- unique format, the update of the devices in the status will be rejected.
320+ unique format, the update of the devices in the status will fallback. to cluster wide authorization.
321+
322+ Here is a ` ResourceClaim ` allocated on a node:
319323
320- Here is a ` ResourceClaim ` allocated on a node. This would only work for now if
321- exactly one node is set:
322324``` yaml
323325apiVersion : resource.k8s.io/v1alpha3
324326kind : ResourceClaim
@@ -339,46 +341,33 @@ status:
339341 ...
340342```
341343
342- Here is an example of how the ` ValidatingAdmissionPolicy ` could look like:
344+ Here is an example of how the ` ClusterRole ` could look like for a driver running in a node:
345+
343346``` yaml
344- ---
345- apiVersion : admissionregistration.k8s.io/v1
346- kind : ValidatingAdmissionPolicy
347+ apiVersion : rbac.authorization.k8s.io/v1
348+ kind : ClusterRole
347349metadata :
348- name : " resourceclaim-device-status-update"
349- spec :
350- failurePolicy : Fail
351- matchConstraints :
352- resourceRules :
353- - apiGroups : ["resource.k8s.io"]
354- apiVersions : ["*"]
355- operations : ["UPDATE"]
356- resources : ["resourceclaims"]
357- matchConditions :
358- - name : ' device-status-update'
359- expression : >- # Validation only for objects with their .status.devices updated.
360- object.status.devices != oldObject.status.devices
361- validations :
362- - expression : >- # User node must be the same node as the one where the ResourceClaim is allocated.
363- variables.userNodeName != variables.objectNodeName
364- messageExpression: >-
365- "User '" + request.userInfo.username + "' on node '" + variables.userNodeName + "' is not allowed to update the .status.devices of a ResourceClaim allocated on node '" + variables.objectNodeName + "'."
366- reason: Forbidden
367- variables :
368- - name : userNodeName
369- expression : >-
370- request.userInfo.extra[?'authentication.kubernetes.io/node-name'][0].orValue('')
371- - name : objectNodeName
372- expression : >-
373- object.status.allocation.nodeSelector.nodeSelectorTerms[0].matchFields[0].values[0].orValue('')
374- ---
375- apiVersion : admissionregistration.k8s.io/v1
376- kind : ValidatingAdmissionPolicyBinding
350+ name : my-driver-status-updater
351+ rules :
352+ - apiGroups : ["resource.k8s.io"]
353+ resources : ["drivers"]
354+ verbs : ["update-device-status"]
355+ resourceNames : ["my-driver.example.com"]
356+ ` ` `
357+
358+ Here is an example of how the ` ClusterRole` could look like for a controller that
359+ updates multiple drivers :
360+
361+ ` ` ` yaml
362+ apiVersion: rbac.authorization.k8s.io/v1
363+ kind: ClusterRole
377364metadata:
378- name : " resourceclaim-device-status-update-binding"
379- spec :
380- policyName : " resourceclaim-device-status-update"
381- validationActions : [Deny]
365+ name: my-driver-status-updater
366+ rules:
367+ - apiGroups: ["resource.k8s.io"]
368+ resources: ["drivers"]
369+ verbs: ["update-device-status"]
370+ resourceNames: ["*"]
382371` ` `
383372
384373# ## Test Plan
@@ -409,18 +398,17 @@ Coverage:
409398 * With the feature gate enabled, the field exists in the `ResourceClaim`.
410399 * With the feature gate disabled, the field does not exist in the
411400 ` ResourceClaim` .
412- * With the feature gate enabled, the `ValidatingAdmissionPolicy` exists and
413- restricts the write access of the `ResourceClaim.Status.Devices`.
401+ * With the feature gate enabled, the rbac restricts the write access of the `ResourceClaim.Status.Devices`.
414402
415403# #### e2e tests
416404
417405The [DRA test driver](https://github.com/kubernetes/kubernetes/tree/master/test/e2e/dra/test-driver)
418- will be extended to support the new `ResourceClaim.Status.Devices` field and to
406+ will be extended to support the new `ResourceClaim.Status.Devices` field and to
419407populate it with data related to the device configured in the pod.
420408
421409A new network DRA Driver will be implemented (or extended from the existing DRA
422410test driver) to support networking type of devices and report their
423- network status.
411+ network status and validate the rbac permissions are respected .
424412
425413# ## Graduation Criteria
426414
0 commit comments