@@ -628,12 +628,7 @@ func (c *Container) ociSpec(cjson *dockertypes.ContainerJSON, cmds []string) *sp
628628
629629 ocispec .Hostname = c .p .globalSpec .Hostname
630630
631- /*
632- * ocispec used the user's UID and GID instead of user name and group name,
633- * thus it needed to convert the user name and group name to UID and GID in
634- * the future, here just set it to "0" as default.
635- */
636- ocispec .Process .User = specs.User {UID : 0 , GID : 0 }
631+ ocispec .Process .User = specs.User {Username : c .spec .User .Name }
637632
638633 for _ , l := range c .spec .Ulimits {
639634 ltype := strings .ToLower (l .Name )
@@ -648,7 +643,6 @@ func (c *Container) ociSpec(cjson *dockertypes.ContainerJSON, cmds []string) *sp
648643}
649644
650645func (c * Container ) containerConfig (cjson * dockertypes.ContainerJSON ) (* vc.ContainerConfig , error ) {
651- var user , group string
652646 var ociSpec * specs.Spec
653647 var cmds []string
654648
@@ -665,6 +659,10 @@ func (c *Container) containerConfig(cjson *dockertypes.ContainerJSON) (*vc.Conta
665659 c .spec .StopSignal = "TERM"
666660 }
667661
662+ if c .spec .User == nil {
663+ c .spec .User = & apitypes.UserUser {Name : cjson .Config .User }
664+ }
665+
668666 cmds = append (cmds , cjson .Config .Entrypoint .Slice ()... )
669667 cmds = append (cmds , cjson .Config .Cmd .Slice ()... )
670668
@@ -706,17 +704,12 @@ func (c *Container) containerConfig(cjson *dockertypes.ContainerJSON) (*vc.Conta
706704 }
707705 c .Log (DEBUG , "mount id: %s" , mountId )
708706
709- if c .spec .User != nil {
710- user = c .spec .User .Name
711- group = c .spec .User .Group
712- }
713-
714707 cmd := vc.Cmd {
715708 Args : cmds ,
716709 Envs : c .cmdEnvs ([]vc.EnvVar {}),
717710 WorkDir : c .spec .Workdir ,
718- User : user ,
719- PrimaryGroup : group ,
711+ User : c . spec . User . Name ,
712+ PrimaryGroup : c . spec . User . Group ,
720713 Interactive : c .spec .Tty ,
721714 Detach : ! c .HasTty (),
722715 }
0 commit comments