Skip to content

Commit 88fd541

Browse files
committed
Set user id 0 for user root:root
1 parent 8aada34 commit 88fd541

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

internal/model/types/container.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func (co *Container) GetPodSecurityContext(context *corev1.PodSecurityContext) (
267267
}
268268

269269
// the user id for the root user is always 0
270-
if user == "root" {
270+
if strings.Split(user, ":")[0] == "root" {
271271
klog.Infof("user is root so setting user to 0")
272272
user = "0"
273273
}

internal/model/types/container_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,22 @@ func TestGetRunasUser(t *testing.T) {
483483
outsc: corev1.PodSecurityContext{RunAsUser: makeIntPointer(1000)},
484484
err: false,
485485
},
486+
{ // 8
487+
in: &Container{Labels: map[string]string{
488+
"com.joyrex2001.kubedock.runas-user": "root",
489+
}},
490+
insc: &corev1.PodSecurityContext{RunAsUser: makeIntPointer(500)},
491+
outsc: corev1.PodSecurityContext{RunAsUser: makeIntPointer(0)},
492+
err: false,
493+
},
494+
{ // 9
495+
in: &Container{Labels: map[string]string{
496+
"com.joyrex2001.kubedock.runas-user": "root:root",
497+
}},
498+
insc: &corev1.PodSecurityContext{RunAsUser: makeIntPointer(500)},
499+
outsc: corev1.PodSecurityContext{RunAsUser: makeIntPointer(0)},
500+
err: false,
501+
},
486502
}
487503
for i, tst := range tests {
488504
res, err := tst.in.GetPodSecurityContext(tst.insc)

0 commit comments

Comments
 (0)