Skip to content

Commit ab1940c

Browse files
committed
Write access and CR alternative
Signed-off-by: Lionel Jouin <[email protected]>
1 parent 75b0c94 commit ab1940c

File tree

1 file changed

+99
-7
lines changed
  • keps/sig-node/4817-resource-claim-device-status

1 file changed

+99
-7
lines changed

keps/sig-node/4817-resource-claim-device-status/README.md

Lines changed: 99 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- [Risks and Mitigations](#risks-and-mitigations)
1616
- [Design Details](#design-details)
1717
- [API](#api)
18+
- [Write Permission](#write-permission)
1819
- [Test Plan](#test-plan)
1920
- [Prerequisite testing updates](#prerequisite-testing-updates)
2021
- [Unit tests](#unit-tests)
@@ -40,6 +41,7 @@
4041
- [Pod.Status.PodIPs Enhancement](#podstatuspodips-enhancement)
4142
- [New Pod.Status Field](#new-podstatus-field)
4243
- [KEP-4680 extension](#kep-4680-extension)
44+
- [Custom Resources](#custom-resources)
4345
- [Infrastructure Needed (Optional)](#infrastructure-needed-optional)
4446
<!-- /toc -->
4547

@@ -283,7 +285,7 @@ changes of the state of the device.
283285
As stated, 3rd party DRA drivers will set and update the `Devices` for
284286
the device they manage. An access control must be set in place to restrict the
285287
write access to the appropriate driver (A device status can only be updated by
286-
the driver which allocated and configured this device).
288+
the entities that have a direct control over the device(s) being reported).
287289

288290
Adding `Info` as an arbitrary data slice may introduce extra processing
289291
and storage overhead which might impact performance in a cluster with many
@@ -302,6 +304,85 @@ extended to include the slice of `Devices`.
302304
to be reported only once in the slice, a device is being identified by
303305
`<driver name>/<pool name>/<device name>`.
304306

307+
### Write Permission
308+
309+
To prevent unauthorized or accidental modifications by entities that do not
310+
have access to a particular resource, a `ValidatingAdmissionPolicy` will be
311+
created to validate the entities attempting to update the devices in the
312+
`ResourceClaim.Status`.
313+
314+
The `ValidatingAdmissionPolicy` will restrict `ResourceClaim.Status.Devices`
315+
to be set only during updates, as the object will have first to be created and
316+
allocated, then configured inside the pods. It will also restrict the
317+
`ResourceClaim.Status.Devices` to be set only for when the `ResourceClaim` is
318+
allocated to a node. Additionally, the allocated node where the `ResourceClaim`
319+
is assigned will be used to check if the user/entity updating the
320+
`ResourceClaim.Status.Devices` is running on the same node.
321+
322+
Here is a `ResourceClaim` allocated on a node. This would only work for now if
323+
exactly one node is set:
324+
```yaml
325+
apiVersion: resource.k8s.io/v1alpha3
326+
kind: ResourceClaim
327+
metadata:
328+
...
329+
spec:
330+
...
331+
status:
332+
allocation:
333+
...
334+
nodeSelector:
335+
nodeSelectorTerms:
336+
- matchFields:
337+
- key: metadata.name
338+
operator: In
339+
values:
340+
- my-node
341+
...
342+
```
343+
344+
Here is an example of how the `ValidatingAdmissionPolicy` could look like:
345+
```yaml
346+
---
347+
apiVersion: admissionregistration.k8s.io/v1
348+
kind: ValidatingAdmissionPolicy
349+
metadata:
350+
name: "resourceclaim-device-status-update"
351+
spec:
352+
failurePolicy: Fail
353+
matchConstraints:
354+
resourceRules:
355+
- apiGroups: ["resource.k8s.io"]
356+
apiVersions: ["*"]
357+
operations: ["UPDATE"]
358+
resources: ["resourceclaims"]
359+
matchConditions:
360+
- name: 'device-status-update'
361+
expression: >- # Validation only for objects with their .status.devices updated.
362+
object.status.devices != oldObject.status.devices
363+
validations:
364+
- expression: >- # User node must be the same node as the one where the ResourceClaim is allocated.
365+
variables.userNodeName != variables.objectNodeName
366+
messageExpression: >-
367+
"User '" + request.userInfo.username + "' on node '" + variables.userNodeName + "' is not allowed to update the .status.devices of a ResourceClaim allocated on node '" + variables.objectNodeName + "'."
368+
reason: Forbidden
369+
variables:
370+
- name: userNodeName
371+
expression: >-
372+
request.userInfo.extra[?'authentication.kubernetes.io/node-name'][0].orValue('')
373+
- name: objectNodeName
374+
expression: >-
375+
object.status.allocation.nodeSelector.nodeSelectorTerms[0].matchFields[0].values[0].orValue('')
376+
---
377+
apiVersion: admissionregistration.k8s.io/v1
378+
kind: ValidatingAdmissionPolicyBinding
379+
metadata:
380+
name: "resourceclaim-device-status-update-binding"
381+
spec:
382+
policyName: "resourceclaim-device-status-update"
383+
validationActions: [Deny]
384+
```
385+
305386
### Test Plan
306387
307388
[x] I/we understand the owners of the involved components may require updates to
@@ -323,6 +404,8 @@ to implement this enhancement.
323404
* With the feature gate enabled, the field exists in the `ResourceClaim`.
324405
* With the feature gate disabled, the field does not exist in the
325406
`ResourceClaim`.
407+
* With the feature gate enabled, the `ValidatingAdmissionPolicy` exists and
408+
restricts the write access of the `ResourceClaim.Status.Devices`.
326409

327410
##### e2e tests
328411

@@ -336,12 +419,12 @@ TBD
336419
Feature Gates are disabled by default.
337420
- Documentation provided.
338421
- Initial unit, integration and e2e tests completed and enabled.
422+
- Authorization implemented to allow only the user on the same node as the
423+
allocated `ResourceClaim` to write the status of the devices.
339424

340425
#### Beta
341426

342427
- Feature Gates are enabled by default.
343-
- Authorization implemented to allow only the driver managing the device to
344-
write the status.
345428
- No major outstanding bugs.
346429
- Feedback collected from the community (developers and users) with adjustments
347430
provided, implemented and tested.
@@ -527,7 +610,8 @@ access the corresponding `ResourceClaim` for every Pod.
527610

528611
An option the DRA drivers can currently use to report the status of the device
529612
allocated in the `ResourceClaim` is the annotation of the `ResourceClaim` or of
530-
the `Pod` itself. As a reference, the [k8snetworkplumbingwg/Multus-CNI](https://github.com/k8snetworkplumbingwg/multus-cni) project is utilizing annotation to describe the network attachments/interfaces
613+
the `Pod` itself. As a reference, the [k8snetworkplumbingwg/Multus-CNI](https://github.com/k8snetworkplumbingwg/multus-cni)
614+
project is utilizing annotation to describe the network attachments/interfaces
531615
and report the status.
532616

533617
Here is the API below representing a network attachment. This is stored as a
@@ -555,14 +639,15 @@ type NetworkStatus struct {
555639
As part of the [Multi-Network (KEP-3698)](https://github.com/kubernetes/enhancements/issues/3698),
556640
the idea was to use the existing `Pod.Status.PodIPs` and save the data about the
557641
different network interfaces/devices attached to the `Pod`. As part of the
558-
review of the KEP, it has been indicated ([here](https://github.com/kubernetes/enhancements/pull/3700#discussion_r1501690793) and [here](https://github.com/kubernetes/kubernetes/pull/123112#issuecomment-1925957930))
642+
review of the KEP, it has been indicated ([here](https://github.com/kubernetes/enhancements/pull/3700#discussion_r1501690793)
643+
and [here](https://github.com/kubernetes/kubernetes/pull/123112#issuecomment-1925957930))
559644
that it would be an API breaking change if the `Pod.Status.PodIPs` contains
560645
more than 1 value per IP family.
561646

562647
### New Pod.Status Field
563648

564-
Still as part of the [KEP-3698 - Multi-Network](https://github.com/kubernetes/enhancements/issues/3698), and in
565-
the continuation of the previous alternative, the idea was to add a new field
649+
Still as part of the [KEP-3698 - Multi-Network](https://github.com/kubernetes/enhancements/issues/3698),
650+
and in the continuation of the previous alternative, the idea was to add a new field
566651
`Networks` in the `Pod.Status` so each networking DRA driver could report the
567652
status for each network interface/device directly in the `Pod.Status`.
568653

@@ -609,6 +694,13 @@ the idea was to extend the [KEP-4680 about resource health status in the
609694
`Pod.Status` ](https://github.com/kubernetes/enhancements/issues/4680) in order
610695
to expose device information and not just the health.
611696

697+
### Custom Resources
698+
699+
In the `ResourceClaim.Status.Devices`, instead of having opaque field (`Info`) and
700+
specific type fields, an object reference could be used for each device. The custom
701+
object would be created and maintained by the driver to report the status of the
702+
devices.
703+
612704
## Infrastructure Needed (Optional)
613705

614706
<!--

0 commit comments

Comments
 (0)