-
Notifications
You must be signed in to change notification settings - Fork 462
[WIP] : remove unnecessary permissions, add validating-admissions-policies #2202
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
Draft
rahulait
wants to merge
1
commit into
NVIDIA:main
Choose a base branch
from
rahulait:update-permissions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,17 @@ | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: Role | ||
| metadata: | ||
| name: gpu-operator-daemonsets-role | ||
| rules: | ||
| - apiGroups: | ||
| - apps | ||
| resources: | ||
| - daemonsets | ||
| verbs: | ||
| - create | ||
| - delete | ||
| - get | ||
| - list | ||
| - patch | ||
| - update | ||
| - watch |
This file contains hidden or 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,12 @@ | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: RoleBinding | ||
| metadata: | ||
| name: gpu-operator-daemonsets-rolebinding | ||
| roleRef: | ||
| apiGroup: rbac.authorization.k8s.io | ||
| kind: Role | ||
| name: gpu-operator-daemonsets-role | ||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: gpu-operator | ||
| namespace: system |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
141 changes: 141 additions & 0 deletions
141
deployments/gpu-operator/templates/validating-admission-policies.yaml
This file contains hidden or 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,141 @@ | ||
| {{- if .Capabilities.APIVersions.Has "admissionregistration.k8s.io/v1/ValidatingAdmissionPolicy" }} | ||
| apiVersion: admissionregistration.k8s.io/v1 | ||
| kind: ValidatingAdmissionPolicy | ||
| metadata: | ||
| name: gpu-operator-runtimeclass-handler-policy | ||
| labels: | ||
| {{- include "gpu-operator.labels" . | nindent 4 }} | ||
| app.kubernetes.io/component: "gpu-operator" | ||
| spec: | ||
| failurePolicy: Fail | ||
| matchConstraints: | ||
| resourceRules: | ||
| - apiGroups: | ||
| - node.k8s.io | ||
| apiVersions: | ||
| - v1 | ||
| operations: | ||
| - CREATE | ||
| - UPDATE | ||
| resources: | ||
| - runtimeclasses | ||
| matchConditions: | ||
| - name: gpu-operator-service-account | ||
| expression: request.userInfo.username == 'system:serviceaccount:{{ .Release.Namespace }}:gpu-operator' | ||
| validations: | ||
| - expression: >- | ||
| object.handler in ['nvidia', 'nvidia-cdi', 'nvidia-legacy', '{{ .Values.operator.runtimeClass }}'{{- range $runtimeClass := (default (list) .Values.kataManager.config.runtimeClasses) }}{{- if $runtimeClass.name }}, '{{ $runtimeClass.name }}'{{- end }}{{- end }}] | ||
| message: runtimeclass handler must be one of the allowed runtime classes configured by the chart | ||
| --- | ||
| apiVersion: admissionregistration.k8s.io/v1 | ||
| kind: ValidatingAdmissionPolicyBinding | ||
| metadata: | ||
| name: gpu-operator-runtimeclass-handler-policy-binding | ||
| labels: | ||
| {{- include "gpu-operator.labels" . | nindent 4 }} | ||
| app.kubernetes.io/component: "gpu-operator" | ||
| spec: | ||
| policyName: gpu-operator-runtimeclass-handler-policy | ||
| validationActions: | ||
| - Deny | ||
| --- | ||
| apiVersion: admissionregistration.k8s.io/v1 | ||
| kind: ValidatingAdmissionPolicy | ||
| metadata: | ||
| name: gpu-operator-namespace-label-policy | ||
| labels: | ||
| {{- include "gpu-operator.labels" . | nindent 4 }} | ||
| app.kubernetes.io/component: "gpu-operator" | ||
| spec: | ||
| failurePolicy: Fail | ||
| matchConstraints: | ||
| resourceRules: | ||
| - apiGroups: | ||
| - "" | ||
| apiVersions: | ||
| - v1 | ||
| operations: | ||
| - UPDATE | ||
| resources: | ||
| - namespaces | ||
| matchConditions: | ||
| - name: gpu-operator-service-account | ||
| expression: request.userInfo.username == 'system:serviceaccount:{{ .Release.Namespace }}:gpu-operator' | ||
| - name: target-namespace | ||
| expression: object.metadata.name in ['{{ .Release.Namespace }}', 'nvidia-gpu-operator'] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need inputs here if these are the only namespaces we label or there can be others as well in case of openshift |
||
| validations: | ||
| - expression: >- | ||
| (!has(oldObject.metadata.labels) || | ||
| oldObject.metadata.labels.all(k, v, | ||
| (has(object.metadata.labels) && k in object.metadata.labels && object.metadata.labels[k] == v) || | ||
| k.startsWith('pod-security.kubernetes.io/') || | ||
| k == 'openshift.io/cluster-monitoring' | ||
| )) && | ||
| (!has(object.metadata.labels) || | ||
| object.metadata.labels.all(k, v, | ||
| (has(oldObject.metadata.labels) && k in oldObject.metadata.labels && oldObject.metadata.labels[k] == v) || | ||
| k.startsWith('pod-security.kubernetes.io/') || | ||
| k == 'openshift.io/cluster-monitoring' | ||
| )) | ||
| message: only pod-security.kubernetes.io/* and openshift.io/cluster-monitoring labels may be added or modified by gpu-operator | ||
| --- | ||
| apiVersion: admissionregistration.k8s.io/v1 | ||
| kind: ValidatingAdmissionPolicyBinding | ||
| metadata: | ||
| name: gpu-operator-namespace-label-policy-binding | ||
| labels: | ||
| {{- include "gpu-operator.labels" . | nindent 4 }} | ||
| app.kubernetes.io/component: "gpu-operator" | ||
| spec: | ||
| policyName: gpu-operator-namespace-label-policy | ||
| validationActions: | ||
| - Deny | ||
| --- | ||
| apiVersion: admissionregistration.k8s.io/v1 | ||
| kind: ValidatingAdmissionPolicy | ||
| metadata: | ||
| name: gpu-operator-node-label-policy | ||
| labels: | ||
| {{- include "gpu-operator.labels" . | nindent 4 }} | ||
| app.kubernetes.io/component: "gpu-operator" | ||
| spec: | ||
| failurePolicy: Fail | ||
| matchConstraints: | ||
| resourceRules: | ||
| - apiGroups: | ||
| - "" | ||
| apiVersions: | ||
| - v1 | ||
| operations: | ||
| - UPDATE | ||
| resources: | ||
| - nodes | ||
| matchConditions: | ||
| - name: gpu-operator-service-account | ||
| expression: request.userInfo.username == 'system:serviceaccount:{{ .Release.Namespace }}:gpu-operator' | ||
| validations: | ||
| - expression: >- | ||
| (!has(oldObject.metadata.labels) || | ||
| oldObject.metadata.labels.all(k, v, | ||
| (has(object.metadata.labels) && k in object.metadata.labels && object.metadata.labels[k] == v) || | ||
| k.startsWith('nvidia.com/') | ||
| )) && | ||
| (!has(object.metadata.labels) || | ||
| object.metadata.labels.all(k, v, | ||
| (has(oldObject.metadata.labels) && k in oldObject.metadata.labels && oldObject.metadata.labels[k] == v) || | ||
| k.startsWith('nvidia.com/') | ||
| )) | ||
| message: only nvidia.com/* labels may be added, modified, or removed by gpu-operator on nodes | ||
| --- | ||
| apiVersion: admissionregistration.k8s.io/v1 | ||
| kind: ValidatingAdmissionPolicyBinding | ||
| metadata: | ||
| name: gpu-operator-node-label-policy-binding | ||
| labels: | ||
| {{- include "gpu-operator.labels" . | nindent 4 }} | ||
| app.kubernetes.io/component: "gpu-operator" | ||
| spec: | ||
| policyName: gpu-operator-node-label-policy | ||
| validationActions: | ||
| - Deny | ||
| {{- end }} | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be further restricted to be installed if someone requests validatingadmissionpolicy guardrails in values.yaml. I haven't added added that and looking for feedback if we should do something like that or let these be always installed if supported by k8s.