ctr/tasks: support remapped UID/GID

Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
This commit is contained in:
Iceber Gu
2022-12-23 11:00:44 +08:00
parent f50dce84f8
commit b91f42a146
6 changed files with 20 additions and 33 deletions

View File

@@ -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

View File

@@ -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}
}

View File

@@ -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
}