-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #219 from guptaNswati/limit-cluster-access
Limit cluster access
- Loading branch information
Showing
3 changed files
with
53 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
deployments/helm/k8s-dra-driver/templates/validatingadmissionpolicy.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
8 changes: 8 additions & 0 deletions
8
deployments/helm/k8s-dra-driver/templates/validatingadmissionpolicybinding.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |