File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -267,7 +267,7 @@ func (co *Container) GetPodSecurityContext(context *corev1.PodSecurityContext) (
267
267
}
268
268
269
269
// the user id for the root user is always 0
270
- if user == "root" {
270
+ if strings . Split ( user , ":" )[ 0 ] == "root" {
271
271
klog .Infof ("user is root so setting user to 0" )
272
272
user = "0"
273
273
}
Original file line number Diff line number Diff line change @@ -483,6 +483,22 @@ func TestGetRunasUser(t *testing.T) {
483
483
outsc : corev1.PodSecurityContext {RunAsUser : makeIntPointer (1000 )},
484
484
err : false ,
485
485
},
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
+ },
486
502
}
487
503
for i , tst := range tests {
488
504
res , err := tst .in .GetPodSecurityContext (tst .insc )
You can’t perform that action at this time.
0 commit comments