Skip to content

Commit 778928b

Browse files
committed
run livenessProbe as non root user
1 parent 08de0ed commit 778928b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

controllers/syncer/csi_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func (s *csiControllerSyncer) ensurePodSpec() corev1.PodSpec {
8787
SecurityContext: &corev1.PodSecurityContext{
8888
RunAsNonRoot: util.True(),
8989
RunAsUser: func(uid int64) *int64 { return &uid }(2121),
90+
RunAsGroup: func(uid int64) *int64 { return &uid }(2121),
9091
},
9192
Affinity: s.driver.Spec.Controller.Affinity,
9293
Tolerations: s.driver.Spec.Controller.Tolerations,

controllers/syncer/csi_node.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ func (s *csiNodeSyncer) ensureContainersSpec() []corev1.Container {
141141
RunAsNonRoot: util.False(),
142142
Privileged: util.True(), // Revisit if node server needs privileged permission
143143
RunAsUser: func(uid int64) *int64 { return &uid }(0),
144+
RunAsGroup: func(uid int64) *int64 { return &uid }(0),
144145
}
145146
fillSecurityContextCapabilities(
146147
nodePlugin.SecurityContext,
@@ -158,6 +159,7 @@ func (s *csiNodeSyncer) ensureContainersSpec() []corev1.Container {
158159
registrar.SecurityContext = &corev1.SecurityContext{
159160
RunAsNonRoot: util.False(),
160161
RunAsUser: func(uid int64) *int64 { return &uid }(0),
162+
RunAsGroup: func(uid int64) *int64 { return &uid }(0),
161163
Privileged: util.False(),
162164
}
163165
fillSecurityContextCapabilities(registrar.SecurityContext)
@@ -174,6 +176,18 @@ func (s *csiNodeSyncer) ensureContainersSpec() []corev1.Container {
174176
},
175177
)
176178

179+
livenessProbe.SecurityContext = &corev1.SecurityContext{
180+
RunAsNonRoot: util.True(),
181+
RunAsUser: func(uid int64) *int64 { return &uid }(2121),
182+
RunAsGroup: func(uid int64) *int64 { return &uid }(2121),
183+
Privileged: util.False(),
184+
// This is intended to help the container access privileged host paths like csi socket
185+
SELinuxOptions: &corev1.SELinuxOptions{
186+
Type: "spc_t", // "Super Privileged Container" type.
187+
Level: "s0", // security level.
188+
},
189+
}
190+
177191
fillSecurityContextCapabilities(livenessProbe.SecurityContext)
178192
livenessProbe.ImagePullPolicy = s.getCSINodeDriverRegistrarPullPolicy()
179193
livenessProbe.Resources = getSidecarResourceRequests(s.driver, constants.LivenessProbe)
@@ -221,6 +235,14 @@ func (s *csiNodeSyncer) getEnvFor(name string) []corev1.EnvVar {
221235
Value: constants.COSCSIMounterSocketPath,
222236
},
223237
envVarFromField("KUBE_NODE_NAME", "spec.nodeName"),
238+
{
239+
Name: "IS_NODE_SERVER",
240+
Value: "true",
241+
},
242+
{
243+
Name: "SIDECAR_GROUP_ID",
244+
Value: "2121",
245+
},
224246
}
225247

226248
case constants.CSINodeDriverRegistrar:

0 commit comments

Comments
 (0)