Skip to content
This repository has been archived by the owner on Feb 8, 2021. It is now read-only.

Commit

Permalink
container: fix the issue of using the wrong user
Browse files Browse the repository at this point in the history
Signed-off-by: fupan <[email protected]>
  • Loading branch information
lifupan committed Jul 19, 2018
1 parent 98ab211 commit 6288765
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions daemon/pod/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,12 +628,7 @@ func (c *Container) ociSpec(cjson *dockertypes.ContainerJSON, cmds []string) *sp

ocispec.Hostname = c.p.globalSpec.Hostname

/*
* ocispec used the user's UID and GID instead of user name and group name,
* thus it needed to convert the user name and group name to UID and GID in
* the future, here just set it to "0" as default.
*/
ocispec.Process.User = specs.User{UID: 0, GID: 0}
ocispec.Process.User = specs.User{Username: c.spec.User.Name}

for _, l := range c.spec.Ulimits {
ltype := strings.ToLower(l.Name)
Expand All @@ -648,7 +643,6 @@ func (c *Container) ociSpec(cjson *dockertypes.ContainerJSON, cmds []string) *sp
}

func (c *Container) containerConfig(cjson *dockertypes.ContainerJSON) (*vc.ContainerConfig, error) {
var user, group string
var ociSpec *specs.Spec
var cmds []string

Expand All @@ -665,6 +659,10 @@ func (c *Container) containerConfig(cjson *dockertypes.ContainerJSON) (*vc.Conta
c.spec.StopSignal = "TERM"
}

if c.spec.User == nil {
c.spec.User = &apitypes.UserUser{Name: cjson.Config.User}
}

cmds = append(cmds, cjson.Config.Entrypoint.Slice()...)
cmds = append(cmds, cjson.Config.Cmd.Slice()...)

Expand Down Expand Up @@ -706,17 +704,12 @@ func (c *Container) containerConfig(cjson *dockertypes.ContainerJSON) (*vc.Conta
}
c.Log(DEBUG, "mount id: %s", mountId)

if c.spec.User != nil {
user = c.spec.User.Name
group = c.spec.User.Group
}

cmd := vc.Cmd{
Args: cmds,
Envs: c.cmdEnvs([]vc.EnvVar{}),
WorkDir: c.spec.Workdir,
User: user,
PrimaryGroup: group,
User: c.spec.User.Name,
PrimaryGroup: c.spec.User.Group,
Interactive: c.spec.Tty,
Detach: !c.HasTty(),
}
Expand Down

0 comments on commit 6288765

Please sign in to comment.