Skip to content

Commit c5f3d4f

Browse files
committed
feat: add securityContext for pod and container
Signed-off-by: Jan Jansen <[email protected]>
1 parent 7e59f2a commit c5f3d4f

File tree

3 files changed

+57
-10
lines changed

3 files changed

+57
-10
lines changed

charts/latest/csi-driver-nfs/templates/csi-nfs-controller.yaml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ spec:
6161
- mountPath: /csi
6262
name: socket-dir
6363
resources: {{- toYaml .Values.controller.resources.csiProvisioner | nindent 12 }}
64+
{{- with .Values.controller.containerSecurityContext.csiProvisioner }}
65+
securityContext:
66+
{{- toYaml . | nindent 12 }}
67+
{{- end }}
6468
- name: liveness-probe
6569
image: "{{ .Values.image.livenessProbe.repository }}:{{ .Values.image.livenessProbe.tag }}"
6670
args:
@@ -73,13 +77,12 @@ spec:
7377
- name: socket-dir
7478
mountPath: /csi
7579
resources: {{- toYaml .Values.controller.resources.livenessProbe | nindent 12 }}
80+
{{- with .Values.controller.containerSecurityContext.livenessProbe }}
81+
securityContext:
82+
{{- toYaml . | nindent 12 }}
83+
{{- end }}
7684
- name: nfs
7785
image: "{{ .Values.image.nfs.repository }}:{{ .Values.image.nfs.tag }}"
78-
securityContext:
79-
privileged: true
80-
capabilities:
81-
add: ["SYS_ADMIN"]
82-
allowPrivilegeEscalation: true
8386
imagePullPolicy: {{ .Values.image.nfs.pullPolicy }}
8487
args:
8588
- "--v={{ .Values.controller.logLevel }}"
@@ -114,10 +117,17 @@ spec:
114117
- mountPath: /csi
115118
name: socket-dir
116119
resources: {{- toYaml .Values.controller.resources.nfs | nindent 12 }}
120+
{{- with .Values.controller.containerSecurityContext.nfs }}
121+
securityContext:
122+
{{- toYaml . | nindent 12 }}
123+
{{- end }}
117124
volumes:
118125
- name: pods-mount-dir
119126
hostPath:
120127
path: {{ .Values.kubeletDir }}/pods
121128
type: Directory
122129
- name: socket-dir
123130
emptyDir: {}
131+
{{- with .Values.controller.securityContext }}
132+
securityContext: {{- toYaml . | nindent 8 }}
133+
{{- end }}

charts/latest/csi-driver-nfs/templates/csi-nfs-node.yaml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ spec:
5151
- name: socket-dir
5252
mountPath: /csi
5353
resources: {{- toYaml .Values.node.resources.livenessProbe | nindent 12 }}
54+
{{- with .Values.node.containerSecurityContext.livenessProbe }}
55+
securityContext:
56+
{{- toYaml . | nindent 12 }}
57+
{{- end }}
5458
- name: node-driver-registrar
5559
image: "{{ .Values.image.nodeDriverRegistrar.repository }}:{{ .Values.image.nodeDriverRegistrar.tag }}"
5660
livenessProbe:
@@ -79,12 +83,11 @@ spec:
7983
- name: registration-dir
8084
mountPath: /registration
8185
resources: {{- toYaml .Values.node.resources.nodeDriverRegistrar | nindent 12 }}
82-
- name: nfs
86+
{{- with .Values.node.containerSecurityContext.nodeDriverRegistrar }}
8387
securityContext:
84-
privileged: true
85-
capabilities:
86-
add: ["SYS_ADMIN"]
87-
allowPrivilegeEscalation: true
88+
{{- toYaml . | nindent 12 }}
89+
{{- end }}
90+
- name: nfs
8891
image: "{{ .Values.image.nfs.repository }}:{{ .Values.image.nfs.tag }}"
8992
args :
9093
- "--v={{ .Values.node.logLevel }}"
@@ -119,6 +122,10 @@ spec:
119122
mountPath: {{ .Values.kubeletDir }}/pods
120123
mountPropagation: "Bidirectional"
121124
resources: {{- toYaml .Values.node.resources.nfs | nindent 12 }}
125+
{{- with .Values.node.containerSecurityContext.nfs }}
126+
securityContext:
127+
{{- toYaml . | nindent 12 }}
128+
{{- end }}
122129
volumes:
123130
- name: socket-dir
124131
hostPath:
@@ -132,3 +139,6 @@ spec:
132139
path: {{ .Values.kubeletDir }}/plugins_registry
133140
type: Directory
134141
name: registration-dir
142+
{{- with .Values.node.securityContext }}
143+
securityContext: {{- toYaml . | nindent 8 }}
144+
{{- end }}

charts/latest/csi-driver-nfs/values.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ controller:
7777
requests:
7878
cpu: 10m
7979
memory: 20Mi
80+
containerSecurityContext:
81+
csiProvisioner:
82+
readOnlyRootFilesystem: true
83+
livenessProbe:
84+
readOnlyRootFilesystem: true
85+
nfs:
86+
privileged: true
87+
capabilities:
88+
add: ["SYS_ADMIN"]
89+
allowPrivilegeEscalation: true
90+
## Security context give the opportunity to run container as nonroot by setting a securityContext
91+
## by example :
92+
## securityContext: { runAsUser: 1001 }
93+
securityContext: {}
8094

8195
node:
8296
name: csi-nfs-node
@@ -108,6 +122,19 @@ node:
108122
requests:
109123
cpu: 10m
110124
memory: 20Mi
125+
containerSecurityContext:
126+
livenessProbe:
127+
readOnlyRootFilesystem: true
128+
nodeDriverRegistrar: {}
129+
nfs:
130+
privileged: true
131+
capabilities:
132+
add: ["SYS_ADMIN"]
133+
allowPrivilegeEscalation: true
134+
## Security context give the opportunity to run container as nonroot by setting a securityContext
135+
## by example :
136+
## securityContext: { runAsUser: 1001 }
137+
securityContext: {}
111138

112139
## Reference to one or more secrets to be used when pulling images
113140
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/

0 commit comments

Comments
 (0)