@@ -306,6 +306,12 @@ func TestWithHostNetwork(t *testing.T) {
306306}
307307
308308func TestWithImageConfig (t * testing.T ) {
309+ tmp := t .TempDir ()
310+ passwd := filepath .Join (tmp , "passwd" )
311+ if err := os .WriteFile (passwd , []byte ("negz:x:1000:100::/home/negz:/bin/sh\n " ), 0600 ); err != nil {
312+ t .Fatal (err )
313+ }
314+
309315 type args struct {
310316 cfg * ociv1.ConfigFile
311317 passwd string
@@ -383,6 +389,31 @@ func TestWithImageConfig(t *testing.T) {
383389 },
384390 },
385391 },
392+ "UserWithNoGroupFile" : {
393+ reason : "We should resolve image config users when the rootfs has passwd data but no group file." ,
394+ s : & runtime.Spec {},
395+ args : args {
396+ cfg : & ociv1.ConfigFile {
397+ Config : ociv1.Config {
398+ Entrypoint : []string {"/bin/sh" },
399+ User : "negz" ,
400+ },
401+ },
402+ passwd : passwd ,
403+ group : filepath .Join (tmp , "group" ),
404+ },
405+ want : want {
406+ s : & runtime.Spec {
407+ Process : & runtime.Process {
408+ Args : []string {"/bin/sh" },
409+ User : runtime.User {
410+ UID : 1000 ,
411+ GID : 100 ,
412+ },
413+ },
414+ },
415+ },
416+ },
386417 }
387418
388419 for name , tc := range cases {
@@ -578,13 +609,24 @@ users:x:100:primary,doesnotexist
578609 },
579610 },
580611 "NoGroupFile" : {
581- reason : "We should not return an error if the group file doesn't exist." ,
612+ reason : "We should parse passwd data without supplementary groups if the group file doesn't exist." ,
582613 args : args {
583614 passwd : filepath .Join (tmp , "passwd" ),
584615 group : filepath .Join (tmp , "nonexist" ),
585616 },
586617 want : want {
587- p : Passwd {},
618+ p : Passwd {
619+ UID : map [Username ]UID {
620+ "root" : 0 ,
621+ "negz" : 1000 ,
622+ "primary" : 1001 ,
623+ },
624+ Groups : map [UID ]Groups {
625+ 0 : {PrimaryGID : 0 },
626+ 1000 : {PrimaryGID : 100 },
627+ 1001 : {PrimaryGID : 100 },
628+ },
629+ },
588630 },
589631 },
590632 "Success" : {
0 commit comments