Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit cluster access #219

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions deployments/helm/k8s-dra-driver/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ metadata:
name: {{ include "k8s-dra-driver.fullname" . }}-role
namespace: {{ include "k8s-dra-driver.namespace" . }}
rules:
- apiGroups:
- ""
- apps
- resource.k8s.io
- gpu.nvidia.com
resources: ["*"]
verbs: ["*"]
- apiGroups: ["resource.k8s.io"]
resources: ["resourceclaims"]
verbs: ["get"]
- apiGroups: ["resource.k8s.io"]
resources: ["resourceclaims/status"]
verbs: ["update"]
- apiGroups: [""]
resources: ["nodes"]
verbs: ["get"]
cdesiniotis marked this conversation as resolved.
Show resolved Hide resolved
- apiGroups: ["resource.k8s.io"]
resources: ["resourceslices"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: resourceslices-policy-{{ include "k8s-dra-driver.fullname" . }}
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups: ["resource.k8s.io"]
apiVersions: ["v1beta1"]
operations: ["CREATE", "UPDATE", "DELETE"]
resources: ["resourceslices"]
matchConditions:
- name: isRestrictedUser
expression: >-
request.userInfo.username == "system:serviceaccount:{{ include "k8s-dra-driver.namespace" . }}:{{ include "k8s-dra-driver.serviceAccountName" . }}"
variables:
- name: userNodeName
expression: >-
request.userInfo.extra[?'authentication.kubernetes.io/node-name'][0].orValue('')
- name: objectNodeName
expression: >-
(request.operation == "DELETE" ? oldObject : object).spec.?nodeName.orValue("")
- name: nodeSelectorValue
expression: >-
(request.operation == "DELETE" ? oldObject : object).spec.nodeSelector.nodeSelectorTerms[0].matchExpressions[0].values[0].orValue("")
validations:
- expression: variables.userNodeName != ""
message: >-
no node association found for user, this user must run in a pod on a node and ServiceAccountTokenPodNodeInfo must be enabled
- expression: variables.userNodeName == variables.objectNodeName || variables.nodeSelectorValue != ""
messageExpression: >-
"this user running on node '"+variables.userNodeName+"' may not modify cluster or node resourceslices"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: resourceslices-policy-{{ include "k8s-dra-driver.fullname" . }}
spec:
policyName: resourceslices-policy-{{ include "k8s-dra-driver.fullname" . }}
validationActions: [Deny]
# All ResourceSlices are matched.
Loading