Skip to content

Commit

Permalink
Set user id 0 for user root:root
Browse files Browse the repository at this point in the history
  • Loading branch information
joyrex2001 committed Jan 28, 2025
1 parent 8aada34 commit 88fd541
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/model/types/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func (co *Container) GetPodSecurityContext(context *corev1.PodSecurityContext) (
}

// the user id for the root user is always 0
if user == "root" {
if strings.Split(user, ":")[0] == "root" {
klog.Infof("user is root so setting user to 0")
user = "0"
}
Expand Down
16 changes: 16 additions & 0 deletions internal/model/types/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,22 @@ func TestGetRunasUser(t *testing.T) {
outsc: corev1.PodSecurityContext{RunAsUser: makeIntPointer(1000)},
err: false,
},
{ // 8
in: &Container{Labels: map[string]string{
"com.joyrex2001.kubedock.runas-user": "root",
}},
insc: &corev1.PodSecurityContext{RunAsUser: makeIntPointer(500)},
outsc: corev1.PodSecurityContext{RunAsUser: makeIntPointer(0)},
err: false,
},
{ // 9
in: &Container{Labels: map[string]string{
"com.joyrex2001.kubedock.runas-user": "root:root",
}},
insc: &corev1.PodSecurityContext{RunAsUser: makeIntPointer(500)},
outsc: corev1.PodSecurityContext{RunAsUser: makeIntPointer(0)},
err: false,
},
}
for i, tst := range tests {
res, err := tst.in.GetPodSecurityContext(tst.insc)
Expand Down

0 comments on commit 88fd541

Please sign in to comment.