Skip to content

Commit 0a591f7

Browse files
authored
Setup additional hardening for pods (#168)
Signed-off-by: Pat Riehecky <riehecky@fnal.gov>
1 parent 7813755 commit 0a591f7

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

deployments/helm/cvmfs-csi/templates/controllerplugin-deployment.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ spec:
1515
labels:
1616
{{- include "cvmfs-csi.controllerplugin.labels" . | nindent 8 }}
1717
spec:
18+
hostUsers: {{ .Values.controllerplugin.hostUsers }}
1819
{{- with .Values.controllerplugin.podSecurityContext }}
1920
securityContext: {{ toYaml . | nindent 8 }}
2021
{{- end }}
@@ -37,11 +38,16 @@ spec:
3738
- name: CSI_ADDRESS
3839
value: unix:///csi/{{ .Values.cvmfsCSIPluginSocketFile }}
3940
volumeMounts:
41+
- name: tmp
42+
mountPath: /tmp
4043
- name: socket-dir
4144
mountPath: /csi
4245
{{- with .Values.controllerplugin.provisioner.resources }}
4346
resources: {{ toYaml . | nindent 12 }}
4447
{{- end }}
48+
{{- with .Values.controllerplugin.securityContext }}
49+
securityContext: {{ toYaml . | nindent 12}}
50+
{{- end }}
4551
- name: controllerplugin
4652
image: {{ .Values.controllerplugin.plugin.image.repository }}:{{ .Values.controllerplugin.plugin.image.tag | default .Chart.AppVersion }}
4753
imagePullPolicy: {{ .Values.controllerplugin.plugin.image.pullPolicy }}
@@ -58,6 +64,8 @@ spec:
5864
- name: CSI_DRIVERNAME
5965
value: {{ .Values.csiDriverName }}
6066
volumeMounts:
67+
- name: tmp
68+
mountPath: /tmp
6169
- name: socket-dir
6270
mountPath: /csi
6371
{{- with .Values.controllerplugin.plugin.resources }}
@@ -66,9 +74,16 @@ spec:
6674
{{- with .Values.controllerplugin.extraContainers }}
6775
{{- toYaml . | nindent 8 }}
6876
{{- end }}
77+
{{- with .Values.controllerplugin.securityContext }}
78+
securityContext: {{ toYaml . | nindent 12 }}
79+
{{- end }}
6980
volumes:
81+
- name: tmp
82+
emptyDir:
83+
sizeLimit: 256Mi
7084
- name: socket-dir
71-
emptyDir: {}
85+
emptyDir:
86+
sizeLimit: 256Mi
7287
{{- with .Values.controllerplugin.affinity }}
7388
affinity: {{ toYaml . | nindent 8 }}
7489
{{- end }}

deployments/helm/cvmfs-csi/templates/nodeplugin-daemonset.yaml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ spec:
1818
spec:
1919
# hostPID is required for autofs to work.
2020
hostPID: {{ .Values.nodeplugin.hostPID }}
21+
# hostUsers is required for autofs to work.
22+
hostUsers: {{ .Values.nodeplugin.hostUsers }}
2123
{{- with .Values.nodeplugin.podSecurityContext }}
2224
securityContext: {{ toYaml . | nindent 8 }}
2325
{{- end }}
@@ -44,13 +46,21 @@ spec:
4446
- name: KUBELET_CSI_REGISTRATION_PATH
4547
value: {{ .Values.kubeletDirectory }}/plugins/{{ .Values.csiDriverName }}/{{ .Values.cvmfsCSIPluginSocketFile }}
4648
volumeMounts:
49+
- name: tmp
50+
mountPath: /tmp
4751
- name: socket-dir
4852
mountPath: /csi
4953
- name: registration-dir
5054
mountPath: /registration
5155
{{- with .Values.nodeplugin.registrar.resources }}
5256
resources: {{ toYaml . | nindent 12 }}
5357
{{- end }}
58+
securityContext:
59+
privileged: false
60+
capabilities:
61+
drop: ["ALL"]
62+
allowPrivilegeEscalation: false
63+
runAsNonRoot: false
5464
- name: nodeplugin
5565
image: {{ .Values.nodeplugin.plugin.image.repository }}:{{ .Values.nodeplugin.plugin.image.tag | default .Chart.AppVersion }}
5666
command: [/csi-cvmfsplugin]
@@ -67,7 +77,9 @@ spec:
6777
privileged: true
6878
capabilities:
6979
add: ["SYS_ADMIN"]
80+
drop: ["ALL"]
7081
allowPrivilegeEscalation: true
82+
runAsNonRoot: false
7183
env:
7284
- name: NODE_ID
7385
valueFrom:
@@ -78,6 +90,8 @@ spec:
7890
- name: CSI_DRIVERNAME
7991
value: {{ .Values.csiDriverName }}
8092
volumeMounts:
93+
- name: tmp
94+
mountPath: /tmp
8195
- name: plugins-dir
8296
mountPath: {{ .Values.kubeletDirectory }}/plugins
8397
mountPropagation: Bidirectional
@@ -114,8 +128,12 @@ spec:
114128
privileged: true
115129
capabilities:
116130
add: ["SYS_ADMIN"]
131+
drop: ["ALL"]
117132
allowPrivilegeEscalation: true
133+
runAsNonRoot: false
118134
volumeMounts:
135+
- name: tmp
136+
mountPath: /tmp
119137
- mountPath: /sys
120138
name: host-sys
121139
- name: lib-modules
@@ -149,8 +167,12 @@ spec:
149167
privileged: true
150168
capabilities:
151169
add: ["SYS_ADMIN"]
170+
drop: ["ALL"]
152171
allowPrivilegeEscalation: true
172+
runAsNonRoot: false
153173
volumeMounts:
174+
- name: tmp
175+
mountPath: /tmp
154176
- name: autofs-root
155177
mountPath: /cvmfs
156178
mountPropagation: Bidirectional
@@ -173,8 +195,12 @@ spec:
173195
privileged: true
174196
capabilities:
175197
add: ["SYS_ADMIN"]
198+
drop: ["ALL"]
176199
allowPrivilegeEscalation: true
200+
runAsNonRoot: false
177201
volumeMounts:
202+
- name: tmp
203+
mountPath: /tmp
178204
- name: plugins-dir
179205
mountPath: {{ .Values.kubeletDirectory }}/plugins
180206
mountPropagation: Bidirectional
@@ -204,7 +230,14 @@ spec:
204230
command: ["/usr/sbin/crond", "-n", "-s", "-m", "off", "-x", "load,proc,sch"]
205231
securityContext:
206232
privileged: true
233+
capabilities:
234+
add: ["SYS_ADMIN"]
235+
drop: ["ALL"]
236+
allowPrivilegeEscalation: true
237+
runAsNonRoot: false
207238
volumeMounts:
239+
- name: tmp
240+
mountPath: /tmp
208241
- name: autofs-root
209242
mountPath: /cvmfs
210243
mountPropagation: Bidirectional
@@ -222,6 +255,9 @@ spec:
222255
{{- toYaml . | nindent 8 }}
223256
{{- end }}
224257
volumes:
258+
- name: tmp
259+
emptyDir:
260+
sizeLimit: 265Mi
225261
- name: socket-dir
226262
hostPath:
227263
path: {{ .Values.kubeletDirectory }}/plugins/{{ .Values.csiDriverName }}
@@ -247,7 +283,8 @@ spec:
247283
hostPath:
248284
path: /dev
249285
- name: runtime-metadata
250-
emptyDir: {}
286+
emptyDir:
287+
sizeLimit: 1Gi
251288
- name: autofs-root
252289
hostPath:
253290
path: {{ .Values.automountHostPath }}

deployments/helm/cvmfs-csi/values.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ nodeplugin:
205205
# more details).
206206
hostPID: true
207207

208+
# hostUsers must be enabled for automounts to work.
209+
hostUsers: true
210+
208211
# (deprecated) ServiceAccount to use with Node plugin DaemonSet.
209212
# New CVMFS CSI deployments do not need this. It is only necessary
210213
# when upgrading from v1 of the driver.
@@ -289,11 +292,26 @@ controllerplugin:
289292
deploymentStrategySpec:
290293
type: RollingUpdate
291294

295+
# Control use of user namespaces for controllerplugin deployment.
296+
hostUsers: true
297+
292298
# Pod-level security context for controllerplugin deployment.
293299
podSecurityContext:
294300
seccompProfile:
295301
type: RuntimeDefault
296302

303+
# Container-level security context for controllerplugin deployment.
304+
securityContext:
305+
readOnlyRootFilesystem: true
306+
runAsUser: 12357
307+
runAsGroup: 12357
308+
runAsNonRoot: true
309+
allowPrivilegeEscalation: false
310+
privileged: false
311+
capabilities:
312+
drop:
313+
- ALL
314+
297315
# Pod priority class name.
298316
priorityClassName: ""
299317

0 commit comments

Comments
 (0)