mirror of https://github.com/containers/podman.git
create, rootless: join the userns of container:CONTAINER
so that we can also join the requested namespace. Closes: https://github.com/containers/libpod/issues/1453 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com> Closes: #1507 Approved by: rhatdan
This commit is contained in:
parent
8b9b493b53
commit
1c73404fe1
|
|
@ -802,6 +802,11 @@ func parseCreateOpts(ctx context.Context, c *cli.Context, runtime *libpod.Runtim
|
|||
return config, nil
|
||||
}
|
||||
|
||||
type namespace interface {
|
||||
IsContainer() bool
|
||||
Container() string
|
||||
}
|
||||
|
||||
func joinOrCreateRootlessUserNamespace(createConfig *cc.CreateConfig, runtime *libpod.Runtime) (bool, int, error) {
|
||||
if os.Geteuid() == 0 {
|
||||
return false, 0, nil
|
||||
|
|
@ -833,5 +838,19 @@ func joinOrCreateRootlessUserNamespace(createConfig *cc.CreateConfig, runtime *l
|
|||
}
|
||||
}
|
||||
|
||||
namespaces := []namespace{createConfig.IpcMode, createConfig.NetMode, createConfig.UsernsMode, createConfig.PidMode, createConfig.UtsMode}
|
||||
for _, i := range namespaces {
|
||||
if i.IsContainer() {
|
||||
ctr, err := runtime.LookupContainer(i.Container())
|
||||
if err != nil {
|
||||
return false, -1, err
|
||||
}
|
||||
pid, err := ctr.PID()
|
||||
if err != nil {
|
||||
return false, -1, err
|
||||
}
|
||||
return rootless.JoinNS(uint(pid))
|
||||
}
|
||||
}
|
||||
return rootless.BecomeRootInUserNS()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue