ctr/tasks: support remapped UID/GID
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
This commit is contained in:
@@ -78,7 +78,7 @@ var startCommand = cli.Command{
|
||||
}
|
||||
var (
|
||||
tty = spec.Process.Terminal
|
||||
opts = getNewTaskOpts(context)
|
||||
opts = GetNewTaskOpts(context)
|
||||
ioOpts = []cio.Opt{cio.WithFIFODir(context.String("fifo-dir"))}
|
||||
)
|
||||
var con console.Console
|
||||
|
||||
@@ -79,6 +79,20 @@ func NewTask(ctx gocontext.Context, client *containerd.Client, container contain
|
||||
}
|
||||
opts = append(opts, containerd.WithTaskCheckpoint(im))
|
||||
}
|
||||
|
||||
spec, err := container.Spec(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if spec.Linux != nil {
|
||||
if len(spec.Linux.UIDMappings) != 0 {
|
||||
opts = append(opts, containerd.WithUIDOwner(spec.Linux.UIDMappings[0].HostID))
|
||||
}
|
||||
if len(spec.Linux.GIDMappings) != 0 {
|
||||
opts = append(opts, containerd.WithGIDOwner(spec.Linux.GIDMappings[0].HostID))
|
||||
}
|
||||
}
|
||||
|
||||
var ioCreator cio.Creator
|
||||
if con != nil {
|
||||
if nullIO {
|
||||
@@ -106,7 +120,8 @@ func NewTask(ctx gocontext.Context, client *containerd.Client, container contain
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func getNewTaskOpts(context *cli.Context) []containerd.NewTaskOpts {
|
||||
// GetNewTaskOpts resolves containerd.NewTaskOpts from cli.Context
|
||||
func GetNewTaskOpts(context *cli.Context) []containerd.NewTaskOpts {
|
||||
if context.Bool("no-pivot") {
|
||||
return []containerd.NewTaskOpts{containerd.WithNoPivotRoot}
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@ func NewTask(ctx gocontext.Context, client *containerd.Client, container contain
|
||||
return container.NewTask(ctx, ioCreator)
|
||||
}
|
||||
|
||||
func getNewTaskOpts(_ *cli.Context) []containerd.NewTaskOpts {
|
||||
// GetNewTaskOpts resolves containerd.NewTaskOpts from cli.Context
|
||||
func GetNewTaskOpts(_ *cli.Context) []containerd.NewTaskOpts {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user